编程语言
首页 > 编程语言> > java-如何在spring-ws中解析SoapFaultClientException

java-如何在spring-ws中解析SoapFaultClientException

作者:互联网

我正在使用spring-ws-2.3.1,在为网络服务创建客户端时,有时会收到如下所示的SoapFaultClientException,

<SOAP-ENV:Body>
  <SOAP-ENV:Fault>
     <faultcode>SOAP-ENV:Server</faultcode>
     <faultstring>There was a problem with the server so the message could not proceed</faultstring>
     <faultactor>InvalidAPI</faultactor>
     <detail>
        <ns0:serviceException xmlns:ns0="http://www.books.com/interface/v1">
           <ns1:messageId xmlns:ns1="http://www.books.org/schema/common/v3_1">5411</ns1:messageId>
           <ns1:text xmlns:ns1="http://www.books.org/schema/common/v3_1">Locale is invalid.</ns1:text>
        </ns0:serviceException>
     </detail>
  </SOAP-ENV:Fault>

我正在尝试获取ServiceException的“ messageId”和“ Text”,但我无法.请找到以下代码,

catch (SoapFaultClientException ex) {
        SoapFaultDetail soapFaultDetail = ex.getSoapFault().getFaultDetail(); // <soapFaultDetail> node
        // if there is no fault soapFaultDetail ...
        if (soapFaultDetail == null) {
            throw ex;
        }
        SoapFaultDetailElement detailElementChild = soapFaultDetail.getDetailEntries().next();
        Source detailSource = detailElementChild.getSource();
        Object detail = webServiceTemplate.getUnmarshaller().unmarshal(detailSource);
        System.out.println("Detail"+detail.toString());//This object prints the jaxb element
    }

“详细信息”对象返回JaxbElement.是否有任何优雅的方法来解析soap错误.

任何帮助,不胜感激.

解决方法:

最后,我可以解析出肥皂故障异常,

catch (SoapFaultClientException ex) {
    SoapFaultDetail soapFaultDetail = ex.getSoapFault().getFaultDetail(); // <soapFaultDetail> node
    // if there is no fault soapFaultDetail ...
    if (soapFaultDetail == null) {
        throw ex;
    }
    SoapFaultDetailElement detailElementChild = soapFaultDetail.getDetailEntries().next();
    Source detailSource = detailElementChild.getSource();
    Object detail = webServiceTemplate.getUnmarshaller().unmarshal(detailSource);
    JAXBElement<serviceException> source = (JAXBElement<serviceException>)detail;
    System.out.println("Text::"+source.getText()); //prints : Locale is invalid.
}

我没有找到其他优雅的方法,所以我希望这应该是解决方案.

标签:spring-ws,soapfault,web-services,spring,java
来源: https://codeday.me/bug/20191026/1933763.html