Question

in below RMI service verification on remote method is not working when used naming.lookup(). it does not give any error but does not return remote interface value. But was able to find when searched for all services running on that serve

Registry reg;
String serverAddress = "xxxxx";
String serverPort = "xxxx";
String text = "x";
try {
    reg= LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
    final String regsitryList[] = registry.list();
    // Remote r = registry.lookup("xservice") ;
    if (Arrays.asList(regsitryList).contains("xservice")) {
        Remote r = registry.lookup("xservice");
        if(r!=null)
        log.debug("found the service");
    }
} catch (RemoteException re) {
    re.printStackTrace();
}
Was it helpful?

Solution

The exception that you claimed didn't happen will almost certainly be due to a ClassNotFoundException mentioning the remote interface or the stub, or a class that they depend on. When you call list() you're only retreiving Strings, not the class of the object, so there is no exception.

list() and lookup() both tell you whether the object is currently bound in the Registry. That doesn't by itself mean that the object still exists. You would have to execute a remote method on it to know that; and for that you would need the missing class(es).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top