Monday, May 14, 2012

Spring RMI: handleRemoteConnectFailure

I have a RMI client/server configuration created with Spring 3.0.



When client and server run on the same machine at the url:



  rmi://localhost:1099/myService


everything is ok. When I run the client on a different machine (server run now on 192.168.1.67) and the client "points" to:



  rmi://192.168.1.67:1099/myService 


I can see this error message from the client:



  org.spring...RmiClientInterceptor handlerRemoteConnectFailure. 
Could not connect to Rmi Service [rmi://192.1681.67:1099/myService]


The server is configured in this way:



    <bean id="myService" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="myService"/>
<property name="serviceInterface" value="org.myapp.MyService"/>
<property name="serviceName" value="myService"/>
<property name="alwaysCreateRegistry" value="true"/>
</bean>

<bean id="myService" class="org.myapp.MyServiceImpl" />


and the client:



    RmiProxyFactoryBean rpfb = new RmiProxyFactoryBean();
rpfb.setServiceInterface(MyService.class);
rpfb.setLookupStubOnStartup(true);
rpfb.setRefreshStubOnConnectFailure(true);
RMICustomClientSocketFactory socketFactory = new RMICustomClientSocketFactory();
socketFactory.setTimeout(5000);
rpfb.setRegistryClientSocketFactory(socketFactory);
rpfb.setServiceUrl(getRmiUrl(address, port));
rpfb.afterPropertiesSet();


I checked with a sniffer the port 1099 of the server, and when the client starts its process I can see some data "dispatched" on the server side:



 JRMI..K
...192.168.1.65..
..192.168.1.65....
P....w"..........................D.M...;.t..myService
Q....w.....e...7B+@5..s}.....5org.springframework.remoting.rmi.RmiInvocationHandlerpxr..java.lang.reflect.Proxy.'. ..C....L..ht.%Ljava/lang/reflect/InvocationHandler;pxpsr.-java.rmi.server.RemoteObjectInvocationHandler...........pxr..java.rmi.server.RemoteObject.a...a3....pxpw2.
UnicastRef..127.0.1.1..../.T~.X.....e...7B+@5...x
R
S
T...e...7B+@5..


My question is: Why if client & server run on the same machine, everything is ok but on different machines I get this problem? and how to fix it?



My Answer:



I run the server on windows and client on linux (ubuntu) and everything was ok.
When I run the server on linux and client on windows I get the problem.



My fix is running the server with: -Djava.rmi.server.hostname=192.168.1.67 on Linux.





No comments:

Post a Comment