[英]Get Value from SOAP response
I have such a line: 我有这样一行:
SOAPMessage soapResponse = soapConnection.call(message, url);
and response looks: 和响应看起来:
HTTP/1.1 200 OK
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 24 Jul 2013 07:44:39 GMT
Server: Apache-Coyote/1.1
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<TransactionID soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="1" xmlns="http://somelink"></TransactionID>
</soapenv:Header>
<soapenv:Body>
<soap-env:Fault xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:faultcode>Server</soap-env:faultcode>
<soap-env:faultstring>Server Error</soap-env:faultstring>
<soap-env:Detail>
<soap-env:Status>
<soap-env:StatusCode>3000</soap-env:StatusCode>
<soap-env:StatusText>Server Error</soap-env:StatusText>
<soap-env:Details></soap-env:Details>
</soap-env:Status>
</soap-env:Detail>
</soap-env:Fault>
</soapenv:Body>
</soapenv:Envelope>
how can i get StatusCode (3000) in String from such a soap response? 如何从这样的肥皂响应中获取String中的StatusCode(3000)? i tried
soapResponse.getSOAPBody()....
but all i could get was :status 我试过
soapResponse.getSOAPBody()....
但是我只能得到:status
EDIT: 编辑:
so i did: 所以我做了:
Detail detail = soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getDetail();
Iterator detailEntries = detail.getDetailEntries();
while (detailEntries.hasNext()) {
SOAPBodyElement bodyElement = (SOAPBodyElement) detailEntries.next();
Iterator val = bodyElement.getChildElements();
while (val.hasNext()) {
SOAPBodyElement bodyElement2 = (SOAPBodyElement) val.next();
String val2 = bodyElement2.getValue();
logger.debug("The Value is:" + val2);
}
but got class cast exception } Edit2: Solution: 但收到类强制转换异常} Edit2:解决方案:
soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getDetail().getTextContent().trim().substring(0, 4));
SOAPMessage
, you need to call SOAPMessage#getSOAPPart()
to obtain a SOAPPart
. SOAPMessage
开始,您需要调用SOAPMessage#getSOAPPart()
以获得SOAPPart
。 SOAPPart#getEnvelope()
you can obtain the SOAPEnvelope
. SOAPPart#getEnvelope()
,可以获得SOAPEnvelope
。 SOAPBody
using SOAPEnvelope#getBody()
. SOAPEnvelope#getBody()
获得SOAPBody
。 SOAPFault
by calling SOAPBody#getFault()
. SOAPBody#getFault()
获得SOAPFault
。 SOAPFault#getDetail()
to obtain the Detail
. SOAPFault#getDetail()
获得Detail
。 Detail#getDetailIterator()
you can iterate over all of the DetailEntry
s in the Detail
object. Detail#getDetailIterator()
可以遍历Detail
对象中的所有DetailEntry
。 DetailEntry
interface extends the SOAPElement
interface, you can get its content by calling getChildElements()
; DetailEntry
接口扩展了SOAPElement
接口,因此可以通过调用getChildElements()
获得其内容。 that way you can navigate to the StatusCode
element inside the Status
element and get its value. Status
元素内的StatusCode
元素并获取其值。 soapResponse.getBody().getFault().getFaultCode()
http://docs.oracle.com/javaee/5/api/javax/xml/soap/SOAPFault.html#getFaultCode() http://docs.oracle.com/javaee/5/api/javax/xml/soap/SOAPFault.html#getFaultCode()
and iterate on :
soapResponse.getBody().getFault().getDetailEntries()
http://docs.oracle.com/javaee/5/api/javax/xml/soap/Detail.html#getDetailEntries() http://docs.oracle.com/javaee/5/api/javax/xml/soap/Detail.html#getDetailEntries()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.