strange problem of rmi
Hello all,
first of all i wil say sorry for a repeated query but i searched a lot this forum but what i found were mostly unresolved queries with hardly any solution.
My rmi server and rmi client are working very fine when i use them on my intranet when my client and server are on two differen machines on windows.
But when i put my rmi server on linux maching having a public ip, it starts very fine and binds the objects properly (i cross check it by using Naming.list() and printing and what i get is exactly what i expected)
Now if my client is on this same machine again it works fine.
Problem starts when i access it from any other systems on windows machine.
if i try to try to get a remote reference to remote object , what i get is following :
Looking up rmi server for remote object
java.rmi.NotBoundException: RECORDING_REMOTE_OBJECT
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unk
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at rmiclient.Rec_RemoteClient.main(Rec_RemoteClient.java:73)
Now , if instead i try to get a list of all the bound objects on server then what i get is :-
Getting the list of bound objects on rmi server with port
java.rmi.ConnectException: Connection refused to host: 203.126.226.238; nested e
xception is:
java.net.ConnectException: Connection timed out: connect
java.rmi.ConnectException: Connection refused to host: 203.126.226.238; nested e
xception is:
java.net.ConnectException: Connection timed out: 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)
at java.rmi.Naming.list(Unknown Source)
at rmiclient.Rec_RemoteClient.main(Rec_RemoteClient.java:60)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
... 7 more
I have spent a lot of time but totally in vain.
So i am looking forward for help from all you people if anybody having idea.
Thanks
Rajneesh.
# 1
I would say you are looking at the wrong Registry in the first case and a non-existent Registry in the second case. Check the URLs you are supplying to Naming.lookup() and Naming.list().
ejpa at 2007-7-10 11:38:35 >

# 2
Thanks for your suggestion. I think the problem is something to do with the firewall setting of my company because when i run my rmiserver on a window machine and bind the object to its public ip instead of local ip, the server throws an exception which says that 203.122.26.234(which is actually a proxy server ip behind the local network) is non-local. I went through a previous problem in this forum regarding that and found out that i need to set the java.rmi.server.hostname property to an external public ip.
Now when i run my server on the windows machine with its public ip(203.122.26.233) as hostname and also bind it to this public ip again i get the same exception that (203.122.26.234) is non-local. :(
But when i run my server on linux machine and binds object to its public ip (203.122.26.238) and give hostname also same the server starts just fine.(this linux machine is not having any local ip).
Now when i run my client on windows machine and try to get a list of all the objects bound to my registry on server and then try to lookup my object ............ to my surprise what i get is this :-
Check 1
Getting the list of bound objects on rmi server
Got the list !!!! Starting displaying list ...
//203.122.26.238:1099/rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT
List exhausted !!!
Looking up rmi server for remote object
java.rmi.NotBoundException: RECORDING_REMOTE_OBJECT
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at rmiclient.Rec_RemoteClient.main(Rec_RemoteClient.java:79)
I have no idea why i am getting it : -
//203.122.26.238:1099/rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT
it should have been :-
rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT
May be because of this only my client is not getting the reference.
Now if i change the coding of client program (just for the testing purpose) and try to look with //203.122.26.238:1099/rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT
then this is what i get :-
Check 1
Getting the list of bound objects on rmi server with port
Got the list !!!! Starting displaying list ...
//203.122.26.238:1099/rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT
List exhausted !!!
Looking up rmi server for remote object
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmiserver.RMIServerImpl_Stub
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmiserver.RMIServerImpl_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at rmiclient.Rec_RemoteClient.main(Rec_RemoteClient.java:79)
Caused by: java.lang.ClassNotFoundException: rmiserver.RMIServerImpl_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)
... 3 more
I have no idea and i m stuck here like anythng.
Please help me out if any of you have some idea about it.
Thanks
Rajneesh.
# 3
> Looking up rmi server for remote objectSomething is odd about your code. Can you show it here?Each element of the String[] array returned by Naming.list() can be plugged directly into Naming.lookup(). You don't have to do anything to it, and I think you have.
ejpa at 2007-7-10 11:38:35 >

# 4
Sounds like network setup / firewall issues. First thing to check is that you don't have anything funny in the /etc/hosts file. This could cause issues with DNS configurations and result in timeouts. But if you could post your code here - that would help alot as well.
3cpoa at 2007-7-10 11:38:35 >

# 5
Thanks again for the feedback....
Ok now my code for the server and client is here .... there may be few other methods also in these programs which are called from the main of the two, but i dnt think those are neccessary to put here.....
Code for the server :-
public static void main(String args[])
{
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
System.out.println("Starting the rmiregistry programatically...");
boolean flag = startRegistry();
if(flag)
{
System.out.println("Started Successfully....!!!!!");
}
else
{
System.out.println("Could not start the rmiregistry.... so exiting the system..!!!!!!!!");
System.exit(0);
}
RMIServerImpl object = new RMIServerImpl();
System.out.println("Exporting the object");
Rec_RemoteInterface stub = (Rec_RemoteInterface) UnicastRemoteObject.exportObject(object,8888);
System.out.println("Exported object");
System.out.println("Now binding the object");
Naming.rebind("rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT",stub);
System.out.println("Object bound");
System.out.println("Getting the list of bound objects on this local rmi server");
String objects[] = Naming.list("rmi://203.122.26.238");
System.out.println("Got the list !!!! Starting displaying list ...");
for(int i=0;i<objects.length;i++)
{
System.out.println(objects);
}
System.out.println("List exhausted !!!");
System.out.println("Ready for clients requests to process .....");
while(true); //stay alive
}
catch(RemoteException re)
{
System.out.println("the stack trace is :");
re.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception in main "+e);
}
}
Code for the client :-
public static void main(String args[])
{
if (System.getSecurityManager() == null)
{
//System.setSecurityManager(new SecurityManager());
System.setSecurityManager(new RMISecurityManager());
System.out.println("New Securit Manager !!!");
}
try
{
System.out.println("Check 1");
System.out.println("Getting the list of bound objects on rmi server with port");
String objects[] = Naming.list("rmi://203.122.26.238");
System.out.println("Got the list !!!! Starting displaying list ...");
for(int i=0;i<objects.length;i++)
{
System.out.println(objects);
}
System.out.println("List exhausted !!!");
System.out.println("Looking up rmi server for remote object");
Rec_RemoteInterface rec_remote_obj = (Rec_RemoteInterface)Naming.lookup("rmi://203.122.26.238:1099/RECORDING_REMOTE_OBJECT");
System.out.println("Got the remote object reference as stub !!!");
System.out.println("Check 2");
getDestination();
System.out.println("Check 3");
System.out.println(rec_remote_obj);
String list[] = rec_remote_obj.getFileList();
System.out.println("Check 4");
System.out.println("Number of files at the source folder on server : "+list.length);
String filename = null;
System.out.println(destination_folder);
for(int i=0;i<list.length;i++)
{
filename = list;
System.out.println("Start getting file Bytes for file : "+filename);
byte[] file_content = rec_remote_obj.getFileBytes(filename);
System.out.println("Ended getting file Bytes for file : "+filename);
try
{
FileOutputStream fout = new FileOutputStream(destination_folder+System.getProperty("file.separator")+filename);
fout.write(file_content);
fout.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
System.err.println("Specified Destination folder does not exists");
System.exit(0);
}
}//end of for loop
}
catch(Exception re)
{
System.out.println(re);
re.printStackTrace();
}
}>
# 6
sorry for a little mistake .......
System.out.println("Getting the list of bound objects on rmi server");
String objects[] = Naming.list("rmi://203.122.26.238");
System.out.println("Got the list !!!! Starting displaying list ...");
for(int i=0;i<objects.length;i++)
{
System.out.println(objects[ i ] );//rectified :-)
}>
# 7
The client can't find your stub class in its CLASSPATH. The client and the Registry need the remote interface class, the stub class if you generate one, and any application classes they refer to, and so on until closure.
ejpa at 2007-7-10 11:38:35 >
