I am calling a SOAP webservice with Spring-WS. The webservice in question requires me to pass some information in the SOAP header as shown here:
I came across the same issue, here's my solution but it will work only simple elements not for complex:
template.marshalSendAndReceive(request, new WebServiceMessageCallback(){
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException{
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
SoapHeaderElement messageId = soapMessage.getSoapHeader().addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "MessageID", "wsa"));
messageId.setText("urn:abcdef1234");
}
});
it produces following XML:
urn:abcdef1234
BTW javax.xml.soap.SOAPMessage
can work too, see here: http://docs.oracle.com/javaee/5/tutorial/doc/bnbhr.html#bnbia