On Fri, Aug 7, 2009 at 10:44 AM, arhan<[email protected]> wrote:
>
> Hi,
>
>
> I have a case where the files are being consumed from a directory (quite
> simple), processed, and backed up:
>
> public void configure() {
>   String filesUri = "file:files" +
>
> "?move=files/backup/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml";
>
>   from(filesUri)
>     .process(new Processor() {
>       public void process(Exchange exchange) throws Exception {
>         //some processing done here
>       }
>     })
>     .to("log:mylogger?level=DEBUG");
>  }
>
> now, if the processing fails (some business logic issues), and the processor
> throws an exception, I'm required to rename the file to, adding an 'error'
> suffix. Here's what I did:
>
> public void configure() {
>   String filesUri = "file:files" +
>
> "?move=files/backup/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml";
>
>   onException(Exception.class).handled(true).
>
> to("file:files/error?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.xml.error").
>   end();
>
>   from(filesUri)
>     .process(new Processor() {
>       public void process(Exchange exchange) throws Exception {
>         exchange.setException(new Exception("could not process file "));
>         //throw new Exception("could not process file ");
>       }
>     })
>     .to("log:mylogger?level=DEBUG");
>  }
>
>
> Now the exception is being handled, and the file is renamed to
> 'file.xml.error', but the move expression still handles the file as if it
> was successfully handled, so that same copy of the file is now in
> files/backup and files/error directories. Could there be a way to move the
> failed files only once, without copying the failed file to files/backup?

Hi

Interesting use-case I guess we need to move expressions, one for
success and one for failure to give you full power.

You can use onCompletion on your file route and then move the file
yourself as you got callbacks for onCompletion = OK, onFailure = ERROR
And set noop=true on the file endpoint instead of move option.

But let me create a ticket for the moveFailure option, so we can try
to get it in 2.0 before it goes final.
I recall other have had similar use case before.



> --
> View this message in context: 
> http://www.nabble.com/file-processing%2C-error-handling-tp24861063p24861063.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to