You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by si...@apache.org on 2019/01/23 16:42:40 UTC
[camel] branch camel-2.23.x updated: [CAMEL-13114] Provide single
Cookie header for multiple cookies
This is an automated email from the ASF dual-hosted git repository.
siano pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.23.x by this push:
new 79971ac [CAMEL-13114] Provide single Cookie header for multiple cookies
79971ac is described below
commit 79971ac3c06366defc97c1ee77c581f3e4dcc562
Author: Stephan Siano <st...@sap.com>
AuthorDate: Wed Jan 23 14:26:54 2019 +0100
[CAMEL-13114] Provide single Cookie header for multiple cookies
---
.../apache/camel/component/ahc/DefaultAhcBinding.java | 11 +++++++----
.../camel/component/ahc/AhcProducerSessionTest.java | 17 +++++++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
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 9e2daf0..94ae301 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
@@ -28,6 +28,7 @@ import java.nio.charset.Charset;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.StringJoiner;
import java.util.TreeMap;
import io.netty.handler.codec.http.HttpHeaders;
@@ -125,12 +126,14 @@ 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();
+ StringJoiner joiner = new StringJoiner("; ");
for (String value : entry.getValue()) {
- if (log.isTraceEnabled()) {
- log.trace("Adding header {} = {}", key, value);
- }
- builder.addHeader(key, value);
+ joiner.add(value);
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("Adding header {} = {}", key, joiner.toString());
}
+ builder.addHeader(key, joiner.toString());
}
} catch (IOException e) {
throw new CamelExchangeException("Error loading cookies", exchange, e);
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 3c6e762..8ade2dc 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
@@ -96,10 +96,27 @@ public class AhcProducerSessionTest extends BaseAhcTest {
@Override
public void process(Exchange exchange) throws Exception {
HttpMessage message = exchange.getIn(HttpMessage.class);
+ Object cookiesObj = message.getHeader("Cookie");
HttpSession session = message.getRequest().getSession();
String body = message.getBody(String.class);
if ("bar".equals(session.getAttribute("foo"))) {
message.setBody("Old " + body);
+ /*
+ * If we are in a session we should also have a cookie header with two
+ * cookies. This test checks that the cookies are in one line.
+ * We can also get the cookies with request.getCookies() but this will
+ * always give us two cookies even if there are two cookie headers instead
+ * of one multi-value cookie header.
+ */
+ if (cookiesObj instanceof String && ((String) cookiesObj).contains("othercookie=value")) {
+ if (!((String) cookiesObj).contains("JSESSIONID=")) {
+ log.error("JSESSIONID missing");
+ throw new IllegalStateException("JSESSIONID missing");
+ }
+ } else {
+ log.error("othercookie=value is missing in cookie");
+ throw new IllegalStateException("othercookie=value is missing in cookie");
+ }
} else {
session.setAttribute("foo", "bar");
message.setBody("New " + body);