camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arhan <ant.arhi...@gmail.com>
Subject file processing, error handling
Date Fri, 07 Aug 2009 08:44:05 GMT

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?
-- 
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.


Mime
View raw message