RMI naming lookup throws UnmarshalException caused by ClassNotFoundException

StackOverflow https://stackoverflow.com/questions/21638322

  •  08-10-2022
  •  | 
  •  

문제

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();
}
도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top