I need to add "test" functionality for RMI connection (checking if the server on the other side is available/existent). I have created this class/beans:
public class MyRmiClientSocketFactory implements RMIClientSocketFactory { private int timeout; public void setTimeout(int timeout) { this.timeout = timeout; } @Override public Socket createSocket(String host, int port) throws IOException { final Socket socket = new Socket(); socket.setSoTimeout(timeout); socket.setSoLinger(false, 0); socket.connect(new InetSocketAddress(host, port), timeout); return socket; } } <bean id="myRmiClientSocketFactory" class="org.myapp.MyRmiClientSocketFactory"> <property name="timeout" value="2000"/> </bean> <bean id="myExecutor" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceInterface" value="org.myapp.MyExecutor"/> <property name="serviceUrl" value="rmi://localhost:1099/myExecutor"/> <!-- <property name="refreshStubOnConnectFailure" value="true"/> --> <!-- <property name="lookupStubOnStartup" value="false"/> --> <property name="registryClientSocketFactory" ref="myRmiClientSocketFactory"/> </bean>
When I set a "wrong" url in "serviceUrl" I expect for a "connection timeout" after 2 seconds but that doesn't happen. Any idea how to make it possible?