检索/保留文件 - 如果在Apache Camel中使用带有onexception的“try .. catch”时catch块捕获到异常

时间:2017-12-15 11:37:53

标签: apache-camel

在以下路线中,我使用“try..catch”和onexception功能。 如果我的bean或外部的行中有任何异常,则try block..file被移动到“.error”,因为我使用了moveFailed选项但是在异常期间被try块生成的catch块捕获,文件迷路了..

    1.when server is down
    2.when connection timeout

请建议在此类失败/例外期间保留文件的方法

<camelContext streamCache="false" useMDCLogging="true" id="XXX" xmlns="http://camel.apache.org/schema/spring">
    <streamCaching spoolDirectory="/tmp/cachedir/#camelId#/#uuid#" spoolUsedHeapMemoryThreshold="70" bufferSize="65536" anySpoolRules="true" id="myCacheConfig"/>
    <onException >
        <description>An exception was encountered.</description>
        <exception>java.lang.Exception</exception>
        <log message="somemessage" loggingLevel="INFO"/>
    </onException>   
<route >        
    <from uri="file:D:/Users/Desktop/src?moveFailed=.error" />
    <transform>
        <method ref="somebean" method="somemethod"/>
    </transform>
    <doTry>  
        <to uri="file:D:/Users/Desktop/src" /> 
         <log message="transfered successfully" />           
         <doCatch>
            <exception>java.lang.Exception</exception>
                <log message="Exception occurred and Stopping the Route"/>
                <to uri="controlbus:route?routeId=XXXX&amp;action=stop"/>                       
               <log message="Stopped the Route:XXX"/>
        </doCatch>
    </doTry> 
</route>

请建议在此类失败/例外期间保留文件的方法

1 个答案:

答案 0 :(得分:1)

重新调整docatch-block中的异常以到达onException块。

     <doCatch>
        <exception>java.lang.Exception</exception>
            <log message="Exception occurred and Stopping the Route"/>
            <to uri="controlbus:route?routeId=XXXX&amp;action=stop&amp;async=true"/> // async=true to resume/finish this route                       
           <log message="Stopped the Route:XXX"/>
           <throwException  exception="java.lang.Exception"/> // dont know the exact syntax in xml dsl
    </doCatch>