I have written a custom client socket factory for RMI, so that if direct socket connections are not available due to firewalls, I fall back to HTTP. This worked great with Java 6. In Java 7, when I call RMISocketFactory.setSocketFactory( mySocketFactory ), I get this error message:
java.net.SocketException: factory already defined
Calling RMISocketFactory.getSocketFactory() shows that the installed factory is an instance of com.sun.deploy.net.protocol.rmi.DeployRMISocketFactory. I can’t use the default HTTP fallback mechanism, because I’ve customized the URLs for http connections (I can’t use the /cgi/java-rmi path).
Why is Java 7 pre-installing a socket factory, when setSocketFactory() is defined as only being able to be called once per process? How can I get it to use my own socket factory?
You should be using per-object socket factories via the RMIClientSocketFactory mechanism introduced in 1.2 last century.