2014-10-06 88 views
0

流中的傳出HTTP端點返回狀態500,但Mule不引發異常。當我步調試流程,顯然存在一個例外有效載荷目前HTTP調用後,但貫穿始終的流動遊行:Mule HTTP端點返回狀態500但不會拋出異常

<flow name="pocFlow2" doc:name="pocFlow2"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" path="poc/error" doc:name="HTTP"/> 
    <!-- This one returns 500 error --> 
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/> 
    <object-to-string-transformer doc:name="Object to String"/> 
    <set-payload value="All good" doc:name="Set Payload"/> 
    <catch-exception-strategy doc:name="Catch Exception Strategy"> 
     <logger level="INFO" doc:name="Logger"/> 
    </catch-exception-strategy> 
</flow> 

這是預期的行爲?每次HTTP調用後,我都必須自己拋出錯誤嗎?

回答

0

是的,您需要檢查響應的狀態代碼並採取適當的措施。 Mule不知道你在做什麼,或者你期望什麼狀態碼,所以http連接器不會拋出異常。關於騾的一個小問題是,沒有簡單的方法來拋出異常。我寫了一個非常簡單的小ExceptionThrower java類來處理這種情況。

<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/> 
    <choice doc:name="Choice"> 
     <when expression="#[message.inboundProperties['http.status'] == '200']"> 
      <!-- Handle my payload --> 
     </when> 
     <otherwise> 
      <!-- This isn't what I expected, so throw an exception to let the catch-exception-strategy handle it. --> 
      <component class="com.example.ExceptionThrower" doc:name="Java"/> 
     </otherwise> 
    </choice> 
+0

在這條大道上,我會保持簡單並創建一個HttpResponseResolver類,它可以拋出或不拋出 - 即將狀態檢查烘焙到類中。這樣,您可以將它附加到HTTP的響應變換器,並且沒有額外的塊。最終,可以擴展HTTP組件本身(使用devkit)。國際海事組織有點不贊成騾子,不運送這個OTB。 – Gilbert 2014-10-07 16:11:14

相關問題