You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gnanaguru S <gn...@wipro.com> on 2011/07/01 09:40:02 UTC

File Reading & Writing using Camel

Hi

I am new to camel.

I want to read a xml file and send it to a activemq Queue. share me link
were i can find the components of camel or tell a idea to do it. 

thanks in advance.

I am using Fuse 4.4 FYI

Cheers
Guru

--
View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541266.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File Reading & Writing using Camel

Posted by Mick Knutson <mk...@baselogic.com>.
Reading the file is just ascii. No matter xml or text. Same with writing.

---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (855) BASE-LOGIC: (227-3564-42)
p. (478) BASE-LOGIC (227-3564-42)
f. (855) BASE-LOGIC: (227-3564-42)

Website: http://www.baselogic.com
Blog: http://www.baselogic.com/blog/
Linked IN: http://linkedin.com/in/mickknutson
Twitter: http://twitter.com/mickknutson
---



On Fri, Jul 1, 2011 at 5:10 AM, Gnanaguru S <gnanaguru.sattanathan@wipro.com
> wrote:

> Also what is the thing if i want to read contents form a text. contents
> will
> be some blind text. How to read it and right it in another text file.
>
> help me out.
>

Re: File Reading & Writing using Camel

Posted by Gnanaguru S <gn...@wipro.com>.
Hi Claus,

Thanks . i got a good idea with it. Actually i want to read contents from a
xml file. assume it be input.xml. it may contain some data from form. i want
to read it and will move to another xml/some xml transformation. I want this
sort of reading file content. Hope you got me now. 

Also what is the thing if i want to read contents form a text. contents will
be some blind text. How to read it and right it in another text file. 

help me out.

Cheers
Guru

--
View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541482.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File Reading & Writing using Camel

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 1, 2011 at 10:50 AM, Gnanaguru S
<gn...@wipro.com> wrote:
>
> Hi Claus,
>
> Thanks. I will look into it. Let have this code
>
> <camelContext xmlns="http://camel.apache.org/schema/blueprint">
>      <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="com.foo.MyBean"/>

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
http://camel.apache.org/bean-integration.html




>
> Cheers
> Guru
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541417.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: File Reading & Writing using Camel

Posted by Gnanaguru S <gn...@wipro.com>.
Hi Claus,

Thanks. I will look into it. Let have this code

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <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. 


Cheers
Guru

--
View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541417.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File Reading & Writing using Camel

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 1, 2011 at 10:30 AM, Gnanaguru S
<gn...@wipro.com> wrote:
>
> Hi Thanks.
>
> Presently i want to create a file, I want to read the file contents and
> write to a some other file in someother directory. Thats it. FYI I am new to
> ESB and Camel . Presently i have created a small example using
> camel-blueprint feature. Such that i dont know to use maven things
> currently. kindly help me out to read and write in a file using
> camel-blueprint.
>

When using SMX with Camel and blueprint, you are defining Camel routes in XML.

So all you have to do is something like

<route>
<from uri="file:inbox"/>
<to uri="file:outbox"/>
</route>


If you are new to Camel I suggest reading this article
http://java.dzone.com/articles/open-source-integration-apache




>
> Thanks in advance.
>
> Cheers
> Guru
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541364.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: File Reading & Writing using Camel

Posted by Gnanaguru S <gn...@wipro.com>.
Hi Thanks. 

Presently i want to create a file, I want to read the file contents and
write to a some other file in someother directory. Thats it. FYI I am new to
ESB and Camel . Presently i have created a small example using
camel-blueprint feature. Such that i dont know to use maven things
currently. kindly help me out to read and write in a file using
camel-blueprint.


Thanks in advance.

Cheers
Guru

--
View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541364.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File Reading & Writing using Camel

Posted by Marco Westermann <Ma...@gmx.de>.
Hi,

if you build your project using

//mvn archetype:create 
-DarchetypeArtifactId=servicemix-camel-osgi-bundle 
-//DarchetypeGroupId=org.apache.servicemix.tooling 
//-DartifactId=your.artifact -//DgroupId=yourGroup//

you get an example how to read a file and process it.

to change it to write to activemq just look here

http://camel.apache.org/activemq.html


regards, Marco

Am 01.07.2011 09:40, schrieb Gnanaguru S:
> Hi
>
> I am new to camel.
>
> I want to read a xml file and send it to a activemq Queue. share me link
> were i can find the components of camel or tell a idea to do it.
>
> thanks in advance.
>
> I am using Fuse 4.4 FYI
>
> Cheers
> Guru
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-Reading-Writing-using-Camel-tp4541266p4541266.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>