【问题标题】:SoapFaultClientException: outputting detailSoapFaultClientException:输出详细信息
【发布时间】:2017-11-14 03:10:29
【问题描述】:

我有一个 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>

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

提前感谢您的帮助

【问题讨论】:

    标签: java spring soap


    【解决方案1】:

    这应该可以工作

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

    【讨论】:

    • 上面解组的 SearchResponse 类是什么?
    【解决方案2】:

    gamepudi 方法的更通用版本:

    public <T> T soapFaultClientExceptionToCustomError(SoapFaultClientException e) {
        try {
            SoapFaultDetail soapFaultDetail = e.getSoapFault().getFaultDetail();
            SoapFaultDetailElement detailElementChild = soapFaultDetail.getDetailEntries().next();
            Source detailSource = detailElementChild.getSource();
            T customError = ((T) getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource));
            return customError;
        } catch (IOException e1) {
            //throw new IllegalArgumentException("Cannot unmarshal SOAP fault detail object: " + soapFaultDetail.getSource());
            return null;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      相关资源
      最近更新 更多