JAX-WS with Custom SSLSocketFactory

It’s very easy to configure custom SSLSocketFactory for JAX-WS web-service: just specify custom property referring to SSLSocketFactory bean. But there is a nuance…

In SpringFramework you may setup web service port with following XML configuration:

xml
 1<bean id="myPort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
 2    <property name="serviceInterface" value="com.example.ServicePortInterface"/>
 3    <property name="wsdlDocumentResource" value="classpath:wsdl/MyService.wsdl"/>
 4    <property name="namespaceUri" value="urn:MyServer"/>
 5    <property name="serviceName" value="MyServerService"/>
 6    <property name="endpointAddress" value="${my.service.url}"/>
 7    <property name="customProperties">
 8        <map key-type="java.lang.String">
 9            <entry key="com.sun.xml.ws.transport.https.client.SSLSocketFactory"
10                   value-ref="mySslSocketFactoryBean"/>
11        </map>
12    </property>
13</bean>
14
15<!--  My bean implements javax.net.ssl.SSLSocketFactory -->
16<bean id="mySslSocketFactoryBean" .../>

The code above will work if you are using JAX-WS reference implementation but will not work with JAX-WS bundled in Oracle JDK. For that case you need to set a custom property named "com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory".

That’s confusing, but you should use a property name defined in the JAXWSProperties class of JAX-WS implementation of your choice. For example:

  • com.sun.xml.ws.developer.JAXWSProperties.SSL_SOCKET_FACTORY – if you’re using JAXWS-RI implementation;
  • com.sun.xml.internal.ws.developer.JAXWSProperties.SSL_SOCKET_FACTORY – for Oracle JDK implementation;
  • weblogic.wsee.jaxws.JAXWSProperties.SSL_SOCKET_FACTORY – for WebLogic server’s implementation. …

So find a JAXWSProperties and use a value of constant SSL_SOCKET_FACTORY in JAX-WS binding custom properties.

Konstantin Pavlov

Konstantin Pavlov

Software Engineer working with Java, Kotlin, Swift, and AI. Focusing on software architecture and building AI-infused apps. Passionate about testing and Open-Source projects.