Thursday, March 20, 2008

JAX-WS Custom Properties

After days of searching for ways to set a System property for the endpoint of the JAX-WS web service in order to allow us to configure it on the fly, I finally came across Gerard Davison's blog entry that explains how to do it with those magic JAX-WS Maps. 4 lines of code that solve all of my problems!

http://kingsfleet.blogspot.com/2007/11/changing-endpoint-location-for-jax-ws.html


For more information on the MessageContext properties (the exact list I was looking for):
https://jax-ws.dev.java.net/articles/MessageContext.html

As well, a common problem that I have is setting timeouts for the Web Service calls. While this should be the first result of a Google "JAX-WS timeout" search, I always end up having to run around in circles finding the answer. And, of course, every major server has their own way of doing this. However, in this case (Glassfish v2, JAX-WS 2.1) the answer is as follows:

((BindingProvider)port).getRequestContext().put(
"com.sun.xml.ws.connect.timeout", connectionTimeout);
((BindingProvider)port).getRequestContext().put(
"com.sun.xml.ws.request.timeout", socketTimeout);

Now, why these are not constants in BindingProvider...