Home Help Center

Getting 'Ice-FixedProxyException' when trying to establish bidirectional connection

yotamooyotamoo Member Yotam OhOrganization: SupersonicProject: Tesing Framewok
Hi,
I am working on a testing automation for an Android library my company is releasing for Android publishers. We have a dedicated test app that uses our JAR and what I'm trying to do is to start a server-side socket in the app so it can receive commands from our testing machine. Here's what I'm trying to do:

Server-side (Android app):
public class ControlActivity extends ActionBarActivity {

    protected class MedI extends  Med._MyCompanyDisp {

        private MyCompany mMyCompany;
        private MyCompanyCallbacksPrx client;

        public MedI() {

            mMyCompany = MyCompanyFactory.getInstance();
            mMyCompany.setRewardedVideoListener(this);
            mMyCompany.setOfferwallListener(this);
            mMyCompany.setInterstitialListener(this);
        }

        @Override
        public void setCallbacksIdentity(String Identity, Current __current) {

            Ice.Identity ident = new Identity(Identity,"");
            ObjectPrx prx = __current.con.createProxy(ident);
            this.client = MyCompanyCallbacksPrxHelper.uncheckedCast(prx);
            this.client.notify();
        }


    // Copied from ZeroC tutorial
    // https://doc.zeroc.com/display/Ice36/Writing+an+Ice+Application+with+Java
    private  int startICEServer() {
        System.out.println("Starting server");
        int status = 0;
        Ice.Communicator ic = null;
        try {
            ic = Ice.Util.initialize();
            Ice.ObjectAdapter adapter =
                    ic.createObjectAdapterWithEndpoints("MedMyCompany", "tcp -h 192.168.51.24 -p 15000");
            Ice.Object object = new MedI();
            adapter.add(object, ic.stringToIdentity("MedMyCompany"));
            adapter.activate();
            ic.waitForShutdown();
        } catch (Ice.LocalException e) {
            e.printStackTrace();
            status = 1;
        } catch (Exception e) {
            System.err.println(e.getMessage());
            status = 1;
        }
        if (ic != null) {
            // Clean up
            //
            try {
                ic.destroy();
            } catch (Exception e) {
                System.err.println(e.getMessage());
                status = 1;
            }
        }
        return status;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_control);

        Thread thread = new Thread(new Runnable(){
            @Override
            public void run(){
                startICEServer();
            }
        });
        thread.start();

    }
}

Client-side (testing machine):
public class IceMedSDK implements MedSdk {

    Communicator mIceCommunicator;
    Med.MyCompanyPrx mMyCompanyProxy;
    MyCompanyCallbacksAdapter callbacksAdapter;

    private void startICEServer() {

    }

    public IceMedSDK(String host, int port){
        mIceCommunicator = null;

        try {
            mIceCommunicator = Ice.Util.initialize();
            Ice.ObjectPrx base = mIceCommunicator.stringToProxy("MedMyCompany:tcp -h " + host +  " -p " + port);
            mMyCompanyProxy = Med.MyCompanyPrxHelper.checkedCast(base);
            if (mMyCompanyProxy == null) {
                throw new Error("Invalid proxy");
            }
        } catch (Ice.LocalException e) {
            e.printStackTrace();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }

        // callback
        ObjectAdapter adapter = mIceCommunicator.createObjectAdapter("");
        Identity ident = new Identity();
        ident.name = "callbacks";
        ident.category = "";
        callbacksAdapter = new MyCompanyCallbacksAdapter();
        adapter.add(callbacksAdapter, ident);
        adapter.activate();
        mMyCompanyProxy.ice_getConnection().setAdapter(adapter);
        mMyCompanyProxy.setCallbacksIdentity(ident.name);

        //TODO cleanup
    }
}

Now, the client to server directions works well, but when I call 'setCallbacksIdentity' I get an 'Ice-FixedProxyException' on the server side. This happens right after 'ObjectPrx prx = __current.con.createProxy(ident);' and I'm told that a fixed proxy cannot be stringified. I read about fixed proxies and I understand that they are, well, fixed, but I'm trying to create one, not modify so I don't see why it fails. This is basically a copy-paste from the tutorial so I'm a bit lost here.

I would appreciate any suggestion and I'm close to disparity :)

Many thanks,
Yotam

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    What Ice version are you using? Can you post the stack trace of the exception?

    Bests Regards,
    José
  • yotamooyotamoo Member Yotam OhOrganization: SupersonicProject: Tesing Framewok
    Sorry for the clumsy screen shot, I've just recently switched to Android and still learning, but I think it provides a lot of info. Is that what you needed? Thank you for your fast response. Attachment not found.
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    It seems like the debugger it's calling toString on the proxy object to display the info, do you see the same issue when the application runs without the debugger?

    You can try to change FixedReference.toString() to not throw and just return a string like "fixed proxy" and then rebuild ice.jar
  • yotamooyotamoo Member Yotam OhOrganization: SupersonicProject: Tesing Framewok
    You were right :) thanks!
    You guys have great support.
Sign In or Register to comment.