Add child elements to custom SOAP header in Spring-WS

后端 未结 4 852
清酒与你
清酒与你 2020-12-30 04:09

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:



        
4条回答
  •  萌比男神i
    2020-12-30 04:45

    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

提交回复
热议问题