Callback stub class not found

Hi there

This is my first time with RMI, so don't be hard on me ;) I've already looked at some topic, but didn't find a solution for my problem.. Well, the forum search is appalling, so it could very well be out there... Here it goes:

I have a modular system:

- a server, getting events from devices

- a client module

The modules connect to the server via RMI, and they can receive the events they apply for

So i have the following interfaces (I simplified it a bit):

publicinterface ModuleRegisterextends Remote{

publicvoid register(Module module)throws RemoteException;

publicvoid register(Module module,int[] accept)throws RemoteException;

publicvoid unRegister(Module module)throws RemoteException;

It has in implementation on the server side. And this interface:

publicinterface Moduleextends Remote{

public String getName()throws RemoteException;

publiclong getIdentification()throws RemoteException;

publicvoid receiveEvent(Packet packet)throws RemoteException;

}

The module interface has a client implementation. Obviously, Packet is another interface and is implemented at the Server

publicinterface Packetextends Remote{

publicbyte[] getData()throws RemoteException;

publicint getID()throws RemoteException;

publicint getSize()throws RemoteException;

public InetSocketAddress getRemoteAddress()throws RemoteException;

}

Okay now, Thats about it.

The Test module looks like this:

publicclass TestModuleextends UnicastRemoteObjectimplements Module{

public TestModule()throws RemoteException{

super(0);

}

privatestaticfinallong serialVersionUID = -<xxxxxxxxxx>L;

publiclong getIdentification()throws RemoteException{

return 12321321564564;

}

public String getName()throws RemoteException{

return"testmodule";

}

publicvoid receiveEvent(Packet packet)

throws RemoteException{

System.out.println("received packet with id ["+packet.getID()+"] and size ["+packet.getSize()+"]");

}

The server starts, an seems to run fine. The RMI inspector shows that the ModuleRegister is exported nicely.

So now the client connects to the RMI server (at the moment localhost). After some security problems I run against this problem:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:

java.lang.ClassNotFoundException: com.foo.testmodule.TestModule_Stub

at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:325)

at sun.rmi.transport.Transport$1.run(Transport.java:153)

at java.security.AccessController.doPrivileged(Native Method)

at sun.rmi.transport.Transport.serviceCall(Transport.java:149)

at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)

at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)

at java.lang.Thread.run(Thread.java:595)

at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)

at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)

at sun.rmi.server.UnicastRef.invoke(Unknown Source)

at com.foo.udpserver.net.ModuleManager_Stub.register(Unknown Source)

at com.foo.testmodule.Test.serviceAdded(Test.java:55)

at javax.jmdns.JmDNS.updateRecord(JmDNS.java:909)

at javax.jmdns.JmDNS.handleResponse(JmDNS.java:994)

at javax.jmdns.JmDNS.access$900(JmDNS.java:25)

at javax.jmdns.JmDNS$SocketListener.run(JmDNS.java:1139)

at java.lang.Thread.run(Unknown Source)

Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:

java.lang.ClassNotFoundException: com.foo.testmodule.TestModule_Stub

at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:285)

at sun.rmi.transport.Transport$1.run(Transport.java:153)

at java.security.AccessController.doPrivileged(Native Method)

at sun.rmi.transport.Transport.serviceCall(Transport.java:149)

at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)

at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)

at java.lang.Thread.run(Thread.java:595)

Caused by: java.lang.ClassNotFoundException: com.foo.testmodule.TestModule_Stub

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:242)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)

at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)

at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)

at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)

at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)

at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1543)

at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1465)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)

at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:290)

at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:279)

The big question is: why can't the TestModule stub be found. All stubs were generated my the eclipse RMI plugin. I also see it in the client class folder, but it appears that the server cannot load the stub?

Why is this? Did I miss something?

I'm using JDK 1.5...

[8695 byte] By [deepspacea] at [2007-10-3 5:04:11]
# 1

Well, I added

System.setProperty("java.rmi.server.ignoreStubClasses", "true");

And now it works.. except for remote computers:

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:

java.lang.ClassNotFoundException: com.foo.udpserver.net.ModuleMana

ger_Stub

at sun.rmi.server.UnicastRef.invoke(Unknown Source)

at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn

own Source)

at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)

at $Proxy0.lookup(Unknown Source)

at java.rmi.Naming.lookup(Unknown Source)

at com.foo.testmodule.Test.serviceAdded(Test.java:53)

at javax.jmdns.JmDNS.updateRecord(JmDNS.java:909)

at javax.jmdns.JmDNS.handleResponse(JmDNS.java:994)

at javax.jmdns.JmDNS.access$900(JmDNS.java:25)

at javax.jmdns.JmDNS$SocketListener.run(JmDNS.java:1139)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.ClassNotFoundException: com.foo.udpserver.net.ModuleM

anager_Stub

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)

at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)

at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)

at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)

at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)

at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)

at java.io.ObjectInputStream.readClassDesc(Unknown Source)

at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)

at java.io.ObjectInputStream.readObject0(Unknown Source)

at java.io.ObjectInputStream.readObject(Unknown Source)

at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)

... 11 more

deepspacea at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...
# 2
You can read about the codebase property: http://www.genady.net/rmi/v20/docs/tutorials/print_server.html (scroll down a bit) http://www.genady.net/forum/viewtopic.php?t=262 http://java.sun.com/j2se/1.5.0/docs/guide/rmi/codebase.htmlGenady
genadya at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...
# 3

Thanks... is there any way that I can dynamicly set this codebase? And why does it have to be a file or URL if 1.5 dynamicly creates the stubs? Where would they be? I'm not at alle interested in runnig a http server or a file share for this.

I don't want to client to know where to get the files, it just should simply work, only with the interfaces that are common among remote and local objects.

Also, I still don't het why this would work locally, and not remote?

deepspacea at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...
# 4
Well, turns out you need the JDK and not the JRE on your client machine to make it work. Logical, because you'll still need rmic to create the subs (although this is done automagicly).
deepspacea at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...
# 5
Sometimes you'll have to pass classes for one side to another (for example classes that implement a non-remote interface) and the other side must have access to its definition. This is what the codebase is for even with Java 5.0.
genadya at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...
# 6
Yes, I understand that. But I'd rather not use it. And now, I found the solution to do that, so I'm very happy :)
deepspacea at 2007-7-14 23:10:05 > top of Java-index,Core,Core APIs...