views:

29

answers:

2

Hello,

I have an RMI Server which correctly binds to an RMI Registry when running on localhost (to demonstrate that things are setup correctly). The code which does this is:

 private void exposeTickHistoryRemoteProvider(TickHistoryRemoteInterface aTickHistoryServer) {
        if (System.getSecurityManager() == null) {
            SecurityManager mySecurityManager = getSecurityManager();
   System.setSecurityManager(mySecurityManager);
        }
  String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
  try {
   TickHistoryRemoteInterface stub =
                (TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
            Registry registry = LocateRegistry.getRegistry(rmiServerHostname);
            String[] services = registry.list();
            registry.rebind(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER, stub);
            log.info(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " bound");
        } catch (Exception e) {
         log.error(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " exception:" + e.toString());
            e.printStackTrace();
        }
    }

My localhost is running Windows with the following version of Java:

C:\eclipse>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

Now, my issue is that I want to bind to an RMIRegistry running on a different machine (running Ubuntu 10.04, with OpenJDK IcedTea6 1.8.1, java version 1.6.0_18).

On this Ubuntu machine, I have nothing in my CLASSPATH (echo $CLASSPATH), and am running the OpenJDK RMIRegistry (as opposed to the one bundled with Ubuntu):

sudo /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry &

Now, in the code above, when variable rmiServerHostname is "localhost" with the RMIRegistry running on my Windows localhost, the code works correctly (the RMI Server code binds to the RMI Registry). However, when rmiServerHostname is my remote Ubuntu machine ("deity") I get the following exception thrown on the "rebind" invocation:

 java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
 java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
 java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
 java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
 java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
 java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface

If I kill the RMIRegistry, I get a different error message (I would expect):

 java.rmi.ConnectException: Connection refused to host: deity; nested exception is: 
 java.net.ConnectException: Connection refused: connect
 at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
 at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
 at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
 at sun.rmi.server.UnicastRef.newCall(Unknown Source)
 at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source)

I would assume there is no incompatibility between these implementations of RMIRegistry (Windows Java6 and Ubuntu OpenJDK 6)... but, I am unsure how to get to the bottom of this one. Especially because I know the code works correctly (in the first, Windows/localhost) example.


Progress So Far

Thanks alot for the helpful responses. I understand that I was getting confused between the rmiServerHostname (running on my localhost), and the rmiRegistryHostname (running on 'deity'). I have revised the code, with the following, but am still getting the same problem (note the change in the line "Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname)"):

    String rmiServerCodebase = System.getProperties().getProperty("java.rmi.server.codebase");
    String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
    String rmiRegistryHostname = "deity";
    System.out.println("rmiServerCodebase=" + rmiServerCodebase + "; rmiServerHostname=" + rmiServerHostname);
    try {
        TickHistoryRemoteInterface stub =
            (TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
        Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname);

The output of the print statement is (note, my localhost is 'RTPC-16')

"rmiServerCodebase=file:///C:/workspace/DEV/ReutersTickHistoryServer/ReutersTickHistoryInterface.jar; rmiServerHostname=RTPC-16"

This file does exist:

C:\>dir c:\workspace\DEV\ReutersTickHistoryServer\ReutersTickHistoryInterface.jar
 Volume in drive C is OS
 Volume Serial Number is 7AEB-A105

 Directory of c:\workspace\DEV\ReutersTickHistoryServer

22/10/2010  12:21 PM             9,467 ReutersTickHistoryInterface.jar
               1 File(s)          9,467 bytes

So, to summarise once more:

  • This code works when RMIRegistry and RMIServer are on same physical host (eg, localhost)
  • The problem occurs when I try to run only the RMIRegistry process on a separate host (ie, RMIRegistry is running on 'deity' as I want it to be whilst RMIServer is running on my localhost 'RTPC-16')
  • I was bundling the RMI interface codebase ("ReutersTickHistoryInterface.jar") on both the client and server, so I was not anticipating RMI would need to transport any class definitions - RMI simply create the stub classes on the client and handle the actual RMI calls
A: 

You are getting this exception because the rmiregistry can't locate the remote object's stubs or other classes needed by the stub. You need to specify the java.rmi.server.codebase property when starting the server, set to be the location of the implementation stubs. This is required so that the stub class can be dynamically downloaded to the registry.

For more details on this property take a look at the Dynamic code downloading using RMI tutorial.

dogbane
A: 

Also you are misusing java.rmi.server.hostname. That's not what it is for. As this code is binding to the Registry, and as you can only do that if the Registry is running in the same host, you should just use "localhost" when obtaining the registry reference for binding or unbinding.

EJP