You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dunnlow <du...@yahoo.com> on 2012/01/31 18:12:41 UTC

Accessing a Map header via Simple?

Hi.  I have a Map<String,Object> in my header and I am trying to access it
via Simple in my spring dsl.

I see an example using body in the documentation and am extrapolating that
for my header purposes.  However, I'm getting a NullPointerException, so I
am thinking I've got bad syntax.

My map holds key/value pairs like ->
{("user1","http://127.0.0.1/serv/s1"),("user2","http://127.0.0.1/serv/s2)}
and has been added to the headers and is named uriMap.

I want to do a lookup on "user1" for example.

I'm trying: 

   <simple>user1=${in.header.uriMap[user1]}</simple>

Question:
 -  Is it ok without quotes around user1?
 -  If there is no user1 in the map, can I use the .? to avoid a NPE like:
in.header?.uriMap[user1]?

Thanks!
-J

--
View this message in context: http://camel.465427.n5.nabble.com/Accessing-a-Map-header-via-Simple-tp5445156p5445156.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Accessing a Map header via Simple?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 31, 2012 at 6:12 PM, dunnlow <du...@yahoo.com> wrote:
> Hi.  I have a Map<String,Object> in my header and I am trying to access it
> via Simple in my spring dsl.
>
> I see an example using body in the documentation and am extrapolating that
> for my header purposes.  However, I'm getting a NullPointerException, so I
> am thinking I've got bad syntax.
>
> My map holds key/value pairs like ->
> {("user1","http://127.0.0.1/serv/s1"),("user2","http://127.0.0.1/serv/s2)}
> and has been added to the headers and is named uriMap.
>
> I want to do a lookup on "user1" for example.
>
> I'm trying:
>
>   <simple>user1=${in.header.uriMap[user1]}</simple>
>
> Question:
>  -  Is it ok without quotes around user1?
>  -  If there is no user1 in the map, can I use the .? to avoid a NPE like:
> in.header?.uriMap[user1]?
>

Ad 1)
Quotes should be preferred,  but I think there was a bug in a previous
Camel release that did not strip the quotes from the key.

Ad 2)
Yes the null safe operator should be supported by the map as well.

What Camel version are you using?

And can you post the stacktrace with the NPE ?


> Thanks!
> -J
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Accessing-a-Map-header-via-Simple-tp5445156p5445156.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/