【问题标题】:How to throw exception manually in Mule ESB without using java code如何在不使用 java 代码的情况下在 Mule ESB 中手动抛出异常
【发布时间】:2016-05-26 01:23:53
【问题描述】:

我是 mule 新手,请帮助我了解这个逻辑。实际上,在我的流程中,我有选择消息处理器,不满足的表达式将默认选择。之后我有流量参考。 我不希望消息进入默认(选择)必须填充到流引用。相反,它必须转到我在该流中配置的选择异常策略。 所以我需要默认抛出一些异常。 其实我有一个很大的流量,我让它很容易理解。请通过xml配置查找。

        <flow name="Choice" doc:name="Choice">
    <file:inbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath1" responseTimeout="10000" doc:name="File"/>
    <byte-array-to-string-transformer doc:name="Byte Array to String"/>
    <choice doc:name="Choice">
        <when expression="#[xpath('fn:local-name(/root/*[2])')=='book']">
            <file:outbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath2" responseTimeout="10000" doc:name="File"/>
        </when>
        <otherwise>
            <file:outbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath3" responseTimeout="10000" doc:name="File"/>
        </otherwise>
    </choice>
    <flow-ref name="SampleService" doc:name="Flow Reference"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <logger message="*****#[exception]****" level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</flow>
<flow name="SampleService" doc:name="SampleService">
    <file:inbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath4" responseTimeout="10000" doc:name="File"/>
</flow>

请建议我在 Mule 中抛出异常的任何标准方法。我也尝试保留

            <test:component  throwException="true"/> 

但它会抛出异常,例如 - “元素“test:component”的前缀“test”未绑定”。

【问题讨论】:

    标签: mule mule-studio mule-el


    【解决方案1】:

    要使用test:component,您需要声明test 命名空间,就像Mule 使用的所有其他命名空间一样。这就是说,不确定您是否要在生产代码中使用 test 元素。

    另一种方法是使用null-component,它在收到消息时总是抛出异常,但这并不能让您控制抛出的异常。

    另一种选择是从 Groovy 组件中抛出您想要的任何异常。

    请记住,异常由 Mule 基础架构包装:您必须使用 ExceptionUtils 来挖掘堆栈并找到根本原因。

    【讨论】:

    【解决方案2】:

    如果您不想编写代码,也可以使用验证组件。只需创建一个新的“Is True”验证器并将表达式设置为 #[false]。在自定义页面上设置您的错误和您想要返回的消息,我使用了 org.mule.module.apikit.exception.NotFoundException,但您也可以使用查找。我花了很长时间才弄清楚这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 2014-08-26
      • 2018-10-05
      • 1970-01-01
      相关资源
      最近更新 更多