camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: File Reading & Writing using Camel
Date Fri, 01 Jul 2011 08:58:22 GMT
On Fri, Jul 1, 2011 at 10:50 AM, Gnanaguru S
<> wrote:
> Hi Claus,
> Thanks. I will look into it. Let have this code
> <camelContext xmlns="">
>      <route>
>        <from uri="file://inputdir/"/>
>        <log message="Moving ${file:name} to the output directory"/>
>        <to uri="file://outputdir/"/>
>      </route>
>    </camelContext>
> I want to modify to the above code, such that i can read the contents of a
> file. By the way it will be much helpful for me understand . Since i am new
> to this arena.
> Where are the description for route,from,to,log and all. What are the other
> things available, with which i can read the contents of a file and also
> other operations. Help me out.

What do you want to do with the file? You say read the content. Do you
want to read it from some Java code?
If so you can use regular java beans with Camel.

        <from uri="file://inputdir/"/>
        <log message="Moving ${file:name} to the output directory"/>
        <to uri="bean:myBean?method=myMethod"/>
        <to uri="file://outputdir/"/>

And then define a bean with the id myBean, outside the <camelContext> tag

<bean id="myBean" class=""/>

And then your bean implementation is like

public class MyBean {

public String myMethod(String content) {
   // here you can do whatever you want with the file content.
   // and if you want to change the message, just return whatever, such as:
   return "Hey I read the content of the file which is: " + content;

You can read more about using beans with Camel

> Cheers
> Guru
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Twitter: davsclaus, fusenews
Author of Camel in Action:

View raw message