I'm trying to send SOAP request with soap header looks like this:
<SOAP-ENV:Header>
<Security xmlns="http://www.xxx.org/xxx/2003/05">
<UsernameToken><Username>yyyy</Username><Password>xxx</Password>
</UsernameToken></Security></SOAP-ENV:Header>
In order to do it I'm adding header element using SoapActionCallback
SoapActionCallback actionCallBack = new SoapActionCallback("https://aaa.com/bbb.asmx") {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage) msg;
smsg.setSoapAction("http://www.xxx.org/yyy/2003/05/SessionCreate");
SoapHeaderElement security = smsg.getSoapHeader().addHeaderElement(new QName("http://www.xxx.org/yyy", "Security"));
security.setText("<UsernameToken><Username>yyyy</Username><Password>xxx</Password></UsernameToken>");
}
};
My problem is that soap header looks like this
<SOAP-ENV:Header><Security xmlns="http://www.xxx.org/yyy/2003/05"><UsernameToken><Username>yyyyy</Username><Password>xxxx</Password></UsernameToken></Security></SOAP-ENV:Header>
And as result my request fails:
How can I add this message correct?
I want the same thing as well. However, as it appears in my own searching, Spring doesn't have full functions like the SOAPMessage in java. What you probably needed was an addChildElement() to the header.
I ended up ditching the SoapMessage building and went with this:
Do note that with the approach above passing a SOAPMessage using sendSourceAndReceiveToResult wraps the SOAPMessage in another envelope and this is not what we want. :(
Update (10/25/2013): I found this solution in another discussion. It's a little vague but worth looking into. I'll try to test this out on my end. One of my colleagues tried out spring-integration-ws and looking in google for the topic and soap headers yielded some promising resources.
Update (10/25/2013): After fooling around with the library I discovered there is a quicker way to wrap the SOAPMessage into Spring's SoapMessage using this:
Perhaps after you build your soapmessage you can route it to spring-ws and so on.