2017-06-13 32 views
0

我在基於XML的彈簧上下文文件中定義了駱駝上下文。 有一條路由,正在由SOAP(XML)Web服務客戶端bean調用。 在調用路由時,它會拋出一些異常,並且客戶端接收到Camel異常,而不是原始異常。向客戶端返回原始異常,而不是返回CamelExecutionException Apache Camel

對異常客戶端駱駝響應如下所示


<soap:Fault> 
    <faultcode>soap:Server</faultcode> 
    <faultstring>Exception occurred during execution on the exchange: Exchange[ID-CZC4101XJV-53724-1497351782614-9-2]</faultstring> 
    </soap:Fault> 

預期響應應該是原始異常消息上 任何異常


<soap:Fault> 
    <faultcode>soap:Server</faultcode> 
    <faultstring>blah blah blah Number Not valid, I am the original exception</faultstring> 
    </soap:Fault> 

這裏是我的駱駝路線定義

<route> 
     <from uri="direct:remove" /> 
     <to uri="bean:removeBean?method=validationNubmer" /> 
     <to uri="bean:removeBean?method=checkBusiness" /> 
     <to uri="bean:removeBean?method=triggerRemove" /> 
    </route> 

而且低於該發送XML請求 路由SOAP豆操作

public void removeMe(String id) { 
    RemoveRequest request = new RemoveRequest(); 
    request.setId(id); 
    producer.requestBody("direct:remove", request); 
} 

我宣讀了Apache的駱駝文檔中的例外條款的話題,但我無法找到如何原始異常返回給客戶端,傷心的任何信息!任何幫助?

我用駱駝onException的嘗試,但沒有運氣:(

<onException> 
     <exception>java.lang.Exception</exception> 
     <redeliveryPolicy maximumRedeliveries="0" /> 
     <handled> 
      <constant>true</constant> 
     </handled> 
     <transform> 
      <simple>Error Occurred: ${exception.message}</simple> 
     </transform> 
    </onException> 

回答

0

您可以打開handleFault讓異常自動轉化爲SOAP錯誤。見駱駝在行動2本書第11章,其中有一個小例子:https://github.com/camelinaction/camelinaction2/tree/master/chapter11/errorhandler#1136---handling-faults

或者你需要使用<setFaultBody>而不是<transform>告訴駱駝要設置郵件正文爲SOAP錯誤

0123。
+0

謝謝克勞斯,我嘗試了兩種選擇,一個接一個,但沒有運氣。 – Ash

+0

謝謝克勞斯,對不起,遲到添加我的意見,因爲我想先測試。我嘗試了兩個選項,一個接一個,但沒有運氣。最初的項目是在藍圖中,我在那裏對你的建議進行了測試,但結果是一樣的,所以我想,這可能是因爲藍圖依賴關係。後來我把這個項目遷移到了駱駝的春季引導,並且運用了你的建議,但是再次沒有運氣。我想我可能會錯過一些東西,因爲我可以回想起過去曾在camelContext上使用'handleFalt',它已經奏效。我正在使用駱駝2.19.0。任何建議@克勞斯 – Ash