How to add XML elements to the SOAP Header?
Hello,
I would like to use Spring WS to write a Webservice client.
The special webservice which I want to get data from has the requirement, that I transfer an access-token contained in the SOAP header. So the request must look like this:
Code:
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Header>
<Authorization xmlns="xxx">
<Token>[Access Token]</Token>
</Authorization>
</Header>
<Body>
<!-- SOAP Payload here... -->
</Body>
</Envelope>
I think I have to use a WebServiceMessageCallback to manipulate the SOAP Header, adding the "<Authorization>..." element and sub elements.
What I have so far is:
Code:
WebServiceMessageCallback webServiceMessageCallback = new WebServiceMessageCallback()
{
@Override
public void doWithMessage( WebServiceMessage webServiceMessage ) throws IOException, TransformerException
{
SaajSoapMessage soapMessage = (SaajSoapMessage)webServiceMessage;
soapMessage.setSoapAction( "..." );
soapMessage.getSoapHeader().... // ??
}
};
I'm stuck here - I hope this is the right way to add an element to the SOAP header? But what are the next steps, how may the code look to add the desired "<Authorization>..." block (see above) to the SOAP header?
I really appreciate any help you can offer
Thanks a lot!