2017-04-10 181 views
-1

我使用的彈簧WS-2.3.1,同時爲web服務客戶端的某個時候我得到SoapFaultClientException像下面,如何解析SoapFaultClientException春季-WS

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

我試圖讓「MESSAGEID」和ServiceException的「文本」,但我couldn't.Please找到下面的代碼,

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.Is有任何優雅的方式來解析SOAP錯誤。

任何幫助,不勝感激。

回答

0

最後,我可以能夠解析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. 
} 

我沒有找到,所以任何其他優雅的方式,我希望這應該是解決方案。