2

有谁知道如何在 MULE 中处理未检查/运行时异常..??

我的意思是,在我的 java 代码中,出于某种原因,我正在“抛出异常”,我希望 Mule 检测到它并将其路由到正确的流程,在那里我可以记录或打印该异常。

那么,我究竟应该在 Mule 配置文件中的“流程”中放置什么来实现这一点。

我的 Java 代码:

public Object xyz (Map payload) throws Exception {
    if (payload.isEmpty()) {
        throw new Exception ("New Exception") ;
    }
}

我的骡子配置文件:

<flow name="APIAuthenticate">

    <http:inbound-endpoint address="http://localhost:1212/jcore/authorize" transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJson" contentType="application/json" encoding="UTF-8">
        <not-filter>
            <wildcard-filter pattern="/favicon.ico"/>
        </not-filter>
    </http:inbound-endpoint>

    <component class="main.java.com.abc.XYZ"/>

</flow>

任何帮助将不胜感激..!!

4

2 回答 2

2

Ok..i did some hit and trial and i figured out that

  • When the Exception is thrown, an Exception Strategy is required like default-exception-strategy OR custom-exception-strategy is required, that would route the flow to some Class that would handle it and do required Actions.

  • But When we Return an Exception (like below), then we can use the exception-payload-filter or choice attribute of Mule to handle it.

    public Object xyz (Map payload) throws Exception {
        if (payload.isEmpty()) {
            return new Exception ("New Exception") ;
        }
    }
    

Please Correct me if i am wrong..??

Also if there are other answers to this question, please be kind to put them..

于 2011-11-09T04:35:06.567 回答
2

在流程中配置默认​​异常策略应该允许您捕获异常(甚至是运行时异常)并处理它们。

阅读错误处理参考指南以获取更多信息。

于 2011-11-08T18:26:19.883 回答