camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dusausoy <bdusau...@yp5.be>
Subject Route design
Date Sat, 11 May 2013 07:34:48 GMT
Hi,

I've set up a simple sandbox project[1] which polls a directory for 
files, sends them via ftp to a specific input directory. Then I wait for 
the server to transform the files. In the end I fetch them from another 
specific directory on the ftp server.

Basically my route is defined as is :

from("file:src/data?noop=true")
   .bean(ftpSender)
   .delay(10000)
   .bean(ftpReceiver)
   .log("End route");

ftpSender and ftpReceiver are Spring beans :


@Component
public class FtpSender {

     private final FtpProperties ftpProperties;

     @Autowired
     ProducerTemplate producerTemplate;

     @Autowired
     public FtpSender(FtpProperties ftpProperties) {
         this.ftpProperties = ftpProperties;
     }

     @Handler
     public String send(File file) throws InterruptedException {
         String fileName = file.getName();
         String uri = createInputFtpUri(fileName);
         producerTemplate.sendBody(uri, file);
         return fileName;
     }

     private String createInputFtpUri(String filename) {
         StringBuilder builder = new StringBuilder("ftp://")
                 .append(ftpProperties.getUsername()).append('@')
                 .append(ftpProperties.getHostname()).append(':')
                 .append(ftpProperties.getPort()).append('/')
                 .append(ftpProperties.getInputDirectory()).append('?')
 
.append("password=").append(ftpProperties.getPassword()).append('&')
                 .append("fileName=").append(filename).append('&')
 
.append("delete=").append(ftpProperties.isDeleteAfterConsumption());

         return builder.toString();
     }
}

My question is quite simple : is there a cleaner way to code this ?
I don't really like the route builder with the bean() method, I would 
like to use to() with URI's and some expression language or script.

Regards.

[1] https://github.com/bdusauso/sandbox-camel-dynamic-ftp
-- 
Bruno Dusausoy
Software Engineer
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Mime
View raw message