wireTap: how to put a map in newExchangeBody?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

wireTap: how to put a map in newExchangeBody?

PJ Walstroem
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
Reply | Threaded
Open this post in threaded view
|

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

Claus Ibsen-2
.wireTap("log:foo").newExchangeBody(constant(myMap)).end()

On Thu, Aug 15, 2013 at 4:01 PM, PJ Walstroem <[hidden email]> 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: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

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

PJ Walstroem
great, thank you :-)