Mule始终使用默认的异常处理程序

时间:2014-02-24 06:39:35

标签: exception-handling mule mule-studio

我无法捕获由Poller组件触发的基本org.mule异常,Mule仍在使用默认机制(尝试全局或本地)

如果抛出以下异常,我想在Log it self中打印一些个人用于测试目的,一旦正常工作,将进一步增强。

Message               : Failed to move file "C:\Users\Administrator\Desktop\shared_folder\12131551.XML" to "C:\Users\Administrator\Desktop\archive\backup\12131551.XML.backup".  The file might already exist.
Code                  : MULE_ERROR-3
Exception stack is:
1. Failed to move file "C:\Users\Administrator\Desktop\shared_folder\12131551.XML" to "C:\Users\Administrator\Desktop\archive\backup\12131551.XML.backup".  The file might already exist. (org.mule.api.DefaultMuleException)
  org.mule.transport.file.FileMessageReceiver:553 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)

Root Exception stack trace:
org.mule.api.DefaultMuleException: Failed to move file "C:\Users\Administrator\Desktop\shared_folder\12131551.XML" to "C:\Users\Administrator\Desktop\archive\backup\12131551.XML.backup".  The file might already exist.
    at org.mule.transport.file.FileMessageReceiver.moveAndDelete(FileMessageReceiver.java:553)
    at org.mule.transport.file.FileMessageReceiver.access$400(FileMessageReceiver.java:62)
    at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:414)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

这是我的PoC

<file:connector name="XML_poller" autoDelete="false" streaming="false" validateConnections="true" pollingFrequency="5000" doc:name="File"/>
<file:connector name="output" doc:name="File" autoDelete="false" streaming="false" validateConnections="true"/>

<flow name="exceptionStrategyExample" doc:name="exceptionStrategyExample">
        <file:inbound-endpoint connector-ref="XML_poller" path="C:\Users\Administrator\Desktop\shared_folder" moveToDirectory="C:\Users\Administrator\Desktop\archive\backup"
            moveToPattern="#[header:originalFilename].backup" doc:name="Poller" responseTimeout="10000">
            <file:filename-wildcard-filter pattern="*.xml" caseSensitive="false"/>
        </file:inbound-endpoint>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" doc:name="HTTP"/>

    <choice-exception-strategy>
        <rollback-exception-strategy
                when="exception.causedBy(java.lang.IllegalStateException)"
                maxRedeliveryAttempts="3">
                <logger message="Retrying shipping cost calc." level="WARN" />
                <on-redelivery-attempts-exceeded>
                <logger message="Too many retries shipping cost calc."
                level="WARN" />
                <set-payload value="Error: #[exception.summaryMessage]"/>
                </on-redelivery-attempts-exceeded>
        </rollback-exception-strategy>
         <catch-exception-strategy  doc:name="Catch Exception Strategy" when="exception.causedBy(org.mule.*)">
                    <logger message="************TEST***************" level="INFO" doc:name="Logger"/>
        </catch-exception-strategy>
    </choice-exception-strategy>    
</flow>

根本没有做任何事......任何提示?

2 个答案:

答案 0 :(得分:0)

我认为这是一个系统异常的情况,其中没有创建可以被异常处理组件捕获的消息(有关系统与消息传递异常,请参阅Mule docs)。您可以尝试编写自定义消息接收器来覆盖processFile方法(请参阅this post获取灵感),或者手动检查是否存在重复文件并使用单独的文件:outbound-endpoint来编写文件。

答案 1 :(得分:0)

我找到了一个解决方法。在文件连接器之前插入处理器链元素并放置一个虚拟set-payload。通过这种方式,您将始终创建一条消息,然后它将不会使用DefaultExceptionStrategy来处理错误。