How can I add an object into the soap header of a org.springframework.ws.WebServiceMessage
This is the structure I'm looking to end up with:
<soap:Header>
<credentials xmlns="http://example.com/auth">
<username>username</username>
<password>password</password>
</credentials>
</soap:Header>
You need to cast the
WebServiceMessage
toSoapMessage
, which has agetSoapHeader()
method you can use to modify the header. In turn,SoapHeader
has various methods for adding elements, includinggetResult()
(which can be used as the output of aTransformer.transform()
operation).Basically, you need to use a
WebServiceMessageCallback
in your client to modify the message after its creation but before it is sent. To rest of the code has been described pretty accurately by @skaffman so the whole stuff might look like this:Personally, I find that Spring-WS sucks hard for such a basic need, they should fix SWS-479.
You can do as below:
Then