2015-11-06 39 views
1

我騾流具有catch異常策略象下面這樣:騾MEL使用和ExceptionUtils.containsType(例外,類型)

<catch-exception-strategy when="org.mule.util.ExceptionUtils.containsType(exception, IllegalArgumentException.class)" 
       doc:name="Catch Exception Strategy"> 
    <logger message="IllegalArgumentException occurred" level="INFO" doc:name="logInfo" /> 
</catch-exception-strategy> 

表達org.mule.util.ExceptionUtils.containsType(exception, IllegalArgumentException.class)發送作爲第二個參數的類的方法containsTypeorg.mule.util.ExceptionUtils。當我將表達式更改爲org.mule.util.ExceptionUtils.containsType(exception, java.lang.IllegalArgumentException.class)時,這次騾子說表達式是錯誤的並引發異常。

所以我的問題是爲什麼表達式org.mule.util.ExceptionUtils.containsType(exception, IllegalArgumentException.class)發送null到第二個參數?

任何人都可以請建議?

回答

3

如果要針對每種類型的異常實施不同的處理,可以使用「選擇 - 異常策略」。這裏有一個例子:

<flow name="Sample_Flow"> 
... 
    <choice-exception-strategy doc:name="Choice Exception Strategy"> 
     <catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causedBy(org.mule.api.routing.filter.FilterUnacceptedException)]"> 
      <set-variable variableName="errorStatusCode" value="404" doc:name="Set status code"/> 
      <set-variable variableName="errorReasonPhrase" value="Not Found" doc:name="Set reason phrase"/> 
     </catch-exception-strategy> 
     <rollback-exception-strategy doc:name="Rollback Exception Strategy"> 
      <logger level="INFO" doc:name="Logger" message="Unknown error"/> 
     </rollback-exception-strategy> 
    </choice-exception-strategy> 
</flow> 

在您的具體實現,你可以嘗試的情況下,只需使用「拋出:IllegalArgumentException」,而不是「llegalArgumentException.class」:

<catch-exception-strategy when="org.mule.util.ExceptionUtils.containsType(exception, IllegalArgumentException)"> 
    <logger message="IllegalArgumentException occurred #[exception.getCauseException().getClass()] - #[IllegalArgumentException]: #[org.mule.util.ExceptionUtils.containsType(exception.getCauseException(), IllegalArgumentException)]" level="INFO" doc:name="logInfo" /> 
</catch-exception-strategy> 

分析我發現後表達式「IllegalArgumentException.class」返回null,但表達式「IllegalArgumentException」返回類。

您可以找到下一個環節的詳細信息: https://docs.mulesoft.com/mule-user-guide/v/3.7/choice-exception-strategy

+0

我非常瞭解選擇異常策略。你能否只提供相關的答案? –

+0

使用示例中的表達式,必要時更改包: when =「#[exception.causedBy(java.lang.IllegalArgumentException)]」 –

+0

請記住,答案適用於您和其他可能有類似問題的人問題,所以答案必須完整。有時最好根據文檔和經驗推薦最佳實踐。 –