简体   繁体   English

在将消息发布到服务器之前,如何从SOAP请求中删除标头元素

[英]How to remove a header element from a SOAP request before posting the message to server

I have a SOAP request like below. 我有一个如下的SOAP请求。 Before sending the request to server, I want to remove "SessionType" and "SessionToken" from the SOAP Header. 在将请求发送到服务器之前,我想从SOAP标头中删除“ SessionType”和“ SessionToken”。

Please guide. 请指导。

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header>
      <SessionType xmlns="http://siebel.com/webservices">Stateless</SessionType>
      <SessionToken xmlns="http://siebel.com/webservices">xkhdj</SessionToken>
      <UsernameToken xmlns="http://siebel.com/webservices">xyz</UsernameToken>
      <PasswordText xmlns="http://siebel.com/webservices">**********</PasswordText>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      <GetCustomerPreference_Input xmlns="http://siebel.com/CustomUI">
         <CustNumber>FR7810</CustNumber>
         <Country>France</Country>
         <LOB/>
      </GetCustomerPreference_Input>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Regards, Milan 问候米兰

You can try 你可以试试

    SOAPMessage msg = context.getMessage();
    SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
    SOAPHeader header = env.getHeader();
    header.detachNode();

But it will remove the complete header from the request if you want to do so. 但是,如果您愿意,它将从请求中删除完整的标头。 For removing specific header you need to write custom code like mentioned here 要删除特定的标头,您需要编写自定义代码,如此处所述

https://technology.amis.nl/2011/05/16/how-to-remove-unwanted-soap-header-elements-in-jax-ws/ https://www.w3schools.com/xml/dom_nodes_remove.asp https://technology.amis.nl/2011/05/16/how-to-remove-unwanted-soap-header-elements-in-jax-ws/ https://www.w3schools.com/xml/dom_nodes_remove。天冬氨酸

我可以使用以下内容清除标题,然后设置所需的元素。

soapHeaders.removeContents();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM