2016-12-28 51 views
0

我的一個SOAP Web服務的使用者無法讀取SOAP Faults(模式驗證),因此他希望我們發送「Ok = false」響應,而不是發生模式驗證消息失敗。是否可以在Apache CXF和Spring SOAP WS中發送Interceptors的「False」響應?

我不知道,如果我們以任何方式可以自定義攔截器來產生錯誤的響應,而不是SOAP故障。

我使用攔截器如下圖所示

@org.apache.cxf.interceptor.InInterceptors(interceptors = {"com.xxx.piano.services.interceptors.RequestParserInterceptor", 
    "com.xxx.piano.services.interceptors.RequestInterceptor"}) 
@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN) 
@org.apache.cxf.interceptor.OutFaultInterceptors(classes = RequestParsingValidator.class) 

截至今天我越來越像下面

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
    <soap:Fault> 
    <faultcode>soap:Server</faultcode> 
    <faultstring>[City is empty !] </faultstring> 
    </soap:Fault> 
</soap:Body> 
</soap:Envelope> 

雖然我想類似下面故障,則產生今天的故障:

<ns3:XXXServiceTypeResponse> 
     <OK>false</OK> 
     <Error> 
      <Message>Duplicate Product Individual Identifier.</Message> 
      <TechnicalDescription>Postal Code Missing</TechnicalDescription> 
      <ErrorCode>E0022</ErrorCode> 
     </Error> 
     <ns3:ResponseID>01202662-0010-0001-0001-4617844469</ns3:ResponseID> 
    </ns3:XXXServiceTypeResponse> 

請幫助。

回答

0

隨着攔截器是可以自定義的響應,但我不建議返回一個消息,是不存在的WSDL,它是客戶端和服務器之間的合同。

相反,它會提高,答案有錯誤代碼,而不是產生SOAP錯誤。通過這種方式,您的客戶端也將能夠自動生成他的編程語言的代碼。

每封郵件有狀態(正常),錯誤的詳細信息,以及通常的反應,如果狀態正確

<ns3:XXXServiceTypeResponse> 
     <OK>false</OK> 
     <Error> 
      <Message>Duplicate Product Individual Identifier.</Message> 
      <TechnicalDescription>Postal Code Missing</TechnicalDescription> 
      <ErrorCode>E0022</ErrorCode> 
     </Error> 
     <ns3:ResponseID>01202662-0010-0001-0001-4617844469</ns3:ResponseID> 
     <ns3:ResponseIfOk /> 
    </ns3:XXXServiceTypeResponse> 
+0

不知道我是否正確理解@pedrofb。 您的意思是我們應該嘗試將錯誤轉換爲響應對象。 但我這裏的消費者不能在我的情況下解析錯誤響應。 :( –

+0

確定我的英文不太好,我建議不要使用錯誤並改變對象模型,而應該在業務邏輯中引發錯誤,而不要在異常中捕獲異常並將錯誤代碼作爲返回對象的屬性返回。包括在你的響應消息中的每一個該屬性。該方案是在肥皂很常見的,以避免使用錯誤(我更喜歡如果可能使用故障) – pedrofb

+0

感謝。 但後來我想構建驗證失敗消息的標準響應。 我看過其他地方,這是不可能從CXF攔截器創建ServiceResponse消息 將是巨大的,如果你能解釋這樣做的soome好辦法 –