如何在 spring-ws 中解析 SoapFaultClientException [英] How to Parse SoapFaultClientException in spring-ws

查看:51
本文介绍了如何在 spring-ws 中解析 SoapFaultClientException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using spring-ws-2.3.1, While creating client for webservices sometime i am getting SoapFaultClientException like below,

<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",但我不能.请在下面找到代码,

I am trying to get the "messageId" and "Text" of the ServiceException but i couldn't.Please find the code below,

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
    }

detail"对象返回JaxbElement.有没有什么优雅的方法来解析soap错误.

The "detail" object returns the JaxbElement.Is there any elegant way to parse the soap fault.

应该感谢任何帮助.

推荐答案

终于可以解析soap错误异常了,

Finally,I can able to parse the soap fault exception,

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.
}

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

I don't find any other elegant way so i hope this should be the solution.

这篇关于如何在 spring-ws 中解析 SoapFaultClientException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆