Monday, March 3, 2008

Adding WS-addressing to a JAX-WS Web service

I had the following code:

@WebService(targetNamespace=Constants.NAMESPACE)
public class CustomersWebService{
@Resource
private WebServiceContext context;

static {
// don't put the stacktrace in the soap fault
System.setProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace", "true");
}

@WebMethod
public String registrationRequest(@WebParam(name = "registrationRequest") InitialEntity registrationRequest) throws CareException{
...}
...
}


and I needed to make WS-addressing work. Web Services Addressing provides transport-neutral mechanisms to address Web services and messages. (https://jax-ws.dev.java.net/jax-ws-21-ea3/docs/why-wsaddressing.html)

First I had put

@javax.xml.ws.Action(
input="http://example.com/inputAction",
output="http://example.com/outputAction",
fault = {
@javax.xml.ws.FaultAction(className=AddNumbersException.class, value="http://example.com/faultAction")
})

according to http://weblogs.java.net/blog/ramapulavarthi/archive/2006/09/support_for_wsa_1.html above each method, but that wasn't sufficient: the schema didn't change.

What made things work, was adding a @javax.xml.ws.soap.Addressing attribute above my class declaration, right under the @WebService(targetNamespace=Constants.NAMESPACE), as said on https://jax-ws.dev.java.net/jax-ws-21-ea3/docs/wsaddressing.html. The schema changed and the application reacted also to ws-addressed soap calls.

No comments: