当 Soap Fault 调用 Java Web Service 时,我有这种响应
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:WaybillRegistrationFault xmlns:ns1="http://pod.waybillmanagement.ws.industrysystem.com.ar/">
<errors xmlns:ns2="http://pod.waybillmanagement.ws.industrysystem.com.ar/">
<code>80000</code>
<description>El número de CTG 20140904 ya existe</description>
</errors>
<errors xmlns:ns2="http://pod.waybillmanagement.ws.industrysystem.com.ar/">
<code>1000</code>
<description>La carta de porte ya se encuentra registrada.</description>
</errors>
</ns1:WaybillRegistrationFault>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
我用它的 handleFault 方法做了一个 Soap Handler:public boolean handleFault(SOAPMessageContext context){
try {
System.err.println("Handler handleFault");
if (context.getMessage().getSOAPBody().hasFault()) {
SOAPFault fa = context.getMessage().getSOAPBody().getFault();
System.err.println(fa.getFaultString());
System.err.println("FaultCode: " + fa.getFaultCode() + " - Detail: " + fa.getDetail());
}
return true;
} catch (SOAPException ex) {
System.err.println("SoapEx " + ex.getMessage());
return true;
}
}
但在我的输出中我只有:
Handler handleFault
Fault occurred while processing.
FaultCode: soap:Server - Detail: [detail: null]
如何处理错误节点?
更新:
用fa.getDetail().getFirstChild().getTextContent()
我得到 xml 中的文本。我如何将其作为对象。我认为这是一个 WaybillRegistrationFault。
2 回答
如果要将故障内容打印为 xml 字符串,则必须将 fa.getDetail()返回的 dom 实例转换为 String,fa.getDetail().toString() return [1]“而不是 xml 的内容。
尝试以下方法;
这是我总是处理肥皂故障错误的方式: