如果条件为真,则复制文件

时间:2013-02-11 03:51:41

标签: java file apache-camel

骆驼。文件组件。我需要配置路由,以便只有在没有错误发生时才复制文件。我有什么:

<route id="importFile" autoStartup="{{fdr.import.enabled}}">
            <from uri="direct:startImportFile"/>
            <from uri="file://{{fdr.folder.working}}?delete=true&amp;readLock=changed"/>
            <transacted ref="fdrTxRequired"/>
            <doTry>
                <to uri="file://{{fdr.folder.done}}"/> <!--1-->
                <bean ref="transactionsProcessor"/>
                <bean ref="transactionsFinalizer"/>
                <!--2-->
                <doCatch>
                    <exception>java.lang.Exception</exception>
                    <to uri="file://{{fdr.folder.failed}}"/>
                    <bean ref="exceptionProcessor"/>
                </doCatch>
                <doFinally>
                    <bean ref="responsePublisher"/>
                </doFinally>
            </doTry>
        </route>

所需逻辑: 如果在TransactionsProcessor和transactionsFinalizer中处理好了,那么我们只是将文件从'working'文件夹移动到'done'文件夹 如果在transactionProcessor或transactionsFinalizer中发生错误,那么我们将文件从'working'移动到'failed','done'必须为空 如果我将第1行放到占位符2,而不是在我的自定义处理器中处理之后无法将文件重新定位为InputStream。 也许我们可以从“工作”转变为“完成”。然后我们处理文件,如果确定然后确定。如果发生错误,则从“完成”移至“失败”。请帮助。

1 个答案:

答案 0 :(得分:0)

ou,我找到了解决方案 - 使用stopOnExeption进行多播

<routeContext id="fileImportOnlyRouteContext" xmlns="http://camel.apache.org/schema/spring">
        <route id="importFile" autoStartup="{{fdr.import.enabled}}">
            <from uri="direct:startImportFile"/>
            <from uri="file://{{fdr.folder.working}}?delete=true&amp;readLock=changed"/>
            <transacted ref="fdrTxRequired"/>
            <doTry>
                <multicast stopOnException="true">
                    <to uri="direct:startFileImporter"/>
                    <to uri="file://{{fdr.folder.done}}"/>
                </multicast>
                <doCatch>
                    <exception>java.lang.Exception</exception>
                    <to uri="file://{{fdr.folder.failed}}"/>
                    <bean ref="exceptionProcessor"/>
                </doCatch>
                <doFinally>
                    <bean ref="responsePublisher"/>
                </doFinally>
            </doTry>
        </route>

        <route id="fileImporterRoute">
            <from uri="direct:startFileImporter"/>
            <bean ref="transactionsProcessor"/>
            <bean ref="transactionsFinalizer"/>
        </route>
    </routeContext>