You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/09 15:37:58 UTC
[2/2] camel git commit: CAMEL-9281: Http/http4 producer should keep
trailing slash if provided in url. Thanks to Edward Welch for the patch.
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/705fba25
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/705fba25
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/705fba25
Branch: refs/heads/camel-2.16.x
Commit: 705fba25fa9d351f3462761caf44c283dda96ac6
Parents: f467ebf
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jan 9 15:34:07 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jan 9 15:37:49 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/705fba25/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/705fba25/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/705fba25/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);