SoapFaultClientException:输出详细信息

Gar*_*ead 0 java spring soap

我有一个 org.springframework.ws.soap.client.SoapFaultClientException 对象。我想获取其中包含的详细信息以用于记录目的,但我发现很难确定如何执行此操作。

exception.getFaultStringOrReason() 方法会给我一个基本的错误信息。但是,我需要获取包含在对象故障详细信息中的更多详细信息。SOAP 响应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <faultcode>soap:Client</faultcode>
  <faultstring>The values from the client failed to pass validation.</faultstring>
  <detail>
    <Errors>
      <Error reason="Required on input.">
        <ErrorLocation>
          <Node level="1" name="MyElement"/>
          <Node level="2" name="MyField"/>
        </ErrorLocation>
        <Parameters/>
        <StackTrace/>
      </Error>
    </Errors>
  </detail>
</soap:Fault>
Run Code Online (Sandbox Code Playgroud)

我已经遍历了许多 org.springframework.ws.soap.SoapFaultDetailElement 对象,但我无法获取其中包含的详细信息。这能做到吗?

提前感谢您的任何帮助

小智 7

这应该工作

} catch (SoapFaultClientException e) {
    log.error(e);
    SoapFaultDetail soapFaultDetail = e.getSoapFault().getFaultDetail();
    SoapFaultDetailElement detailElementChild = (SoapFaultDetailElement) soapFaultDetail.getDetailEntries().next();
    Source detailSource = detailElementChild.getSource();

    try {
        return (JAXBElement<SearchResponse>) getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource).getValue();
    } catch (IOException e1) {
        throw new IllegalArgumentException("cannot unmarshal SOAP fault detail object: " + soapFaultDetail.getSource());
    }
}
Run Code Online (Sandbox Code Playgroud)