从SOAP响应中获取价值 [英] Get Value from SOAP response
本文介绍了从SOAP响应中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一句话:
SOAPMessage soapResponse = soapConnection.call(message,url);
并且回复看起来:
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>
如何从这样的soap响应中获取String中的StatusCode(3000)?
i试过 soapResponse.getSOAPBody()....
但我能得到的是:状态
how can i get StatusCode (3000) in String from such a soap response?
i tried soapResponse.getSOAPBody()....
but all i could get was :status
编辑:
所以我做了:
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);
}
但是获得了类强制转换异常
}
Edit2:解决方案:
but got class cast exception } Solution:
soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getDetail().getTextContent().trim().substring(0, 4));
推荐答案
- 从< a href =http://docs.oracle.com/javase/7/docs/api/javax/xml/soap/SOAPMessage.html\"rel =nofollow>
SOAPMessage
,你需要调用SOAPMessage#getSOAPPart()
获取SOAPPart
。 - 通过致电
SOAPPart#getEnvelope()
你可以获得SOAPEnvelope
。 - 接下来你得到
SOAPBo dy
使用SOAPEnvelope #getBody()
。 - 现在你可以得到
SOAPFault
通过调用SOAPBody #getFault()
。 - 接下来,您调用
SOAPFault#getDetail()
获取明细
。 - 使用
详细信息#getDetailIterator()
你可以迭代ov所有的DetailEntry
详细信息
对象。 - 由于
DetailEntry
接口扩展了SOAPElement
界面,您可以通过调用getChildElements()
;这样你就可以导航到Status
元素中的StatusCode
元素并获取它的值。 - Starting from the
SOAPMessage
, you need to callSOAPMessage#getSOAPPart()
to obtain aSOAPPart
. - By calling
SOAPPart#getEnvelope()
you can obtain theSOAPEnvelope
. - Next you get the
SOAPBody
usingSOAPEnvelope#getBody()
. - Now you can get the
SOAPFault
by callingSOAPBody#getFault()
. - Next, you call
SOAPFault#getDetail()
to obtain theDetail
. - Using
Detail#getDetailIterator()
you can iterate over all of theDetailEntry
s in theDetail
object. - Since the
DetailEntry
interface extends theSOAPElement
interface, you can get its content by callinggetChildElements()
; that way you can navigate to theStatusCode
element inside theStatus
element and get its value.
这篇关于从SOAP响应中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文