Hi again
I need to clarify that I want to access members of the Object in the body,
which is a HashMap, from within the DSL. From a Processor I can access the
Object as such:
// works
exchange.getIn().getBody(Map.class).get("user_name"));
In the fluent builder, like in the following example, this does not work since
the body() method returns a ValueBuilder Object so the following code won't
compile.
// won't compile
.split(body())
setHeader("uid").body(Map.class).get("user_name"));
What am I missing here?
>>>>>>>>
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 <
[email protected]<mailto:[email protected]>>
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