我是Spring-WS的新手,慢慢地將頭部纏繞起來。現在,我正在寫一個簡單的客戶端來與現有的WS進行通信。我正在使用WebServiceTemplate和marshalSendAndReceive方法。一切正常。如何解組FaultMessageResolver中的SOAP錯誤?
但是,當發生SOAP錯誤時,WST將引發SoapFaultClientException。我注意到我可以創建自己的FaultMessageResolver來檢查SOAP錯誤中包含的內容。然而,當我嘗試解編WebServiceMessage在我FaultMessageResolver,我得到了以下錯誤消息:
JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are ....
很顯然,我的解組配置不正確。我是否必須使用xjc自己生成JAXB故障模型,然後才能解組錯誤?我有些驚訝,這還不存在。
有沒有更好的方式來從我的soap:fault響應中額外添加自定義錯誤信息?我的錯誤看起來像下面這樣,我試圖提取/訪問serviceErrors項目。
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Blaze Data Error</faultstring>
<detail>
<ns14:serviceErrors xmlns="http://www.nb.com/ClientServices/LendingSimulation/CalculateProfitabilityRequest" xmlns:ns13="http://www.nb.com/fw/errorMgmt" xmlns:ns14="http://www.nb.com/ClientServices/LendingSimulation/V1" >
<ns13:faultstring>ServiceExecutionError</ns13:faultstring>
<ns13:serviceError>
<ns13:errorCode>C10F1013</ns13:errorCode>
<ns13:errorType>B</ns13:errorType>
<ns13:errorMessage>Unable to retreive additional data</ns13:errorMessage>
<ns13:fieldName>Message error received from PHClient : [An unexpected error code was received : system=PH context=[empty]]</ns13:fieldName>
<ns13:systemId>Calculator</ns13:systemId>
<ns13:time>2012-06-19 14:45:10.151-0400</ns13:time>
</ns13:serviceError>
</ns14:serviceErrors>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
謝謝!
埃裏克
謝謝。這幾乎是我最終做的。但是一次只能得到一個故障信息,我認爲這很奇怪。我本來期望一些系統允許我把所有的錯誤都列入一個列表或一系列錯誤中。 –