Skip to main content
  1. Posts/

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:

<bean id="myPort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="serviceInterface" value="com.example.ServicePortInterface"/>
    <property name="wsdlDocumentResource" value="classpath:wsdl/MyService.wsdl"/>
    <property name="namespaceUri" value="urn:MyServer"/>
    <property name="serviceName" value="MyServerService"/>
    <property name="endpointAddress" value="${my.service.url}"/>
    <property name="customProperties">
        <map key-type="java.lang.String">
            <entry key="com.sun.xml.ws.transport.https.client.SSLSocketFactory"
                   value-ref="mySslSocketFactoryBean"/>
        </map>
    </property>
</bean>

<!--  My bean implements javax.net.ssl.SSLSocketFactory -->
<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.