2017-10-06 49 views
0

我有一個由Tomcat服務器提供的Content-Type = application/json的其餘API。 這意味着所有的響應應該是json格式。終點響應中的不同內容類型

其餘API由WSO2 ESB調用以傳遞一些數據。

如果提供其他API的應用程序關閉(但tomcat服務器仍然運行),則tomcat服務器用Content-Type = text/html重新發送http代碼= 404(發送HTML頁面「所請求的資源不可用。「)ESB錯誤」構建消息時出現錯誤「異常和ESB崩潰並丟失消息的結果。

您能否建議如何處理這種情況?我需要收到消息並對此事件做出反應。有沒有辦法如何動態切換內容類型?

回答

0

你可以試試這個用自己的修改:

<?xml version="1.0" encoding="UTF-8"?> 
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault_filter_based_http_status_code" trace="disable"> 
    <filter regex="401" source="get-property('axis2', 'HTTP_SC')"> 
    <then> 
     <makefault version="soap11"> 
     <code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Server"/> 
     <reason value="Unauthorized to access the resource"/> 
     <role/> 
     </makefault> 
     <send/> 
    </then> 
    <else/> 
    </filter> 
    <filter regex="500" source="get-property('axis2', 'HTTP_SC')"> 
    <then> 
     <makefault version="soap11"> 
     <code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:Server"/> 
     <reason value="Internal Server Error Occurred"/> 
     <role/> 
     </makefault> 
     <send/> 
    </then> 
    <else/> 
    </filter> 
</sequence> 

請看:http://harshcreationz.blogspot.com/2016/02/common-and-error-handling-sequences.html

+0

喜豪爾赫,謝謝你,我已經嘗試過類似的東西,但問題是,建立在消息失敗該響應,因此還沒有可用的http代碼。奇怪的是,即使是FAULT序列沒有輸入 –

+0

你能分享服務器響應嗎? –

相關問題