我如何获得SoapFaultClientException发送的故障详细信息?
我使用WebServiceTemplate,如下所示:
WebServiceTemplate ws = new WebServiceTemplate();
ws.setMarshaller(client.getMarshaller());
ws.setUnmarshaller(client.getUnMarshaller());
try {
MyResponse resp = (MyResponse) = ws.marshalSendAndReceive(WS_URI,req);
} catch (SoapFaultClientException e) {
SoapFault fault = e.getSoapFault();
SoapFaultDetail details = e.getSoapFault().getFaultDetail();
//details always NULL ? Bug?
}
发送的Web服务错误似乎是正确的:
谢谢
Willome
最佳答案
我还遇到了getFaultDetail()返回null(对于SharePoint Web服务)的问题.我可以通过使用类似于此的方法来获取detail元素:
原文链接:https://www.f2er.com/spring/431611.htmlprivate Element getDetail(SoapFaultClientException e) throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMResult result = new DOMResult();
transformer.transform(e.getSoapFault().getSource(),result);
NodeList nl = ((Document)result.getNode()).getElementsByTagName("detail");
return (Element)nl.item(0);
}