You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by PJ Walstroem <wa...@hotmail.com> on 2013/08/15 16:01:30 UTC

wireTap: how to put a map in newExchangeBody?

hello,
I have a map with two entries which I would like to use as the new body in a
wireTap

.wireTap("log:foo").newExchangeBody(myMap).end()

I managed doing this by writing a custom Expression, but there must be an
easier way of doing this?

.newExchangeBody(new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
 Map<String, String> newBody = new HashMap<>(); 
  newBody.put("supplier",
(String)exchange.getIn().getHeader("supplierName"));
  newBody.put("status", "started");
 return exchange.getContext().getTypeConverter().convertTo(type, exchange,
newBody);
}})

any suggestions would be highly appreciated!

cheers,
pj



--
View this message in context: http://camel.465427.n5.nabble.com/wireTap-how-to-put-a-map-in-newExchangeBody-tp5737340.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: wireTap: how to put a map in newExchangeBody?

Posted by PJ Walstroem <wa...@hotmail.com>.
great, thank you :-)



--
View this message in context: http://camel.465427.n5.nabble.com/wireTap-how-to-put-a-map-in-newExchangeBody-tp5737340p5737343.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: wireTap: how to put a map in newExchangeBody?

Posted by Claus Ibsen <cl...@gmail.com>.
.wireTap("log:foo").newExchangeBody(constant(myMap)).end()

On Thu, Aug 15, 2013 at 4:01 PM, PJ Walstroem <wa...@hotmail.com> wrote:
> hello,
> I have a map with two entries which I would like to use as the new body in a
> wireTap
>
> .wireTap("log:foo").newExchangeBody(myMap).end()
>
> I managed doing this by writing a custom Expression, but there must be an
> easier way of doing this?
>
> .newExchangeBody(new Expression() {
> @Override
> public <T> T evaluate(Exchange exchange, Class<T> type) {
>  Map<String, String> newBody = new HashMap<>();
>   newBody.put("supplier",
> (String)exchange.getIn().getHeader("supplierName"));
>   newBody.put("status", "started");
>  return exchange.getContext().getTypeConverter().convertTo(type, exchange,
> newBody);
> }})
>
> any suggestions would be highly appreciated!
>
> cheers,
> pj
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/wireTap-how-to-put-a-map-in-newExchangeBody-tp5737340.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