camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Müller <christian.muel...@gmail.com>
Subject Re: Route design
Date Sat, 11 May 2013 07:46:20 GMT
Why do you not use the Camel FTP/SFTP/FTPS component?

Best,
Christian

Sent from a mobile device
Am 11.05.2013 09:35 schrieb "Bruno Dusausoy" <bdusausoy@yp5.be>:

> 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<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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message