SoapFaultClientException:输出细节

时间:2017-11-14 03:10:30

标签: 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>

我已经迭代了一些org.springframework.ws.soap.SoapFaultDetailElement对象但我无法获得其中包含的详细信息。可以这样做吗?

提前感谢您的任何帮助

2 个答案:

答案 0 :(得分:3)

这应该有效

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

答案 1 :(得分:0)

gamepudi 方法的更通用版本:

set @Sql_Search_Table ='select '+@id+'=id from ##Insert_Data where ....'
exec sp_executesql @Sql_Search_Table
set @temp = @id

--I want to get **id from above exec** and pass to another statement below
set @Sql_Table = 'insert into ##Insert_Data
                      select name from tbl where id='+@temp+'