Correct, but I need to call the get method on the body Object which is a 
HashMap like in the following example. 

msg.getBody(Map.class).get("user_name"));

But the body() method returns a ValueBuilder Object so the following code won't 
compile

setHeader("uid").body(String.class) .get("user_name"));

What am I missing here?

-----Original Message-----
From: Charles Moulliard [mailto:ch0...@gmail.com] 
Sent: Mittwoch, 21. Mai 2014 11:44
To: users@camel.apache.org
Subject: Re: Java DSL question

The body part of the camel exchange object (exchange.getIn().getBody())
after the split contain the string. So the syntax (to be typesafe) is

.split(body())
setHeader("uid").body(String.class)


On Wed, May 21, 2014 at 11:19 AM, Glattfelder, Beat <
beat.glattfel...@credit-suisse.com> wrote:

> Hi Camel Riders
>
> I am back with a simple question I found to tough to answer myself: How do
> I access the message body in a typesafe manner like in the TODO comment
> below? Obviously implementing a processor works fine, but make things
> harder to read.
>
> Thanks for advising,
> Beat
>
>
>     from("direct:start-profile-pics")
>
>                                     .to("sql:select * from cwd_user where
> active='T' and directory_id=76644354?dataSource=confDB")
>
>                                     .split(body())
>
>                                     // TODO: setHeader("uid",
> bodyAsType(Map.class).get("username"));
>
>                                     .process(new Processor() {
>
>
>                                                    @Override
>
>                                                    public void
> process(Exchange exchange)
>
>
>        throws Exception {
>
>                                                                    Message
> msg = exchange.getIn();
>
>
>  msg.setHeader("uid", msg.getBody(Map.class)
>
>
>                       .get("user_name"));
>
>
>  msg.setHeader(Exchange.HTTP_PATH, "avatar/" + msg.getBody(Map.class)
>
>
>                       .get("user_name"));
>
>
>                                                    }
>
>                                     })
>
>                                     .setBody(constant(null))
>
>                                     .to("http4://
> unity-uat.apps.csintra.net/")
>
>                                     .bean(applicationContext
>
>
>  .getBean("confluenceClient"),
>
>
>  "updateProfilePic");
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Reply via email to