Spring&Web Service客户端-故障详细信息
时间:2020-03-06 14:25:25 来源:igfitidea点击:
如何获得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服务故障似乎是正确的:
<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:Body> <soapenv:Fault> <faultcode>soapenv:Client</faultcode> <faultstring>Validation error</faultstring> <faultactor/> <detail> <ws:ValidationError xmlns:ws="http://ws.x.y.com">ERR_UNKNOWN</ws:ValidationError> </detail> </soapenv:Fault> </soapenv:Body>
谢谢
威乐美
解决方案
来自Javadocs中的marshalSendAndReceive方法
看起来catch块中的SoapFaultClientException永远不会发生。
从API看来,确定故障详细信息的最佳选择是设置自定义故障消息接收器。
问题来自JAXB库