Balaji Kannan
Balaji Kannan

Reputation: 417

Camel File polling - moved file to processed path without processing

Below is my camel file route with a delay set to 2000, which continuosly polls a folder {{ResponsePath}} and moves it to path {{ResponseProcessed}} on completion and to {{ResponseFailed}} on failure

<route id="fileProcessor">
    <from uri="file://{{ResponsePath}}?preMove={{ResponseInProgressPath}}/${header.CamelFileNameOnly}&amp;move={{ResponseProcessed}}/${header.CamelFileNameOnly}&amp;moveFailed={{ResponseFailed}}/${header.CamelFileNameOnly}&amp;delay=2000"/>
    <doTry>
        <convertBodyTo type="java.lang.String"/>
        <log message="Response ${body}"/>
        <bean ref="fileProcessorBean" method="processFile" />
        <log message="File Processed Successfully"/>
    <doCatch>
        <exception>com.test.CustomFileException
        </exception>
        <handled>
            <constant>true</constant>
        </handled>
    </doCatch>
    </doTry>
</route>

The problem Im facing is on loading multiple files to the polling folder, some of the files are processed and moved to PROCESSED path and some are directly moved to PROCESSED path without processing

Upvotes: 0

Views: 432

Answers (1)

burki
burki

Reputation: 7005

As @Screwtape already commented, all files are moved to PROCESSED path because you catch and handle exceptions.

  • A file is consumed
  • It is processed in the try block
  • If all goes well, it is moved by the file consumer to the PROCESSED path
  • If an exception occurs, it is handled by the catch block
  • Therefore the exception does not reach the file consumer
  • So the file consumer think all went well and moves it to the PROCESSED path

Remove the whole doTry/doCatch block so that exceptions reach the file consumer and it will move these files to the FAILED path.

Upvotes: 1

Related Questions