I have a problem. An API I am using uses TCP/IP. The server with which it communicates does not do any authentication. I would like to make it hook into my own Socket class (which obviously would just use a plain java.net.Socket internally) which would wrap all write requests (with HTTP headers with credentials in), and check incoming data (which will be HTTP replies) before passing it back for reading. It would connect to a piece of middleware which would take these requests and authenticate them before passing them on to the REAL server, and passing replies back. It doesn't seem like you can do it! If I set my own SocketImplFactory, then when in the createSocketImpl() method, I try to create a socket, it obviously starts an infinite recursion! I want to UNSET the factory just while I create the ordinary socket, but you can't do that! It actually stops you from setting the FactoryImpl back to null once you have set it! They really want to make you write a socket implementation with native calls rather than wrapping up an ordinary socket in some way! That's mad! Anyone got round this one?