You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Mangiameli, Josiah" <jo...@urjanet.com> on 2013/04/25 16:51:32 UTC

Handle different route types in a single method

Hey All,


I am trying to write processor class that can process files retrieved from
different routes. Originally It was designed to handle email routes but I
also want to handle sftp, ftp or local file routes. However I am finding
that the ftp files are not delivered as a Message like an email is.

Is there a way that I could handle all different route delivery types in a
single process method like this?


*Here is how the routes are setup*

        try{
            context.addRoutes(new RouteBuilder() {
                    public void configure() throws Exception{
                        from(route).process(new FileProcessor());
                    }
                });
        }


*Here is how I am processing files and messages delivered*

public class FileProcessor implements Processor {

        public void process(Exchange exchange) throws Exception {

               Map<String, DataHandler> attachments =
exchange.getIn().getAttachments();



-- 
Josiah Mangiameli

Software Developer
Urjanet Energy Solutions

*(770) 262 9306*

Re: Handle different route types in a single method

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah you can use the same processor to handle messages from different routes.

There is a method on exchange that tells you the original endpoint
which created the Exchange.
getFromEndpoint
getFromRouteId

You can also just check if there is attachments, then its from mail etc.
Where as if not, then its from ftp/file etc.

attachments is only really used by a very few components such as mail
/ WS-* etc.





On Thu, Apr 25, 2013 at 4:51 PM, Mangiameli, Josiah
<jo...@urjanet.com> wrote:
> Hey All,
>
>
> I am trying to write processor class that can process files retrieved from
> different routes. Originally It was designed to handle email routes but I
> also want to handle sftp, ftp or local file routes. However I am finding
> that the ftp files are not delivered as a Message like an email is.
>
> Is there a way that I could handle all different route delivery types in a
> single process method like this?
>
>
> *Here is how the routes are setup*
>
>         try{
>             context.addRoutes(new RouteBuilder() {
>                     public void configure() throws Exception{
>                         from(route).process(new FileProcessor());
>                     }
>                 });
>         }
>
>
> *Here is how I am processing files and messages delivered*
>
> public class FileProcessor implements Processor {
>
>         public void process(Exchange exchange) throws Exception {
>
>                Map<String, DataHandler> attachments =
> exchange.getIn().getAttachments();
>
>
>
> --
> Josiah Mangiameli
>
> Software Developer
> Urjanet Energy Solutions
>
> *(770) 262 9306*



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen