Reputation: 360
I'm having a bit of an issue with preventing the original file from being renamed when I throw/catch an Exception in a Processor.
I have a route like this:
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<process ref="Processor" />
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
The from URI includes the option of: &move=${file:name.noext}.${file:name.ext}.old
And during my Process, I stop the Exchange from being routed to the end under certain conditions and also throw an Exception that I catch using:
<onException>
<exception>com.myException.ThrownException</exception>
<handled><constant>true</constant></handled>
</onException>
Is there any way to prevent the renaming of the original file I'm pulling from if I throw and catch that exception?
(I throw and catch that Exception in order to prevent a file from entering a Idempotent File Repository for other routes. Many routes use this Processor.)
Upvotes: 1
Views: 702
Reputation: 360
So I think I may have found an answer.
So what I have found out is that by doing a global <onException>
block that catches my custom Exception, it will prevent logging a stack trace and entering in a file name into the File Repo for routes that use a Idempotent File Repository. But that global block will not prevent the routes that rename files from renaming the files.
In order to catch the Exception and prevent the logging of the stack trace on routes that rename files, I needed to use the doTry/doCatch blocks. I have to do something like this:
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<doTry>
<process ref="Processor" />
<doCatch><exception>com.myException.ThrownException</exception></doCatch>
</doTry>
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
So my solution ends up looking like this:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<onException>
<exception>com.myException.ThrownException</exception>
<handled><constant>true</constant></handled>
</onException>
<route customId="true" id="localRoute">
<from uri="{{ftp.pull.LOCAL.server}}" />
<doTry>
<process ref="Processor" />
<doCatch><exception>com.myException.ThrownException</exception></doCatch>
</doTry>
<to uri="{{ftp.push.LOCAL.route}}" />
</route>
<route customId="true" id="otherRoute">
<from uri="{{ftp.pull.OTHER.server}}" />
<setHeader headerName="otherFileRepoKey">
<simple>${file:name}-${file:modified}</simple>
</setHeader>
<idempotentConsumer messageIdRepositoryRef="otherFileStore">
<header>otherFileRepoKey</header>
<process ref="Processor" />
<to uri="{{ftp.push.OTHER.route}}"/>
</idempotentConsumer>
</route>
</camelContext>
Upvotes: 0
Reputation: 715
File will be renamed unless you remove the <handled>
or mark that as false.
If you handle the exception it won't propagate and your file component thinks that the Camel exchange processed successfully and it will rename the file.
Upvotes: 0