You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by alapaka <al...@rocketmail.com> on 2013/10/01 01:24:13 UTC

Re: Jetty consumer - how to send reply?

Seems like the only way (without using a processor/filter/endpoint ) is to
use enrich. 
I tried to use a file directly in setBody: 

from("jetty:http://localhost:8123/services?matchOnUriPrefix=true")
.log("Received Request\n----------------\n ${body}
\n---------------------\n")
.setBody(body().append(new File("C:\\devTestResponse.xml")))
.log("Sending Response\n----------------\n ${body}
\n---------------------\n")
.end();

this does not work. I infer from the documentation that setBody() is meant
to work with expressions i.e. scripts/xpath etc.. that work on the current
content of the Message.

This exercise is more academic than a real requirement - just seeing what I
can and cannot do within these routes. I can certainly live with pollEnrich
as is.
Thanks for all the help guys!

aloha
ala



--
View this message in context: http://camel.465427.n5.nabble.com/Jetty-consumer-how-to-send-reply-tp5740450p5740616.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Jetty consumer - how to send reply?

Posted by alapaka <al...@rocketmail.com>.
thanks again guys!

sorry for the newbie questions - still getting my head around the
architecture and the major moving parts.

aloha
ala



--
View this message in context: http://camel.465427.n5.nabble.com/Jetty-consumer-how-to-send-reply-tp5740450p5740633.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Jetty consumer - how to send reply?

Posted by Dale King <da...@jadabeauty.com>.
On Oct 1, 2013, at 2:14 AM, Claus Ibsen <cl...@gmail.com> wrote:

> You can do
> 
> setBody(constant(new File("xxxx")))

That works if the file name is fixed at the time of route construction.

The method I showed using simple and the built in conversion from string to File will allow you to determine the file name dynamically when the route is running, which is what I needed in my case.


Re: Jetty consumer - how to send reply?

Posted by Claus Ibsen <cl...@gmail.com>.
You can do

setBody(constant(new File("xxxx")))


On Tue, Oct 1, 2013 at 1:24 AM, alapaka <al...@rocketmail.com> wrote:
> Seems like the only way (without using a processor/filter/endpoint ) is to
> use enrich.
> I tried to use a file directly in setBody:
>
> from("jetty:http://localhost:8123/services?matchOnUriPrefix=true")
> .log("Received Request\n----------------\n ${body}
> \n---------------------\n")
> .setBody(body().append(new File("C:\\devTestResponse.xml")))
> .log("Sending Response\n----------------\n ${body}
> \n---------------------\n")
> .end();
>
> this does not work. I infer from the documentation that setBody() is meant
> to work with expressions i.e. scripts/xpath etc.. that work on the current
> content of the Message.
>
> This exercise is more academic than a real requirement - just seeing what I
> can and cannot do within these routes. I can certainly live with pollEnrich
> as is.
> Thanks for all the help guys!
>
> aloha
> ala
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Jetty-consumer-how-to-send-reply-tp5740450p5740616.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Re: Jetty consumer - how to send reply?

Posted by Dale King <da...@jadabeauty.com>.
Appending a file like that probably won't work. Here is what I am doing in a route where I need to read a file:

   .setBody().simple("path/To/File", File.class)

which also lets you use ${...} expressions to form the file path

If absolutely necessary you could then do a convertBodyTo but Camel should handle conversion to an InputStream automatically.

Note that reading the body in a log message like that will mess up the process for later steps because you will exhaust the InputStream and then there will be nothing to read later so in real code if you want to log it you might have to convert it to a string or byte array first. 

On Sep 30, 2013, at 7:24 PM, alapaka <al...@rocketmail.com> wrote:

> Seems like the only way (without using a processor/filter/endpoint ) is to
> use enrich. 
> I tried to use a file directly in setBody: 
> 
> from("jetty:http://localhost:8123/services?matchOnUriPrefix=true")
> .log("Received Request\n----------------\n ${body}
> \n---------------------\n")
> .setBody(body().append(new File("C:\\devTestResponse.xml")))
> .log("Sending Response\n----------------\n ${body}
> \n---------------------\n")
> .end();
> 
> this does not work. I infer from the documentation that setBody() is meant
> to work with expressions i.e. scripts/xpath etc.. that work on the current
> content of the Message.
> 
> This exercise is more academic than a real requirement - just seeing what I
> can and cannot do within these routes. I can certainly live with pollEnrich
> as is.
> Thanks for all the help guys!
> 
> aloha
> ala
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Jetty-consumer-how-to-send-reply-tp5740450p5740616.html
> Sent from the Camel - Users mailing list archive at Nabble.com.