我需要阅读SOAP标头。
下面是发送的xml:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.com/" xmlns:ns2="http://tech.com/">
<SOAP-ENV:Header>
<ns2:header id="ref1">
<session_id>63949bc1878725afd28cc8283ec3252a</session_id>
<ip_address>127.0.0.1</ip_address>
<user_agent>Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0</user_agent>
<last_activity>1362395880</last_activity>
<user_data></user_data>
<username>serge</username>
<logged_in>true</logged_in>
</ns2:header>
<ns2:header href="#ref1"/>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getInvo>
<id>1</id>
</ns1:getInvo>
</SOAP-ENV:Body>
我需要阅读包含session_id等的ns2:header内部...
最佳答案
您可以使用以下代码阅读
SOAPMessage soapMessage= context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
我们可以直接对soapheader进行解析,如下所示
NodeList nodes =soapHeader.getElementsByTagName("param");