Soap envelope header and WebServiceMessageCallback
I am trying to add a customised header to my soap message and I use a WebServiceMessageCallback.soWithMessage to add it.
I've tried several things, influenced by examples on this forum but no luck yet. They do something to the message but not actually what I was hoping to see.
Code:
...
SoapMessage soapMessage = (SoapMessage) message;
SoapHeader header = soapMessage.getSoapHeader();
StringBuffer sbHeader = new StringBuffer();
sbHeader.append("<hdrns:MyHeader xmlns:hdrns=\"http://www.company.com/foo/bar/MyHeader.xsd\" ID=\"myHdr\">")
.append("<hdrns:MessageID>")
.append("1234")
.append("</hdrns:MessageID>")
.append("</hdrns:MyHeader>");
StringSource mefHeaderSource = new StringSource(sbHeader.toString());
SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(mefHeaderSource, soapHeader.getResult());
...
The above is one of the example I found here and the result I got was:
Code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<hdrns:MyHeader soapenv:mustUnderstand="0" xmlns:hdrns="http://www.company.com/foo/bar/MyHeader.xsd"/>
</soapenv:Header>
<soapenv:Body>
Huh? It obviously added something to the header because the top element is there but not the child element. I must have missed a step.
I haven't specified the message handler and it defaulted to Saaj.
Spring-ws 1.0.2
saaj-1.4
Thanks