Sunday, February 3, 2008

Apache CXF and SOAP Headers

Here is a link that helped me with the Apache CXF client capabilities. The requirement was to send a request to a web service which required a SOAP Header expressing authentication information. The WSDL for the Web Service did not express the request in the abstract portion but rather in the binding/concrete portion of the WSDL. Apache CXF generated a class to support the setting of the Authentication Header but no methods to add it to the request. Using Google and a decent portion of scanning/reading, I found that Apache CXF will not generate the appropriate methods to attach a SOAP Header. Java Annotations provided the answer as described at:

tapestryofthoughts.blogspot.com

By adding an annotation @WebParam along with the header=true flag and other appropriate values in the generated <####>SOAP.java as well as instantiating the Authentication Header via the generated class inside the <####>SOAP_Client.java, the client was sending a SOAP Header to the destination service.

2 comments:

John Greeley said...

You can also use a CXF Interceptor or a JAX-WS Handler (CXF's implementation of the JAX-WS Handlers is based on its native interceptors) to pull header information out of the soap message before it reaches the service implementation bean. The advantage of this approach is that you don't need to muddy up the service implementation with cross-cutting concerns.

Jon DeJong said...

Thanks! I was about to try to track down everything you just did, but you saved me the effort. I had the exact same issue. Appreciate the post.