Archived

This forum has been archived. Please start a new discussion on GitHub.

Using config file with Java client

Hi,

I'm practically brand new to ICE, and I'm trying to run a simple Java client; the server is already written in C++. I've been reading through the documentation extensively to get myself up to speed, but I'm having some difficulty.

I have a small .ice file which I've compiled with slice2java into a slice definition. However, I cannot get my client to run properly, and I believe it is caused by two problems.

First, I was told by the person who wrote the C++ server to include a configuration file with:
Ice.Trace.Network = 0
Ice.Default.Locator = IceGrid/Locator:default -h localhost -p 11010
LOTFVigra.Proxy = LOTFVigra@LOTFVigra

I understand what the first two lines are for, but not really the third. I've asked the person who wrote the server what that is for. Either way, I do not understand how to use this configuration file (named "config") in my client. I searched the web and found that I would need a --Ice.Config argument passed to the Ice runtime, correct? I'm not sure how I would do this. Would I do it when I compile the client code in Java? When I run it? Or is there another way?

Second, I am uncertain of how to determine the object identity to use in the Ice.Communicator.stringtoProxy method. I'm following the HelloWorld example in the documentation by creating a Ice.Communicator, initializing it, creating an Object proxy, and performing a checked cast:
Ice.Communicator ic = null;
try {
      ic = Ice.Util.initialize(args);
      Ice.ObjectPrx base = ic.stringToProxy("IMAQ:default -h localhost -p 11010";
      LOTFVigra.ImageAcquisitionPrx imAq = LOTFVigra.ImageAcquisitionPrxHelper.checkedCast(base);

However, when I attempt to run the client, I get the error:

Ice.ObjectNotExistException
id.name = "IMAQ"
id.category = ""
facet = ""
operation = "ice_isA"
at IceInternal.Outgoing.invoke(Outgoing.java:148)
at Ice._ObjectDelM.ice_isA(_ObjectDelM.java:31)
at Ice.ObjectPrxHelkperBase.ice_isA(ObjectPrxHelperBase.java:86)
at Ice.ObjectPrxHelkperBase.ice_isA(ObjectPrxHelperBase.java:61)
at LOTFVigra.ImageAcquisitionPrxHelper.checkedCast(ImageAcquisitionPrxHelper.java:70)
at Client.main(Client.java:8)

If I need to provide more information or if I am missing something else, please let me know.

Thanks,
Dan

Comments

  • mes
    mes California
    Hi Dan,

    There are many ways to use a configuration file. The most common way is using the --Ice.Config command line option, such as

    $ java MyProgram --Ice.Config=config

    You can also load a configuration file programmatically into an Ice.Properties object and then supply that object when calling Ice.Util.initialize:
    Ice.InitializationData id = new Ice.InitializationData();
    id.properties = Ice.Util.createProperties();
    id.properties.load("config");
    Ice.Communicator ic = Ice.Util.initialize(id);
    

    Chapter 30 of the Ice manual describes the use of properties and configuration files in detail.

    Regarding the LOTFVigra.Proxy property, I believe your client should be passing the value of this property to stringToProxy:
    String proxy = communicator.getProperties().getProperty("LOTFVigra.Proxy");
    Ice.ObjectPrx base = communicator.stringToProxy(proxy);
    

    In Ice 3.2, there's an even easier way to convert a stringified proxy contained in a property into a proxy object:
    Ice.ObjectPrx base = communicator.propertyToProxy("LOTFVigra.Proxy");
    

    You are getting Ice.ObjectNotExistException because you are attempting to use a proxy that contains your application-specific identity (IMAQ) and the endpoint of the locator. No such object exists in the locator service, so the Ice run time raises that exception. If this is the identity of a well-known object, you can use stringToProxy("IMAQ"). See chapters 32 and 38 for more information on using the locator service.

    Hope that helps,
    - Mark
  • Hi Mark,

    Thanks for the help, and I apologize for taking so long to respond; I have been busy with other projects recently.

    The --Ice.Config=config command line argument worked fine for me when I ran my Client.

    Replacing my current method of calling a proxy with:
    Ice.ObjectPrx base = communicator.propertyToProxy("LOTFVigra.Proxy");
    

    allows me to connect to the server. At first it was giving me an error, which I cannot display here because it seemed to have solved itself, about not finding any endpoints for the proxy object. I am not too sure what the error said, as I cannot get to it now; I ran my code again today to see what the error was, but now it is working. Therefore, I believe it was a problem with the server the other day, and something I need to ask the server admin about.

    My problem is solved now, so thank you again for the help.

    Dan

    EDIT: The reason my Client was not running previously is because the server admin had killed the server to modify it.