You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by helander <le...@gmail.com> on 2013/01/27 14:55:19 UTC
Reading a file
I am trying to find a way to do:
>From a Producer Template send a request to a route, and in the route I would
like to read the contents of a file, transform the contents and return back
to the producer template.
Location and name of file is fixed and the file should not be moved/removed
by the route.
If the specified file does not exist, the exchange should return without
waiting for the file to appear.
I tried using enrich/pollEnrich, but it seemed like I ended up having
produced a file with the contents of the inBody.
Any suggestions on how to do this?
Thanks
Lars
--
View this message in context: http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reading a file
Posted by helander <le...@gmail.com>.
Christian,
thank you very much, it helped
/Lars
--
View this message in context: http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376p5726852.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reading a file
Posted by Christian Müller <ch...@gmail.com>.
In this case you can use a producer template and send the received message
(file) to what ever endpoint you want, e.g. a direct endpoint. And for this
endpoint, you can develop a route with the functionality you want:
from("direct:start")
.to("...")
...
.to("..");
Exchange exchange = receiveNoWait("file://...?
fileName=foo.txt&noop=true");
if (exchange != null) {
YourCustomBean bean = exchange.getIn().getBody(YourCustomBean.class);
producerTemplate.sendBody("direct:start", bean);
}
Best,
Christian
On Tue, Jan 29, 2013 at 8:31 AM, Lars-Erik Helander <le...@gmail.com>wrote:
> In general I meant the transformation to be part of these steps, in some
> cases it it only the transformation that takes place between reading the
> file and consumer reception, but there could be other steps to.
>
> Skickat från min iPhone
>
> 28 jan 2013 kl. 23:22 skrev Christian Müller <christian.mueller@gmail.com
> >:
>
> > Don't understand. You have to do something else BEFORE you can read the
> > file? Or AFTER reading the file and BEFORE you transform the content?
> >
> > Sent from a mobile device
> > Am 27.01.2013 20:47 schrieb "helander" <le...@gmail.com>:
> >
> >> Hi Christian,
> >>
> >> sounds simple :)
> >>
> >> However before the consumer can consume the contents of the file, it
> needs
> >> to be processed by some additonal (route)-steps, how would I do that?
> >>
> >> Thanks
> >>
> >> Lars
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376p5726388.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>
>
--
Re: Reading a file
Posted by Lars-Erik Helander <le...@gmail.com>.
In general I meant the transformation to be part of these steps, in some cases it it only the transformation that takes place between reading the file and consumer reception, but there could be other steps to.
Skickat från min iPhone
28 jan 2013 kl. 23:22 skrev Christian Müller <ch...@gmail.com>:
> Don't understand. You have to do something else BEFORE you can read the
> file? Or AFTER reading the file and BEFORE you transform the content?
>
> Sent from a mobile device
> Am 27.01.2013 20:47 schrieb "helander" <le...@gmail.com>:
>
>> Hi Christian,
>>
>> sounds simple :)
>>
>> However before the consumer can consume the contents of the file, it needs
>> to be processed by some additonal (route)-steps, how would I do that?
>>
>> Thanks
>>
>> Lars
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376p5726388.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
Re: Reading a file
Posted by Christian Müller <ch...@gmail.com>.
Don't understand. You have to do something else BEFORE you can read the
file? Or AFTER reading the file and BEFORE you transform the content?
Sent from a mobile device
Am 27.01.2013 20:47 schrieb "helander" <le...@gmail.com>:
> Hi Christian,
>
> sounds simple :)
>
> However before the consumer can consume the contents of the file, it needs
> to be processed by some additonal (route)-steps, how would I do that?
>
> Thanks
>
> Lars
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376p5726388.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Reading a file
Posted by helander <le...@gmail.com>.
Hi Christian,
sounds simple :)
However before the consumer can consume the contents of the file, it needs
to be processed by some additonal (route)-steps, how would I do that?
Thanks
Lars
--
View this message in context: http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376p5726388.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reading a file
Posted by Christian Müller <ch...@gmail.com>.
Why no using a consumer template [1]?
For the transformation, I would use a custom type converter [2].
Than you could do something like:
YourCustomBean bean =
receiveBodyNoWait("file://...?fileName=foo.txt&noop=true",
YourCustomBean.class);
or if you need to access the exchange:
Exchange exchange = receiveNoWait("file://...?fileName=foo.txt&noop=true");
if (exchange != null) {
YourCustomBean bean = exchange.getIn().getBody(YourCustomBean.class);
}
Isn't it simple?
[1] camel.apache.org/polling-consumer.html
[2] http://camel.apache.org/type-converter.html
Best,
Christian
On Sun, Jan 27, 2013 at 2:55 PM, helander <le...@gmail.com> wrote:
> I am trying to find a way to do:
>
> From a Producer Template send a request to a route, and in the route I
> would
> like to read the contents of a file, transform the contents and return back
> to the producer template.
> Location and name of file is fixed and the file should not be moved/removed
> by the route.
> If the specified file does not exist, the exchange should return without
> waiting for the file to appear.
> I tried using enrich/pollEnrich, but it seemed like I ended up having
> produced a file with the contents of the inBody.
>
> Any suggestions on how to do this?
>
> Thanks
>
> Lars
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Reading-a-file-tp5726376.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--