I need to parse file by rows. Each row handled separatly, using splitter component. After all rows were processed I need to copy file to done_folder. All works fine if all rows were processed correctly. But if there was incorrect row then I get the following warning about rollback and file do not copy to done_folder Warning:
WARN (Camel (com.company.realcardparser) thread #0 - file://project/src/test/resources/working_folder) [GenericFileOnCompletion] Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy@41a7d9e7 for file: GenericFile[237file09062012-qa.csv]
My camel config:
<camelContext id="com.company.realcardparser" xmlns="http://camel.apache.org/schema/spring" trace="true">
<routeContextRef ref="idtProxyRoute"/>
<endpoint id="fileParserInputEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.input}?delete=true&readLock=${idt.proxy.real.card.parser.readLock}&readLockCheckInterval=${idt.proxy.real.card.parser.readLockCheckInterval}&readLockTimeout=${idt.proxy.real.card.parser.readLockTimeout}&delay=${idt.proxy.real.card.parser.delay}"/>
<endpoint id="fileParserOutputEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.output}"/>
<endpoint id="fileParserOutputFailedEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.output.failed}"/>
</camelContext>
<bean id="idtTxRequired" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="transactionManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
</bean>
<routeContext id="idtProxyRoute" xmlns="http://camel.apache.org/schema/spring">
<route id="idtRealCardParserRoute">
<from ref="fileParserInputEndPoint"/>
<transacted ref="idtTxRequired"/>
<split>
<method bean="realCardParser" method="handle"/>
<to uri="bean:realCardFinalizer"/>
</split>
<to ref="fileParserOutputEndPoint"/>
</route>
</routeContext>
How to make camel ignore exceptions? I tried to surround splitter with try/catch block but it didn't help.
Claus Ibsen's answer directed me in the right path. However, it took me a little while to figure out how to do it.
onException(Exception.class)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// place to add logic to handle exception
Throwable caught = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Throwable.class);
logger.error("FATAL ERROR - ", caught);
}
})
.handled(true); // if I don't give handled(true), it will keep reprocessing the file again and again.
from("file:" + pathToFile + "?noop=true")
// rest of the route
http://camel.apache.org/exception-clause.html - explains more ways for error handling.