Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the default SocketFactory

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.

like image 735
jconlin Avatar asked Apr 29 '09 17:04

jconlin


People also ask

What is SocketFactory?

SocketFactory class is used to create sockets. It must be subclassed by other factories, which create particular subclasses of sockets and thus provide a general framework for the addition of public socket-level functionality. (See, for example, SSLSocketFactory .) The javax. net.

What is a SSL Factory?

ssl. SSLSocketFactory is used for creating SSLSocket objects. This class contains three groups of APIs. The first group consists of a single static getDefault() method used to retrieve the default instance which, in turn, can create SSLSocket instances.


2 Answers

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.

like image 172
Nuoji Avatar answered Oct 26 '22 07:10

Nuoji


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

like image 36
Powerlord Avatar answered Oct 26 '22 06:10

Powerlord