簡體   English   中英

在將消息發布到服務器之前,如何從SOAP請求中刪除標頭元素

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

我有一個如下的SOAP請求。 在將請求發送到服務器之前,我想從SOAP標頭中刪除“ SessionType”和“ SessionToken”。

請指導。

<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>

問候米蘭

你可以試試

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

但是,如果您願意,它將從請求中刪除完整的標頭。 要刪除特定的標頭,您需要編寫自定義代碼,如此處所述

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