Java SoapFaultClientException:输出详细信息

Java SoapFaultClientException:输出详细信息,java,spring,soap,Java,Spring,Soap,我有一个org.springframework.ws.soap.client.SoapFaultClientException对象。我希望获得其中包含的详细信息,以便进行日志记录,但我发现很难确定如何做到这一点 getFaultStringOrReason()方法将给我一条基本错误消息。但是,我需要获得更多细节,这些细节保存在对象的故障细节中。SOAP响应如下所示: <?xml version="1.0" encoding="UTF-8"?> <soap:Fault xmlns

我有一个org.springframework.ws.soap.client.SoapFaultClientException对象。我希望获得其中包含的详细信息,以便进行日志记录,但我发现很难确定如何做到这一点

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>

soap:客户端
来自客户端的值未能通过验证。
我已经遍历了许多org.springframework.ws.soap.SoapFaultDetailElement对象,但无法获得其中包含的详细信息。这能做到吗

提前感谢您提供的任何帮助

这应该行得通

} 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());
    }
}
}catch(SoapFaultClientException e){
日志错误(e);
SoapFaultDetail SoapFaultDetail=e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild=(SoapFaultDetailElement)soapFaultDetail.getDetailEntries().next();
Source detailSource=detailElementChild.getSource();
试一试{
return(JAXBElement)getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource).getValue();
}捕获(IOE1异常){
抛出新的IllegalArgumentException(“无法解组SOAP错误详细信息对象:+soapFaultDetail.getSource());
}
}
这应该行得通

} 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());
    }
}
}catch(SoapFaultClientException e){
日志错误(e);
SoapFaultDetail SoapFaultDetail=e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild=(SoapFaultDetailElement)soapFaultDetail.getDetailEntries().next();
Source detailSource=detailElementChild.getSource();
试一试{
return(JAXBElement)getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource).getValue();
}捕获(IOE1异常){
抛出新的IllegalArgumentException(“无法解组SOAP错误详细信息对象:+soapFaultDetail.getSource());
}
}

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;
    }
}
public T soapFaultClientExceptionToCustomError(SoapFaultClientException e){
试一试{
SoapFaultDetail SoapFaultDetail=e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild=soapFaultDetail.getDetailEntries().next();
Source detailSource=detailElementChild.getSource();
T customError=((T)getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource));
返回自定义错误;
}捕获(IOE1异常){
//抛出新的IllegalArgumentException(“无法解组SOAP错误详细信息对象:+soapFaultDetail.getSource());
返回null;
}
}

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;
    }
}
public T soapFaultClientExceptionToCustomError(SoapFaultClientException e){
试一试{
SoapFaultDetail SoapFaultDetail=e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild=soapFaultDetail.getDetailEntries().next();
Source detailSource=detailElementChild.getSource();
T customError=((T)getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource));
返回自定义错误;
}捕获(IOE1异常){
//抛出新的IllegalArgumentException(“无法解组SOAP错误详细信息对象:+soapFaultDetail.getSource());
返回null;
}
}

上面正在解组的SearchResponse类是什么?上面正在解组的SearchResponse类是什么?