tags:

views:

224

answers:

1

Hello friends,

Any idea why do I get RemoteException while trying to invoke methods on Unix machine from Windows. I am inside the network and dont think this is because of firewall problem as I can do "telnet" from Windows to Unix box after starting the RMI server at the unix box. I also could not understand why is it going to local loopback IP?

Stack Trace:: RemoteException occured, details java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused: connect java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused: connect

Many thanks in advance.

A: 

You probably don't have your hostname configured properly on your Linux box. I bet if you ping $(hostname) from your Linux box, it will ping 127.0.0.1. Usually this is because of an entry in your /etc/hosts file.

There's a couple of ways to solve the problem. The hard way would be to get your Linux box to resolve its own hostname to its IP address properly. You can edit your /etc/hosts file, setup your DNS server, whatever you've got to do. The challenge is that while this may make things more technically correct, you run the risk of breaking things that relied on the old behavior.

The path of least change would be to set the system property java.rmi.server.hostname to the hostname or IP address of your Linux box. (i.e. java -Djava.rmi.server.hostname=$(hostname) ...).

Why?

The Java RMI registration server is actually a network wide registration server. Objects on other machines can bind themselves to this registry.

When a remote object is registered, the registration includes the network address as part of the registration. By default, the address it uses is 'the IP address of the local host, in "dotted-quad" format.' In your setup, this address is 127.0.0.1.

When your Windows box contacts the registration service for the address of the remote object, it gets back 127.0.0.1. It then tries to contact the remote object at that address. That's why it's going to the loopback address.

dave
It doesn't really have anything to do with the Registry. It's just about what information gets embedded in the stub. It can happen without the Registry. Apart from that Dave's answer is correct. Best fix is to correct your /etc hosts file; workaround is to set java.rmi.server.hostname *at the server JVM*. Fundamentally this is a problem with certain Linux distributions. This is item A.1 on the RMI FAQ in the Javadoc.
EJP
Hi Dave,I did set the system property as told by you but I am still getting the same exception. Though before making the change and even after it, I was able to locate Registry object and successfully invoke list() method on it. I wonder what could be the cause for this error?
Gabriel Parenza
@Gabriel - did you set the property on the server (Unix) side or the client (Windows) side? Should be on the server side.
dave
On the server side.
Gabriel Parenza
Try the IP address instead of `$(hostname)`
dave
I actually gave IP address only.
Gabriel Parenza
I tried the other way around, connecting to Windows from Unix and it worked successfully. Also, I did not need to give "java.rmi.server.hostname" when running server on Windows.I wonder if the information I have given below could be of any help!System.out.println for Registry object::Windows-->RegistryImpl[UnicastServerRef [liveRef: [endpoint:[<MyMachinesIPNo>:1099](local),objID:[0:0:0, 0]]]]Unix-->gnu.java.rmi.server.UnicastServerRef@410e590Host file contents::Windows-->127.0.0.1 localhostUnix-->127.0.0.1 <Server-name> localhost.localdomain localhost
Gabriel Parenza
It worked out after removing hostname from the /etc/hosts file. Strangely did not work out using java.rmi.server.hostname!Thanks Dave for your help on this.
Gabriel Parenza