You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Aki Yoshida <el...@gmail.com> on 2013/05/08 00:45:31 UTC

propagating multiple header entries from cxf to camel

We have a header entry that has multiple entries that are in the response
HTTP message. These multiple entries are available in CXF, as each header
value is represented as a list. However, when this message is propagated
back to camel, only the first entry of this list is read into the camel
message's headers.

Looking at the current camel-cxf code in trunk as shown below, I don't see
an available option to propagate multiple entries back into the camel's
message header.

        // Copy the CXF protocol headers to the camel headers
        Map<String, List<String>> cxfHeaders =
            CastUtils.cast((Map<?,
?>)message.get(Message.PROTOCOL_HEADERS));
        if (cxfHeaders != null) {
            for (Map.Entry<String, List<String>> entry :
cxfHeaders.entrySet()) {
                if (!strategy.applyFilterToExternalHeaders(entry.getKey(),
entry.getValue(), exchange)) {
                    headers.put(entry.getKey(), entry.getValue().get(0));
                }
            }
        }

Is this assumption correct and if so, has there been some work on how to
get the multiple entries propagate back to camel? I can think of several
strategy/options to not to break the existing applications and I was
wondering if we can add such an option.

I appreciate for your advice.

regards, aki.

Re: propagating multiple header entries from cxf to camel

Posted by Aki Yoshida <el...@gmail.com>.
Hi,
I created CAMEL-6393 to describe the change proposed.
regards, aki


2013/5/17 Aki Yoshida <el...@gmail.com>

> Hi Claus,
> so the http component assumes always a list of string as its header value?
>
> camel-cxf seems to currently always assume a string entry (there is a
> casting code like (String)camelHeaders.get(...) in DefaultCxfBinding. And
> maybe there are other existing code that assume the string header value in
> camel-cxf scenarios. So, we probably can't switch to the list value
> directly.
>
> I think we would need to provide a configuration option for camel-cxf to
> decide whether to propagate a list directly or converting its entries to a
> string. In that case, if this option is not set, we should create a string
> value using the conversion rule defined in HTTP 1.1 spec, section 4.2,
> converting multiple header fields into a single header field.
>
> We could also provide an additional option for the current behavior,
> namely propagating only the first entry. But this behavior is achieved with
> the string conversion rule when the list has one value, which is the
> typical case. So, I don't think we need to add this option to make it more
> complicated.
>
> How do you think?
>
> regards, aki
>
> 2013/5/10 Claus Ibsen <cl...@gmail.com>
>
>> Hi Aki
>>
>> Yeah it should add those values as a List when if you add a 2nd value
>> to the same key.
>> We do the same in http based components
>>
>> See the appendHeaders method on
>>
>> https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java;h=e98f2bb75087cca8e4a02efcb61888c2804bfaa5;hb=HEAD
>>
>> We could consider having such a method in camel-core in a
>> MessageHelper util class or something.
>>
>> On Wed, May 8, 2013 at 12:45 AM, Aki Yoshida <el...@gmail.com> wrote:
>> > We have a header entry that has multiple entries that are in the
>> response
>> > HTTP message. These multiple entries are available in CXF, as each
>> header
>> > value is represented as a list. However, when this message is propagated
>> > back to camel, only the first entry of this list is read into the camel
>> > message's headers.
>> >
>> > Looking at the current camel-cxf code in trunk as shown below, I don't
>> see
>> > an available option to propagate multiple entries back into the camel's
>> > message header.
>> >
>> >         // Copy the CXF protocol headers to the camel headers
>> >         Map<String, List<String>> cxfHeaders =
>> >             CastUtils.cast((Map<?,
>> > ?>)message.get(Message.PROTOCOL_HEADERS));
>> >         if (cxfHeaders != null) {
>> >             for (Map.Entry<String, List<String>> entry :
>> > cxfHeaders.entrySet()) {
>> >                 if
>> (!strategy.applyFilterToExternalHeaders(entry.getKey(),
>> > entry.getValue(), exchange)) {
>> >                     headers.put(entry.getKey(),
>> entry.getValue().get(0));
>> >                 }
>> >             }
>> >         }
>> >
>> > Is this assumption correct and if so, has there been some work on how to
>> > get the multiple entries propagate back to camel? I can think of several
>> > strategy/options to not to break the existing applications and I was
>> > wondering if we can add such an option.
>> >
>> > I appreciate for your advice.
>> >
>> > regards, aki.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>

Re: propagating multiple header entries from cxf to camel

Posted by Aki Yoshida <el...@gmail.com>.
Hi Claus,
so the http component assumes always a list of string as its header value?

camel-cxf seems to currently always assume a string entry (there is a
casting code like (String)camelHeaders.get(...) in DefaultCxfBinding. And
maybe there are other existing code that assume the string header value in
camel-cxf scenarios. So, we probably can't switch to the list value
directly.

I think we would need to provide a configuration option for camel-cxf to
decide whether to propagate a list directly or converting its entries to a
string. In that case, if this option is not set, we should create a string
value using the conversion rule defined in HTTP 1.1 spec, section 4.2,
converting multiple header fields into a single header field.

We could also provide an additional option for the current behavior, namely
propagating only the first entry. But this behavior is achieved with the
string conversion rule when the list has one value, which is the typical
case. So, I don't think we need to add this option to make it more
complicated.

How do you think?

regards, aki

2013/5/10 Claus Ibsen <cl...@gmail.com>

> Hi Aki
>
> Yeah it should add those values as a List when if you add a 2nd value
> to the same key.
> We do the same in http based components
>
> See the appendHeaders method on
>
> https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java;h=e98f2bb75087cca8e4a02efcb61888c2804bfaa5;hb=HEAD
>
> We could consider having such a method in camel-core in a
> MessageHelper util class or something.
>
> On Wed, May 8, 2013 at 12:45 AM, Aki Yoshida <el...@gmail.com> wrote:
> > We have a header entry that has multiple entries that are in the response
> > HTTP message. These multiple entries are available in CXF, as each header
> > value is represented as a list. However, when this message is propagated
> > back to camel, only the first entry of this list is read into the camel
> > message's headers.
> >
> > Looking at the current camel-cxf code in trunk as shown below, I don't
> see
> > an available option to propagate multiple entries back into the camel's
> > message header.
> >
> >         // Copy the CXF protocol headers to the camel headers
> >         Map<String, List<String>> cxfHeaders =
> >             CastUtils.cast((Map<?,
> > ?>)message.get(Message.PROTOCOL_HEADERS));
> >         if (cxfHeaders != null) {
> >             for (Map.Entry<String, List<String>> entry :
> > cxfHeaders.entrySet()) {
> >                 if
> (!strategy.applyFilterToExternalHeaders(entry.getKey(),
> > entry.getValue(), exchange)) {
> >                     headers.put(entry.getKey(), entry.getValue().get(0));
> >                 }
> >             }
> >         }
> >
> > Is this assumption correct and if so, has there been some work on how to
> > get the multiple entries propagate back to camel? I can think of several
> > strategy/options to not to break the existing applications and I was
> > wondering if we can add such an option.
> >
> > I appreciate for your advice.
> >
> > regards, aki.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: propagating multiple header entries from cxf to camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi Aki

Yeah it should add those values as a List when if you add a 2nd value
to the same key.
We do the same in http based components

See the appendHeaders method on
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java;h=e98f2bb75087cca8e4a02efcb61888c2804bfaa5;hb=HEAD

We could consider having such a method in camel-core in a
MessageHelper util class or something.

On Wed, May 8, 2013 at 12:45 AM, Aki Yoshida <el...@gmail.com> wrote:
> We have a header entry that has multiple entries that are in the response
> HTTP message. These multiple entries are available in CXF, as each header
> value is represented as a list. However, when this message is propagated
> back to camel, only the first entry of this list is read into the camel
> message's headers.
>
> Looking at the current camel-cxf code in trunk as shown below, I don't see
> an available option to propagate multiple entries back into the camel's
> message header.
>
>         // Copy the CXF protocol headers to the camel headers
>         Map<String, List<String>> cxfHeaders =
>             CastUtils.cast((Map<?,
> ?>)message.get(Message.PROTOCOL_HEADERS));
>         if (cxfHeaders != null) {
>             for (Map.Entry<String, List<String>> entry :
> cxfHeaders.entrySet()) {
>                 if (!strategy.applyFilterToExternalHeaders(entry.getKey(),
> entry.getValue(), exchange)) {
>                     headers.put(entry.getKey(), entry.getValue().get(0));
>                 }
>             }
>         }
>
> Is this assumption correct and if so, has there been some work on how to
> get the multiple entries propagate back to camel? I can think of several
> strategy/options to not to break the existing applications and I was
> wondering if we can add such an option.
>
> I appreciate for your advice.
>
> regards, aki.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen