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/09/28 07:42:38 UTC

[4/4] camel git commit: rest-dsl - Components should use context-path configuration so you can configure this in the rest-dsl.

rest-dsl - Components should use context-path configuration so you can configure this in the rest-dsl.


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

Branch: refs/heads/master
Commit: bc9260414d77e873841d1cce7ae47742707af236
Parents: 6ffcacc
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Sep 28 07:44:15 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Sep 28 07:44:15 2015 +0200

----------------------------------------------------------------------
 .../model/rest/RestConfigurationDefinition.java | 10 ++++--
 .../org/apache/camel/spi/RestConfiguration.java |  3 +-
 .../component/jetty/JettyHttpComponent.java     | 10 ++++++
 .../netty/http/NettyHttpComponent.java          |  5 ++-
 .../netty4/http/NettyHttpComponent.java         |  5 ++-
 .../component/restlet/RestletComponent.java     | 10 ++++++
 .../component/servlet/ServletComponent.java     |  2 ++
 .../component/sparkrest/SparkComponent.java     | 32 +++++++++++++-------
 8 files changed, 60 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
index 2854eb2..7429fb1 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -174,7 +174,10 @@ public class RestConfigurationDefinition {
 
     /**
      * Sets a leading context-path the REST services will be using.
-     * This can be used when using components such as SERVLET where the deployed web application is deployed using a context-path.
+     * <p/>
+     * This can be used when using components such as <tt>camel-servlet</tt> where the deployed web application
+     * is deployed using a context-path. Or for components such as <tt>camel-jetty</tt> or <tt>camel-netty4-http</tt>
+     * that includes a HTTP server.
      */
     public void setContextPath(String contextPath) {
         this.contextPath = contextPath;
@@ -429,10 +432,11 @@ public class RestConfigurationDefinition {
     }
 
     /**
-     * Sets a leading API context-path the REST API services will be using.
+     * Sets a leading context-path the REST services will be using.
      * <p/>
      * This can be used when using components such as <tt>camel-servlet</tt> where the deployed web application
-     * is deployed using a context-path.
+     * is deployed using a context-path. Or for components such as <tt>camel-jetty</tt> or <tt>camel-netty4-http</tt>
+     * that includes a HTTP server.
      */
     public RestConfigurationDefinition apiContextPath(String contextPath) {
         setApiContextPath(contextPath);

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
index 4c78a39..8c057ea 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
@@ -162,7 +162,8 @@ public class RestConfiguration {
      * Sets a leading context-path the REST services will be using.
      * <p/>
      * This can be used when using components such as <tt>camel-servlet</tt> where the deployed web application
-     * is deployed using a context-path.
+     * is deployed using a context-path. Or for components such as <tt>camel-jetty</tt> or <tt>camel-netty4-http</tt>
+     * that includes a HTTP server.
      *
      * @param contextPath the context path
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 03b5d17..bcaea1b 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -1036,6 +1036,16 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
             port = num;
         }
 
+        // prefix path with context-path if configured in rest-dsl configuration
+        String contextPath = config.getContextPath();
+        if (ObjectHelper.isNotEmpty(contextPath)) {
+            contextPath = FileUtil.stripTrailingSeparator(contextPath);
+            contextPath = FileUtil.stripLeadingSeparator(contextPath);
+            if (ObjectHelper.isNotEmpty(contextPath)) {
+                path = contextPath + "/" + path;
+            }
+        }
+
         // if no explicit hostname set then resolve the hostname
         if (ObjectHelper.isEmpty(host)) {
             if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index 370c6c8..a9d8c27 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -271,11 +271,14 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
             port = num;
         }
 
+        // prefix path with context-path if configured in rest-dsl configuration
         String contextPath = config.getContextPath();
         if (ObjectHelper.isNotEmpty(contextPath)) {
             contextPath = FileUtil.stripTrailingSeparator(contextPath);
             contextPath = FileUtil.stripLeadingSeparator(contextPath);
-            path = contextPath + "/" + path;
+            if (ObjectHelper.isNotEmpty(contextPath)) {
+                path = contextPath + "/" + path;
+            }
         }
         
         // if no explicit hostname set then resolve the hostname

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
index 1f8e397..989d2ee 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
@@ -270,11 +270,14 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
             port = num;
         }
 
+        // prefix path with context-path if configured in rest-dsl configuration
         String contextPath = config.getContextPath();
         if (ObjectHelper.isNotEmpty(contextPath)) {
             contextPath = FileUtil.stripTrailingSeparator(contextPath);
             contextPath = FileUtil.stripLeadingSeparator(contextPath);
-            path = contextPath + "/" + path;
+            if (ObjectHelper.isNotEmpty(contextPath)) {
+                path = contextPath + "/" + path;
+            }
         }
         
         // if no explicit hostname set then resolve the hostname

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index 9b91d90..4b809ea 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -698,6 +698,16 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
             port = num;
         }
 
+        // prefix path with context-path if configured in rest-dsl configuration
+        String contextPath = config.getContextPath();
+        if (ObjectHelper.isNotEmpty(contextPath)) {
+            contextPath = FileUtil.stripTrailingSeparator(contextPath);
+            contextPath = FileUtil.stripLeadingSeparator(contextPath);
+            if (ObjectHelper.isNotEmpty(contextPath)) {
+                path = contextPath + "/" + path;
+            }
+        }
+
         // if no explicit hostname set then resolve the hostname
         if (ObjectHelper.isEmpty(host)) {
             if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/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 9aa1300..5aca6a6 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
@@ -197,6 +197,8 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
             map.putAll(config.getEndpointProperties());
         }
 
+        // do not append with context-path as the servlet path should be without context-path
+
         String query = URISupport.createQueryString(map);
 
         String url;

http://git-wip-us.apache.org/repos/asf/camel/blob/bc926041/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index 826db58..8850346 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -159,29 +159,39 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
         }
         path = FileUtil.stripLeadingSeparator(path);
 
-        if (ObjectHelper.isNotEmpty(path)) {
-            // spark-rest uses :name syntax instead of {name} so we need to replace those
-            Matcher matcher = pattern.matcher(path);
-            path = matcher.replaceAll(":$1");
+        RestConfiguration config = configuration;
+        if (config == null) {
+            config = getCamelContext().getRestConfiguration("spark-rest", true);
         }
 
-        String uri = String.format("spark-rest:%s:%s", verb, path);
-
         Map<String, Object> map = new HashMap<String, Object>();
         if (consumes != null) {
             map.put("accept", consumes);
         }
 
-        // build query string, and append any endpoint configuration properties
-        RestConfiguration config = configuration;
-        if (config == null) {
-            config = getCamelContext().getRestConfiguration("spark-rest", true);
-        }
         // setup endpoint options
         if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
             map.putAll(config.getEndpointProperties());
         }
 
+        if (ObjectHelper.isNotEmpty(path)) {
+            // spark-rest uses :name syntax instead of {name} so we need to replace those
+            Matcher matcher = pattern.matcher(path);
+            path = matcher.replaceAll(":$1");
+        }
+
+        // prefix path with context-path if configured in rest-dsl configuration
+        String contextPath = config.getContextPath();
+        if (ObjectHelper.isNotEmpty(contextPath)) {
+            contextPath = FileUtil.stripTrailingSeparator(contextPath);
+            contextPath = FileUtil.stripLeadingSeparator(contextPath);
+            if (ObjectHelper.isNotEmpty(contextPath)) {
+                path = contextPath + "/" + path;
+            }
+        }
+
+        String uri = String.format("spark-rest:%s:%s", verb, path);
+
         String query = URISupport.createQueryString(map);
 
         String url = uri;