Repository: camel
Updated Branches:
  refs/heads/master 80a83842c -> d901b59e8


CAMEL-11649 - Cookie Handling only works for one cookie

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d901b59e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d901b59e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d901b59e

Branch: refs/heads/master
Commit: d901b59e8d5a77aad1b87e8effd12ff708ead135
Parents: 80a8384
Author: Stephan Siano <stephan.si...@sap.com>
Authored: Tue Aug 8 12:42:59 2017 +0200
Committer: Stephan Siano <stephan.si...@sap.com>
Committed: Tue Aug 8 12:45:53 2017 +0200

----------------------------------------------------------------------
 .../camel/component/ahc/DefaultAhcBinding.java  | 24 +++++++++++---------
 .../component/ahc/AhcProducerSessionTest.java   |  2 ++
 2 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d901b59e/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
index dae132b..2e5c3d9 100644
--- 
a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
+++ 
b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
@@ -25,12 +25,12 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.TreeMap;
 
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
@@ -128,11 +128,11 @@ public class DefaultAhcBinding implements AhcBinding {
                 Map<String, List<String>> cookieHeaders = 
endpoint.getCookieHandler().loadCookies(exchange, uri);
                 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);
-                        builder.addHeader(key, s);
+                    for (String value : entry.getValue()) {
+                        if (log.isTraceEnabled()) {
+                            log.trace("Adding header {} = {}", key, value);
+                        }
+                        builder.addHeader(key, value);                        
                     }
                 }
             } catch (IOException e) {
@@ -233,13 +233,15 @@ public class DefaultAhcBinding implements AhcBinding {
 
     @Override
     public void onHeadersReceived(AhcEndpoint endpoint, Exchange exchange, 
HttpResponseHeaders headers) throws Exception {
-        List<Entry<String, String>> l = headers.getHeaders().entries();
-        Map<String, List<String>> m = new HashMap<String, List<String>>();
+        Map<String, List<String>> m = new TreeMap<String, 
List<String>>(String.CASE_INSENSITIVE_ORDER);
         for (Entry<String, String> entry : headers.getHeaders().entries()) {
             String key = entry.getKey();
             String value = entry.getValue();
-            m.put(key, Collections.singletonList(value));
-            exchange.getOut().getHeaders().put(key, value);
+            if (!m.containsKey(key)) {
+                m.put(key, new LinkedList<String>());
+                exchange.getOut().getHeaders().put(key, value);
+            }
+            m.get(key).add(value);
         }
         // handle cookies
         if (endpoint.getCookieHandler() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/d901b59e/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducerSessionTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducerSessionTest.java
 
b/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducerSessionTest.java
index ca9bebe..95b519a 100644
--- 
a/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducerSessionTest.java
+++ 
b/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducerSessionTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.ahc;
 
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpSession;
 
 import org.apache.camel.Exchange;
@@ -103,6 +104,7 @@ public class AhcProducerSessionTest extends BaseAhcTest {
                                 session.setAttribute("foo", "bar");
                                 message.setBody("New " + body);
                             }
+                            message.getResponse().addCookie(new 
Cookie("othercookie","value"));
                         }
                     });
             }

Reply via email to