Unable to bind class to RMI registry

R

Robin

I'm not sure I understand the exceptions being thrown here. I need a
connection between two servers and I chose to use RMI. Whenever I try
to run the code that starts the "RMI Server" I am getting an exception.
I will post the code, and then the exceptions. Hopefully someone can
see an error - I cannot.

Interface:

public interface G2RemoteInterface extends Remote {
public InquiryConfig getConfig(String configFile) throws
RemoteException;
public Response makeRequest(G2Request request) throws
RemoteException;
}

Implementation:

public class G2Remote implements G2RemoteInterface, Serializable {
private static final long serialVersionUID = 2530016775139934837L;

public G2Remote() throws RemoteException {
System.out.println("G2Remote Object Constructed");
}

public InquiryConfig getConfig(String configFile) throws
RemoteException {
InquiryConfig config = new InquiryConfig();
try {
config.load(configFile);
} catch (Exception e) {
e.printStackTrace();
}
return config;
}

public Response makeRequest(G2Request request) throws RemoteException
{
try {
return request.runDataHandler();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

Server to launch this:

public class G2RemoteServer {

public static void main(String[] args) {
try {
//System.out.println("feh");
Naming.rebind("G2Remote", new G2Remote());
System.out.println("G2 Remote Server running...");
} catch (Exception e) {
e.printStackTrace();
}
}
}




I do have rmiregistry running before the server is ever called. When I
do run it, I get this error:

G2Remote Object Constructed
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested
exception is:
java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
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:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
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 sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at
tpc.circulation.discus.g2.remote.G2RemoteServer.main(G2RemoteServer.java:26)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
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:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
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:1538)
at
java.io_ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
at
java.io_ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
at java.io_ObjectInputStream.readObject0(ObjectInputStream.java:1299)
at java.io_ObjectInputStream.readObject(ObjectInputStream.java:339)
... 9 more



I hope someone can help.

Cheers,

Robin
 
R

Robin

I should have mentioned that I was building the Stub's and Skel's.
Interesting -- when I build via an ANT script I only get the stub, but
if I do an rmic on the command line I'm getting both Stub's and Skel's.

Robin
 
R

Robin

If anyone is reading this thread - I found the reason for my error.

I was starting rmiregistry in one terminal window, while launching the
server in another. When launching the server I used a -classpath
option for my java command.

The problem was that my CLASSPATH env variable was not set correctly
when I was starting rmiregistry. Even though I'm not relying on it for
running the server, it must be there for the registry.

This worked:
$ CLASSPATH=/path/to/jars ; export CLASSPATH
$ rmiregistry &
$ java -cp $CLASSPATH the.rmi.server.ClassName

Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top