This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.21.x by this push:
     new d81f881  CAMEL-12395: Fixed issue with cookie headers on http 
producer. Thanks to Kevin Brooks for the patch.
d81f881 is described below

commit d81f88126e771d4ecdadd21f6fe5a0e13f87a1f8
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Apr 13 09:20:59 2018 +0200

    CAMEL-12395: Fixed issue with cookie headers on http producer. Thanks to 
Kevin Brooks for the patch.
---
 .../main/java/org/apache/camel/component/http/HttpProducer.java  | 9 ++++-----
 .../main/java/org/apache/camel/component/http4/HttpProducer.java | 9 ++++-----
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
index c8e8855..1a76ccf 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.stream.Collectors;
 
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
@@ -150,10 +151,8 @@ public class HttpProducer extends DefaultProducer {
             for (Map.Entry<String, List<String>> entry : 
cookieHeaders.entrySet()) {
                 String key = entry.getKey();
                 if (entry.getValue().size() > 0) {
-                    // use the default toString of a ArrayList to create in 
the form [xxx, yyy]
-                    // if multi valued, for a single value, then just output 
the value as is
-                    String s = entry.getValue().size() > 1 ? 
entry.getValue().toString() : entry.getValue().get(0);
-                    method.addRequestHeader(key, s);
+                    // join multi-values separated by semi-colon
+                    method.addRequestHeader(key, 
entry.getValue().stream().collect(Collectors.joining(";")));
                 }
             }
         }
@@ -208,7 +207,7 @@ public class HttpProducer extends DefaultProducer {
         for (Header header : headers) {
             String name = header.getName();
             String value = header.getValue();
-            m.put(name, Collections.singletonList(value));
+            m.computeIfAbsent(name, k -> new ArrayList<>()).add(value);
             if (name.toLowerCase().equals("content-type")) {
                 name = Exchange.CONTENT_TYPE;
                 exchange.setProperty(Exchange.CHARSET_NAME, 
IOHelper.getCharsetNameFromContentType(value));
diff --git 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index be67e73..6638e1b 100644
--- 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -33,6 +33,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.stream.Collectors;
 
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
@@ -162,10 +163,8 @@ public class HttpProducer extends DefaultProducer {
             for (Map.Entry<String, List<String>> entry : 
cookieHeaders.entrySet()) {
                 String key = entry.getKey();
                 if (entry.getValue().size() > 0) {
-                    // use the default toString of a ArrayList to create in 
the form [xxx, yyy]
-                    // if multi valued, for a single value, then just output 
the value as is
-                    String s = entry.getValue().size() > 1 ? 
entry.getValue().toString() : entry.getValue().get(0);
-                    httpRequest.addHeader(key, s);
+                    // join multi-values separated by semi-colon
+                    httpRequest.addHeader(key, 
entry.getValue().stream().collect(Collectors.joining(";")));
                 }
             }
         }
@@ -255,7 +254,7 @@ public class HttpProducer extends DefaultProducer {
         for (Header header : headers) {
             String name = header.getName();
             String value = header.getValue();
-            m.put(name, Collections.singletonList(value));
+            m.computeIfAbsent(name, k -> new ArrayList<>()).add(value);
             if (name.toLowerCase().equals("content-type")) {
                 name = Exchange.CONTENT_TYPE;
                 exchange.setProperty(Exchange.CHARSET_NAME, 
IOHelper.getCharsetNameFromContentType(value));

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to