That does work just fine. It allows me to put one tag only under the header so I get this:
Code:
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<eai:applicationContext
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
xmlns:eai="http://www.xxx.co.nz/EAI/UMTS_ICMSAdapter">
<hdrns:MessageID xmlns:hdrns="http://www.company.com/foo/bar/MyHeader.xsd">1234</hdrns:MessageID>
</eai:applicationContext>
</soapenv:Header>
But I actually have three tags to add at the level of hdrns:MessageID.
So this is what my code look like now (to produce the above header):
Code:
SoapMessage soapMessage = (SoapMessage) message;
SoapHeader soapHeader = soapMessage.getSoapHeader();
SoapHeaderElement headerElement = soapHeader.addHeaderElement(new QName(WebServiceHelper.EAI_NAMESPACE,"applicationContext","eai"));
headerElement.setMustUnderstand(false);
StringBuffer sbHeader = new StringBuffer();
sbHeader.append("<hdrns:MessageID xmlns:hdrns=\"http://www.company.com/foo/bar/MyHeader.xsd\">")
.append("1234")
.append("</hdrns:MessageID>");
StringSource mefHeaderSource = new StringSource(sbHeader.toString());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(mefHeaderSource, headerElement.getResult());
If I add another tag to the list in the StringBuffereg:
Code:
<hdrns:MessageID xmlns:hdrns="http://www.xxx.com/x.xsd">1234</hdrns:MessageID>
<hdrns:TransactionID xmlns:hdrns="http://www.xxx.com/x.xsd">1234</hdrns:TransactionID>
Then I get problems with the XML not being well formed so (understandably) the transform doesn't work (I tried it anyway, just in case).
Is there any way to make a multi-tag element and put it into the header?