Search code examples
javaweb-servicestomcatjax-ws

can we use jaxws-rt.jar as runtime implementation though it includes sun libraries?


Many recommend not to use sun packages for various reasons. Detailed answers are provided here.

However I am using jaxws-rt.jar which uses sun library.

I am wondering if I should jaxws-rt.jar or not. I am running in tomcat container and I do not want to include jaxws implementations of Jboss,GlassFish or any other application servers.

Here is what I am trying to do (setting connection and request timeouts)

import com.sun.xml.internal.ws.client.BindingProviderProperties;
import javax.xml.ws.BindingProvider;

((BindingProvider)soapService).getRequestContext()
        .put(BindingProviderProperties.REQUEST_TIMEOUT,REQUEST_TIMEOUT_MILLI);
((BindingProvider)soapService).getRequestContext()
        .put(BindingProviderProperties.CONNECT_TIMEOUT,CONNECT_TIMEOUT_MILLI);

Thanks


Solution

  • As you've found, certain behaviors (such as connection timeouts) are controlled through implementation-specific means.

    If you're not keen on compiling against (importing) the com.sun packages, one way to remove the compile-time dependencies yet set these properties to control the JAX-WS reference implementation the way you need, you can try just setting the BindingProvider request context properties for the reference implementation by their string values. You can set these properties even when running with other JAX-WS runtimes than the RI - it won't fail (it just may have no effect).

    import javax.xml.ws.BindingProvider;
    
    ((BindingProvider)soapService).getRequestContext()
        .put("com.sun.xml.ws.request.timeout", 5000L);
    ((BindingProvider)soapService).getRequestContext()
        .put("com.sun.xml.ws.connect.timeout", 5000L);
    

    Here are the two values for both constants in your question. JAXWSProperties.CONNECT_TIMEOUT and BindingProviderProperties.REQUEST_TIMEOUT.