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 2015/11/19 08:13:21 UTC

[12/12] camel git commit: CAMEL-9263: camel-servlet - Allow to configure the context path without leading slash. Fixed issue with camel-gae extending servlet and works a bit differently than a plain servlet.

CAMEL-9263: camel-servlet - Allow to configure the context path without leading slash. Fixed issue with camel-gae extending servlet and works a bit differently than a plain servlet.


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

Branch: refs/heads/camel-2.16.x
Commit: 9d7e250523dd4bc789917389a8da54d4591ce3d8
Parents: 46092b1
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Nov 19 08:11:16 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Nov 19 08:12:44 2015 +0100

----------------------------------------------------------------------
 .../component/gae/http/GHttpComponent.java      |  6 +++++
 .../component/servlet/ServletComponent.java     | 27 +++++++++++++-------
 2 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9d7e2505/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java b/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
index c5bb708..2fecd4d 100644
--- a/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
+++ b/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
@@ -63,4 +63,10 @@ public class GHttpComponent extends ServletComponent {
     protected ServletEndpoint createServletEndpoint(String endpointUri, ServletComponent component, URI httpUri) throws Exception {
         return new GHttpEndpoint(endpointUri, component, httpUri);
     }
+
+    @Override
+    protected boolean lenientContextPath() {
+        // must use the path as-is
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9d7e2505/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
index 7da4497..25a1b1b 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
@@ -67,16 +67,18 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
         String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
         HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
 
-        // the uri must have a leading slash for the context-path matching to work with servlet, and it can be something people
-        // forget to add and then the servlet consumer cannot match the context-path as would have been expected
-        String scheme = ObjectHelper.before(uri, ":");
-        String after = ObjectHelper.after(uri, ":");
-        // rebuild uri to have exactly one leading slash
-        while (after.startsWith("/")) {
-            after = after.substring(1);
+        if (lenientContextPath()) {
+            // the uri must have a leading slash for the context-path matching to work with servlet, and it can be something people
+            // forget to add and then the servlet consumer cannot match the context-path as would have been expected
+            String scheme = ObjectHelper.before(uri, ":");
+            String after = ObjectHelper.after(uri, ":");
+            // rebuild uri to have exactly one leading slash
+            while (after.startsWith("/")) {
+                after = after.substring(1);
+            }
+            after = "/" + after;
+            uri = scheme + ":" + after;
         }
-        after = "/" + after;
-        uri = scheme + ":" + after;
 
         // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
         URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encodeHttpURI(uri)), parameters);
@@ -120,6 +122,13 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
     }
 
     /**
+     * Whether defining the context-path is lenient and do not require an exact leading slash.
+     */
+    protected boolean lenientContextPath() {
+        return true;
+    }
+
+    /**
      * Strategy to create the servlet endpoint.
      */
     protected ServletEndpoint createServletEndpoint(String endpointUri, ServletComponent component, URI httpUri) throws Exception {