【问题标题】:Exceptions not been catched on Camel Spring DSLCamel Spring DSL 未捕获异常
【发布时间】:2015-10-16 18:42:32
【问题描述】:

我正在使用 Camel 路由将 csv 文件转换为 XML,使用 Spring DSL。我使用带有注释类和 .xsd 的 JAXB 来验证结果。

在路线上,我使用了 doTry/doCatch 代码块。如果发生任何异常,我会将实际消息写入文件。我还使用自定义流程将 CSV 文件转换为我的带注释类的实例。我的问题如下: 例如,如果我在 .xsd 文件中更改名称,则会引发异常,并且在路由中,执行 doCatch sn-p 并将消息写入文件。但如果我的处理器抛出异常,doCatch 将被忽略。

<route>
    <from uri="file://C:/a"/>   


        <doTry>     
        <unmarshal><csv delimiter=","/></unmarshal>
        <process ref="myProccesor"/>
        <marshal ref="jb"></marshal>
        <to uri="file://C:/ok"/> 
        <doCatch>
            <exception>java.lang.Exception</exception>
            <to uri="file://C:/nok"/>
        </doCatch>
    </doTry>
  </route>

【问题讨论】:

  • 那么,如果没有人看到你的代码如何,应该如何提供帮助?
  • myProcessor 抛出的异常没有被 doCatch 语句捕获。
  • 抛出什么样的异常?尝试捕捉 java.lang.Throwable 看看会发生什么

标签: spring exception apache-camel


【解决方案1】:

你确定,doCatch 被忽略了吗?它应该捕获您的异常,但您必须告诉骆驼异常已处理。没有这只骆驼就抓不住它。在&lt;exception&gt;&lt;/exception&gt;之后添加

<handled>
    <constant>true</constant>
</handled>

【讨论】:

    猜你喜欢
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 2012-05-31
    相关资源
    最近更新 更多