You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by David MacDonald <da...@cdonald.net.nz> on 2013/06/27 03:20:09 UTC

Choice sendTo and overwriting exchange body

Hi all,

I'm attempting to use a sub-route via the sendTo expression to act as a
filter (this involves a callout to a web-service), however I run into a
problem in that the sendTo callout overwrites the original exchange body.
For example,
...
.choice()
.when(sendTo("direct:someFilterService").isEqualTo("false"))
.log("the body is now false, rather than the original body")
.otherwise()
.log("the body is now true, rather than the original body'")
.end()

I've worked around this by using .setProperty("OriginalBody",body()) and
replacing it after the filtering however this isn't terribly elegant. I also
realize that it's possible to use a Processor and some kind of producer
template but I'd like to avoid adding Java code.

So, is it possible for the sendTo expression to return a new exchange purely
for evaluation?

Thanks,
David





--
View this message in context: http://camel.465427.n5.nabble.com/Choice-sendTo-and-overwriting-exchange-body-tp5734867.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Choice sendTo and overwriting exchange body

Posted by David MacDonald <da...@cdonald.net.nz>.
Hi Willem, 

I made my own ExpressionAdapter which is effectively a copy paste of
ExpressionBuilder.toExpression that accepts an additional boolean for
whether to (shallow) copy the exchange, i.e. Exchange toExchange =
replaceExchange ? exchange : exchange.copy();

I'll raise a JIRA/code sample it soon.

Cheers,
David



--
View this message in context: http://camel.465427.n5.nabble.com/Choice-sendTo-and-overwriting-exchange-body-tp5734867p5735120.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Choice sendTo and overwriting exchange body

Posted by Willem jiang <wi...@gmail.com>.
Maybe we can add an option in sendTo DSL, to let it restore the original Exchange if the option is enabled.
Please feel free to fill a JIRA for it, if you like you can share us with the solution you have.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Wednesday, July 3, 2013 at 8:19 AM, David MacDonald wrote:

> Hi Willem,
>  
> I guessed this much. Oracle Service Bus has a service call feature out which
> could do callouts to internal routes without affecting the incoming message
> which was quite useful. I might see if I can come up with a reusable
> Expression that does something similar.
>  
> Cheers,
> David
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Choice-sendTo-and-overwriting-exchange-body-tp5734867p5735107.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Choice sendTo and overwriting exchange body

Posted by David MacDonald <da...@cdonald.net.nz>.
Hi Willem,

I guessed this much. Oracle Service Bus has a service call feature out which
could do callouts to internal routes without affecting the incoming message
which was quite useful. I might see if I can come up with a reusable
Expression that does something similar.

Cheers,
David



--
View this message in context: http://camel.465427.n5.nabble.com/Choice-sendTo-and-overwriting-exchange-body-tp5734867p5735107.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Choice sendTo and overwriting exchange body

Posted by Willem jiang <wi...@gmail.com>.
Hi,

When you using sendTo expression, the exchange will be processed, so the original exchange will be processed.
If you need to use the original message body again, you need to resort it yourself.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Thursday, June 27, 2013 at 9:20 AM, David MacDonald wrote:

> Hi all,
>  
> I'm attempting to use a sub-route via the sendTo expression to act as a
> filter (this involves a callout to a web-service), however I run into a
> problem in that the sendTo callout overwrites the original exchange body.
> For example,
> ...
> .choice()
> .when(sendTo("direct:someFilterService").isEqualTo("false"))
> .log("the body is now false, rather than the original body")
> .otherwise()
> .log("the body is now true, rather than the original body'")
> .end()
>  
> I've worked around this by using .setProperty("OriginalBody",body()) and
> replacing it after the filtering however this isn't terribly elegant. I also
> realize that it's possible to use a Processor and some kind of producer
> template but I'd like to avoid adding Java code.
>  
> So, is it possible for the sendTo expression to return a new exchange purely
> for evaluation?
>  
> Thanks,
> David
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Choice-sendTo-and-overwriting-exchange-body-tp5734867.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).