java - Mule MEL 用法和 ExceptionUtils.containsType(exception, type)

标签 java exception mule

我的 mule 流有一个如下所示的捕获异常策略:

<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)null 作为第二个参数发送给方法 containsTypeorg.mule.util.ExceptionUtils。当我将表达式更改为 org.mule.util.ExceptionUtils.containsType(exception, java.lang.IllegalArgumentException.class) 时,这一次 mule 说表达式错误并抛出异常。

所以我的问题是为什么表达式 org.mule.util.ExceptionUtils.containsType(exception, IllegalArgumentException.class) 将 null 发送到第二个参数?

谁能推荐一下?

最佳答案

如果您想对每种类型的异常实现不同的处理,您可以使用“选择异常策略”。这里有一个例子:

<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

关于java - Mule MEL 用法和 ExceptionUtils.containsType(exception, type),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33566561/

相关文章:

java - 使用 SWIG 在重载的 C++ 方法中设置类型

Java 堆大小未完全使用

python - 在ipython终端窗口点击生成MouseEvenT类型.MOUSE_DOWN异常

mule - 使用 Mule 4 在一封电子邮件中动态附加多个 csv 文件

java - Mulesoft 转换消息转义正斜杠

java - 关于在 eclipse 中使用库项目

java - 如何在 jOOQ 中打印异常

c# - 从异常中提取类和文件名

java - Spring Beans Mule - 接口(interface)/类类型的属性

java - 如何读取mule esb中的参数