我有这样一句话:
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)?
我试过soapResponse.getSOAPBody()....
,但我能得到的只是:状态
编辑:
所以我做了:
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:解决方案:
soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getDetail().getTextContent().trim().substring(0, 4));
答案 0 :(得分:2)
SOAPMessage
开始,您需要致电SOAPMessage#getSOAPPart()
以获取SOAPPart
。SOAPPart#getEnvelope()
,即可获得SOAPEnvelope
。SOAPBody
获得SOAPEnvelope#getBody()
。SOAPFault
来获取SOAPBody#getFault()
。SOAPFault#getDetail()
获取Detail
。Detail#getDetailIterator()
,您可以迭代Detail
对象中的所有DetailEntry
。DetailEntry
界面扩展了SOAPElement
界面,您可以通过调用getChildElements()
获取其内容;这样,您就可以导航到StatusCode
元素中的Status
元素并获取其值。答案 1 :(得分:0)
soapResponse.getBody().getFault().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()