如何在使用SOAPHandler Java时读取soap请求中的其他标头

时间:2019-03-21 11:26:10

标签: java web-services soap jax-ws soaphandler

我无法在服务器端从客户端获取作为HttpPost.addHeader(“ SOAPAction”,“ anystring”)传递的soap标头。

以下是我的肥皂要求样本

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.org.com/" xmlns:inp="http://www.sterlingcommerce.com/documentation/reservation/input">
   <soapenv:Header />
   <soapenv:Body>
      <web:reservation>
         <env>
            <loginId>admin</loginId>
            <password>password</password>
         </env>
         <input>
           <!--input goes here -->
         </input>
      </web:reservation>
   </soapenv:Body>
</soapenv:Envelope>

下面是我尝试过的代码段。

snippet1:

    public class SoapHandler implements SOAPHandler<SOAPMessageContext>{
    public boolean handleMessage(SOAPMessageContext messagecontext) {
       SOAPMessage soapMsg = messagecontext.getMessage();
       System.out.println("***HeaderList****");
        SOAPHeader soapHeader = soapMsg.getSOAPHeader();
        Iterator headerElements = soapHeader.examineAllHeaderElements();
        if(headerElements!=null){
            while (headerElements.hasNext()) {
                SOAPHeaderElement element = (SOAPHeaderElement) headerElements.next();
                System.out.println("soapHeader." + element.getElementName().getLocalName() + " = " + element.getValue());
            }
        }
    }
}

片段2:

public class SoapHandler implements SOAPHandler<SOAPMessageContext>{
    public boolean handleMessage(SOAPMessageContext messagecontext) {
        SOAPMessage soapMsg = messagecontext.getMessage();
        Message message = ((WrappedMessageContext) messagecontext).getWrappedMessage();
        List<org.apache.cxf.headers.Header> headers = CastUtils.cast((List<?>) message.get(org.apache.cxf.headers.Header.HEADER_LIST));
        if (headers != null) {
            for (org.apache.cxf.headers.Header header : headers) {
                System.out.println(((Element)header.getObject()).getTextContent());
            }
        }
    }
}

这里的期望是获取SOAPAction标头及其值。

我的要求是获取标头后删除soapaction,但我无法以某种方式找到/获取此附加标头。

请帮助我。

谢谢。

0 个答案:

没有答案