camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9281: Http/http4 producer should keep trailing slash if provided in url. Thanks to Edward Welch for the patch.
Date Sat, 09 Jan 2016 14:37:57 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x f467ebf20 -> 705fba25f
  refs/heads/master 28c6e279b -> e9cac21a5


CAMEL-9281: Http/http4 producer should keep trailing slash if provided in url. Thanks to Edward
Welch for the patch.


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

Branch: refs/heads/master
Commit: e9cac21a5ed70236eccb77f2d68f81c2328e6eb7
Parents: 28c6e27
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jan 9 15:34:07 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jan 9 15:34:07 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/http/common/HttpHelper.java    |  4 ++--
 .../component/http/helper/HttpHelperTest.java   | 22 ++++++++++++++++++++
 .../component/http4/helper/HttpHelperTest.java  | 22 ++++++++++++++++++++
 3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e9cac21a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
index e18198a..4a3c952 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
@@ -273,7 +273,7 @@ public final class HttpHelper {
         String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
         // NOW the HTTP_PATH is just related path, we don't need to trim it
         if (path != null) {
-            if (path.startsWith("/")) {
+            if (path.length() > 1 && path.startsWith("/")) {
                 path = path.substring(1);
             }
             if (path.length() > 0) {
@@ -283,7 +283,7 @@ public final class HttpHelper {
                 // if there are no query params
                 if (idx == -1) {
                     // make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
-                    uri = uri.endsWith("/") ? uri : uri + "/";
+                    uri = uri.endsWith("/") || path.startsWith("/") ? uri : uri + "/";
                     uri = uri.concat(path);
                 } else {
                     // there are query params, so inject the relative path in the right place

http://git-wip-us.apache.org/repos/asf/camel/blob/e9cac21a/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpHelperTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpHelperTest.java
index d8c5a75..37c39b2 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpHelperTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpHelperTest.java
@@ -139,6 +139,28 @@ public class HttpHelperTest {
         assertEquals("http://apache.org/?q=%E2%82%AC", uri.toString());
     }
 
+    @Test
+    public void createURLShouldNotRemoveTrailingSlash() throws Exception {
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "/"),
+                createHttpEndpoint(true, "http://www.google.com"));
+        assertEquals("http://www.google.com/", url);
+    }
+    @Test
+    public void createURLShouldAddPathAndQueryParamsAndSlash() throws Exception {
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "search"),
+                createHttpEndpoint(true, "http://www.google.com/context?test=true"));
+        assertEquals("http://www.google.com/context/search?test=true", url);
+    }
+    @Test
+    public void createURLShouldAddPathAndQueryParamsAndRemoveDuplicateSlash() throws Exception
{
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "/search"),
+                createHttpEndpoint(true, "http://www.google.com/context/?test=true"));
+        assertEquals("http://www.google.com/context/search?test=true", url);
+    }
+
     private Exchange createExchangeWithOptionalHttpQueryAndHttpMethodHeader(String httpQuery,
HttpMethods httpMethod) {
         CamelContext context = new DefaultCamelContext();
         Exchange exchange = new DefaultExchange(context);

http://git-wip-us.apache.org/repos/asf/camel/blob/e9cac21a/components/camel-http4/src/test/java/org/apache/camel/component/http4/helper/HttpHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/helper/HttpHelperTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/helper/HttpHelperTest.java
index d74e43f..c067c5b 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/helper/HttpHelperTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/helper/HttpHelperTest.java
@@ -162,6 +162,28 @@ public class HttpHelperTest {
         assertEquals(HttpMethods.POST, method);
     }
 
+    @Test
+    public void createURLShouldNotRemoveTrailingSlash() throws Exception {
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "/"),
+                createHttpEndpoint(true, "http://www.google.com"));
+        assertEquals("http://www.google.com/", url);
+    }
+    @Test
+    public void createURLShouldAddPathAndQueryParamsAndSlash() throws Exception {
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "search"),
+                createHttpEndpoint(true, "http://www.google.com/context?test=true"));
+        assertEquals("http://www.google.com/context/search?test=true", url);
+    }
+    @Test
+    public void createURLShouldAddPathAndQueryParamsAndRemoveDuplicateSlash() throws Exception
{
+        String url = HttpHelper.createURL(
+                createExchangeWithOptionalCamelHttpUriHeader(null, "/search"),
+                createHttpEndpoint(true, "http://www.google.com/context/?test=true"));
+        assertEquals("http://www.google.com/context/search?test=true", url);
+    }
+
     private Exchange createExchangeWithOptionalHttpQueryAndHttpMethodHeader(String httpQuery,
HttpMethods httpMethod) {
         CamelContext context = new DefaultCamelContext();
         Exchange exchange = new DefaultExchange(context);


Mime
View raw message