You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Lewin Chan <le...@adaptris.com> on 2010/01/07 18:14:55 UTC
CaseInsensitiveMap issues?
Hi,
I'm wondering if CaseInsensitiveMap is behaving as designed, or if I have uncovered an issue
I'm trying (best not to ask why :) )
private static void copyHeaders(org.apache.camel.Message in, MyInterimMessageType out) {
Map<String, Object> hdrs = in.getHeaders();
for (String s : hdrs.keySet()) {
out.addHeader(s, in.getHeader(s, String.class));
}
}
If previously in my route I have added headers to the message whose keys are CamelCase, this is not preserved in my MyInterimMessageType headers, they are all lower case.
Looking at the source; surely CaseInsensitiveMap should override the keySet() method from HashMap so that it returns the original keys rather than all the lower case keys.
I can work around this behaviour in code of course, I'm just trying to ascertain if this behaviour is intended.
Regards
Lewin
Re: CaseInsensitiveMap issues?
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
It works fine :)
When you want to copy headers from one map to another you need to do
it correctly using the EntrySet
Map<String, Object> other = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
other.put(key, value);
}
Or use putAll etc.
Map<String, Object> other = new HashMap<String, Object>();
other.putAll(map);
Or pass it in the constructor
Map<String, Object> other = new HashMap<String, Object>(map);
On Thu, Jan 7, 2010 at 6:14 PM, Lewin Chan <le...@adaptris.com> wrote:
> Hi,
>
> I'm wondering if CaseInsensitiveMap is behaving as designed, or if I have uncovered an issue
>
> I'm trying (best not to ask why :) )
>
> private static void copyHeaders(org.apache.camel.Message in, MyInterimMessageType out) {
> Map<String, Object> hdrs = in.getHeaders();
> for (String s : hdrs.keySet()) {
> out.addHeader(s, in.getHeader(s, String.class));
> }
> }
>
> If previously in my route I have added headers to the message whose keys are CamelCase, this is not preserved in my MyInterimMessageType headers, they are all lower case.
>
> Looking at the source; surely CaseInsensitiveMap should override the keySet() method from HashMap so that it returns the original keys rather than all the lower case keys.
>
> I can work around this behaviour in code of course, I'm just trying to ascertain if this behaviour is intended.
>
> Regards
> Lewin
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus