1

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

4

2 回答 2

4

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

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

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

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

于 2013-10-14T17:40:40.613 回答
1

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

于 2016-05-25T17:23:53.807 回答