This looks close to what I need, but context.getSocketFactory() is an instance of javax.net.ssl.SSLSocketFactory, and Socket.setSocketImplFactory() expects a java.net.SocketImplFactory. I cannot cast them.

Any idea what I am missing?