user6374482
user6374482

Reputation:

Java RMI - NoSuchObjectException: no such object in Table (only via HTTP Proxy!)

got a Problem with my RMI Test...

Server:

LocateRegistry.createRegistry(non-default-port);
obj = new HelloImpl(); 
Naming.rebind("//ip-of-server/HelloServer", obj);

Client:

RMISocketFactory.setSocketFactory(new sun.rmi.transport.proxy.RMIHttpToCGISocketFactory());

obj = (Hello) LocateRegistry.getRegistry("ip of server", non-default-port).lookup( "HelloServer");

obj.sayHello("test");

All objects are static in the class..

But i get a "java.rmi.NoSuchObjectException: no such object in table"-Exception all the time.. This only happens, if i use the HTTP Tunneling via

RMISocketFactory.setSocketFactory(new sun.rmi.transport.proxy.RMIHttpToCGISocketFactory());

If i try it without the HTTP Tunneling (from a other PC in the normal web), it works fine!

What could be the problem?

Upvotes: 0

Views: 1376

Answers (1)

user207421
user207421

Reputation: 310979

You will be getting this from the sayHello() rather than the lookup(). The meaning of the exception is that the stub is 'stale', i.e. the remote object has been unexported, which probably means it has been DGC'd as well. You should try the following, in this order, one at a time:

  1. Keep a static reference to the value returned by createRegistry().

    This should be sufficient by itself, but if it isn't:

  2. Keep a static reference to the remote object itself, and no I do not mean its stub. In this case, obj.

I can't explain why it happens via HTTP tunnelling only, but you should do (1) in all cases anyway, so really it is a bug waiting to happen via any means.

Upvotes: 1

Related Questions