spring & web service 客户端 - 故障详情

标签 spring service webservicetemplate

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

去年关闭。




Improve this question




如何获得 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>

谢谢

威洛姆

最佳答案

我还遇到了 getFaultDetail() 返回 null(对于 SharePoint Web 服务)的问题。我可以使用与此类似的方法获取 detail 元素:

private 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);
}

之后,您可以对返回的 Element 或您想要的任何内容调用 getTextContent()。

关于spring & web service 客户端 - 故障详情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/100990/

相关文章:

java - 新查找器不生成实现(M3)

Angular/RxJs - 使用 take(1) 取消订阅依赖的 http 服务?

android - 如何将 ListView 适配器中的项目绑定(bind)到服务?

java - 处理来自 Spring 的 WebServiceTemplate.marshalSendAndReceive 的错误响应

java - 验证后重新提交表单的问题

java - 如果appendAllowed 设置为true,writeHeader() 仍在运行吗?

java - Gradle 无法解析 Spring Boot HATEOAS 依赖项

debugging - Visual Studio 远程调试服务

java - WebServiceTemplate对象初始化一次后为null