How can I add SOAP Headers to Spring Jax-WS Client?
Specifically, I have a Jaxb object I would like to add to the header but xml examples would be appreciated.
I am using Spring's JaxWsPortProxyFactoryBean described here. Also, I am generating my client as described here which is working less the headers I need to add.
Thank you.
This is an alternative solution:
After some poking around if found a slightly different solution. I'm using JAXB for marshalling my payload and the possible header classes have also been generated with JAXB from the WSDL. In my case I am addressing Microsoft Reporting Services and have pass on an ExecutionID as SOAP header.
Basically the WebServiceGatewaySupport already knows the Marshaller to convert JAXB Pojos. I'm using this one to attach my own header classes to the SoapHeader with this line:
in my nested WebServiceMessageCallback.
A little bit more elegant (still a class cast is required):
Note: This example has been testes with Spring WS 2.1.4.
I'm still trying to find an elegant way to add headers, but what I do as suggested by others is to use a Transformer on the WebServiceMessageCallBack(). Here's an example code:
It's not really elegant, considering this is Spring's WS. It's not intuitive.