6

I recently migrated my web services from Axis to CXF (2.1). It appears that while Axis needed the "axis.socketSecureFactory" set, CXF grabs the default. How do I set the default SocketFactory in Java to my own implementation (such as a property)?

What I am not looking to do is to set the default SocketFactory properties like setting the property for my truststore, keystore and passwords.

jconlin
  • 3,806
  • 6
  • 31
  • 32

2 Answers2

7

If we are talking about the standard sockets then Socket.setSocketImplFactory(SocketImplFactory) is used to change factory for ordinary sockets and ServerSocket.setSocketFactory(SocketImplFactory) for server sockets.

If you are using these, then take note of the fact that you can only set these factories once.

Note the java socket implementation defaults to using SocksSocketImpl (a package visible class in java.net) if the it discovers that the factory is null in case you want a factory that can switch pack to the standard java implementation.

Nuoji
  • 3,438
  • 2
  • 21
  • 35
6

According to the OpenJDK7 source code for javax.net.SocketFactory, the Sun JVM is hard coded to return a javax.net.DefaultSocketFactory for getDefault();

Edit: However, the default SSLSocketFactory can be set by the security property ssl.SocketFactory.provider

Powerlord
  • 87,612
  • 17
  • 125
  • 175
  • In the code you can see that only returns that if you don't set another. – ssedano Jun 13 '12 at 20:30
  • @ssedano The property's inaccessible from anywhere else, and the code defines a standard lazy instantiating getter. Powerlord is correct that the value is therefore effectively hard-coded. – KomodoDave May 13 '13 at 14:50