2016-11-29 91 views
0

在我的駱駝路由中,我正在對現有的bundle進行直接-vm調用。在那項服務中,他們已經處理了異常情況並設置了一些自定義錯誤消息。當該服務發生任何異常時,它們將發送如下所示的錯誤消息。在Apache駱駝中修改處理的異常錯誤消息

{ 
"errorCode": "400", 
"errorMessage": "Unknown error" 
} 

但我需要根據收到的故障消息形成我自己的自定義故障消息。但是,一旦第二包發生異常,我無法收回故障信息並對其進行修改。下面是我的路線。

<route handleFault="true" streamCache="true" id="route1"> 
    <from uri="cxfrs://bean://testCxf?synchronous=true"/> 
    <log message="The consumer message ${body}"/> 
     <bean ref="requestValidator" method="validateRequest"/> 
     <to uri="direct-vm:retrieveData"/> 
     <bean ref="validateResponse" method="validate"/>//need to manipulate the fault message coming from bundle 2 in this bean. 
    <onException> 
     <exception>java.lang.Exception</exception> 
     <handled> 
     <constant>true</constant> 
     </handled> 
     <bean ref="faultMapper" method="mapFault"/> 
    </onException> 
    </route> 

下面是現有的直接:vm路由。

<route handleFault="true" streamCache="true" id="route2"> 
    <from uri="direct-vm:retrieveData"/> 
     <bean ref="manipulateData" method"manipulate"/> 
     <onException> 
      <exception>java.lang.Exception</exception> 
      <handled> 
      <constant>true</constant> 
      </handled> 
      <bean ref="faultMapper1" method="mapFault1"/> 
     </onException> 
    </route> 

我需要直接-VM call.How後攔截在類faultmapper1映射故障,在我ROUTE1以達致這?我不會允許在現有的第二包中更改任何內容。提前致謝。

+0

我不認爲這是可能的。但是更好的設計將是在單獨的路由中執行定製錯誤消息處理,這取決於例如特定報頭會生成自定義錯誤消息。當您的路由發出請求並且發生錯誤時,將使用標題等等。更容易改變。 –

回答

0

經過一番研究發現,這是不可能的。爲了達到這個要求,我在第二條路線中將處理常量設爲假,並在第一條路線中添加了一個塊。這樣我就可以捕獲拋出的異常並通過一些自定義錯誤映射來處理它。