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 2014/08/07 08:58:58 UTC

[1/4] git commit: CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.

Repository: camel
Updated Branches:
  refs/heads/master 1c64ca33c -> ff842d3b0


CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.


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

Branch: refs/heads/master
Commit: e239c0f2d7a29024a31ea3d7e10e05856864e5fe
Parents: 1c64ca3
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 6 13:35:47 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 6 13:35:47 2014 +0200

----------------------------------------------------------------------
 .../management/mbean/CamelOpenMBeanTypes.java   |  7 ++---
 .../camel/component/rest/RestComponent.java     | 18 ++++++++++++-
 .../camel/component/rest/RestEndpoint.java      | 26 +++++++++++++++---
 .../apache/camel/impl/DefaultRestRegistry.java  | 28 ++++++++++++++------
 .../management/mbean/ManagedRestRegistry.java   | 10 ++++---
 .../apache/camel/model/rest/RestDefinition.java |  5 +---
 .../apache/camel/spi/RestConsumerFactory.java   |  5 ++--
 .../java/org/apache/camel/spi/RestRegistry.java | 22 ++++++++++++---
 .../rest/DummyRestConsumerFactory.java          |  9 +++++--
 .../component/jetty/JettyHttpComponent.java     | 25 ++++++++++++++---
 .../netty/http/NettyHttpComponent.java          | 26 +++++++++++++++---
 .../component/restlet/RestletComponent.java     | 26 +++++++++++++++---
 .../component/servlet/ServletComponent.java     | 15 ++++++++---
 .../component/sparkrest/SparkComponent.java     | 20 +++++++++++---
 .../rest/DummyRestConsumerFactory.java          |  9 +++++--
 15 files changed, 202 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index ec56266..3102713 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -47,9 +47,10 @@ public final class CamelOpenMBeanTypes {
     }
 
     public static CompositeType listRestServicesCompositeType() throws OpenDataException {
-        return new CompositeType("rests", "Rest Services", new String[]{"url", "method", "uriTemplate", "consumes", "produces", "inType", "outType", "state"},
-                new String[]{"Url", "Method", "Uri Template", "Consumes", "Produces", "Input Type", "Output Type", "State"},
-                new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
+        return new CompositeType("rests", "Rest Services", new String[]{"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state"},
+                new String[]{"Url", "Base Url", "Base Path", "Uri Template", "Method", "Consumes", "Produces", "Input Type", "Output Type", "State"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
+                               SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
index d595de6..687fb72 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -20,6 +20,7 @@ import java.util.Map;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 
 public class RestComponent extends UriEndpointComponent {
@@ -39,10 +40,25 @@ public class RestComponent extends UriEndpointComponent {
         }
 
         String verb = ObjectHelper.before(remaining, ":");
-        String path = ObjectHelper.after(remaining, ":");
+        String s = ObjectHelper.after(remaining, ":");
+
+        String path;
+        String uriTemplate;
+        if (s != null && s.contains(":")) {
+            path = ObjectHelper.before(s, ":");
+            uriTemplate = ObjectHelper.after(s, ":");
+        } else {
+            path = s;
+            uriTemplate = null;
+        }
+
+        // remove trailing slashes
+        path = FileUtil.stripTrailingSeparator(path);
+        uriTemplate = FileUtil.stripTrailingSeparator(uriTemplate);
 
         answer.setVerb(verb);
         answer.setPath(path);
+        answer.setUriTemplate(uriTemplate);
 
         // if no explicit component name was given, then fallback and use default configured component name
         if (answer.getComponentName() == null && getCamelContext().getRestConfiguration() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index 12bf7b7..66001c5 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -40,6 +40,8 @@ public class RestEndpoint extends DefaultEndpoint {
     @UriParam
     private String path;
     @UriParam
+    private String uriTemplate;
+    @UriParam
     private String consumes;
     @UriParam
     private String produces;
@@ -73,6 +75,14 @@ public class RestEndpoint extends DefaultEndpoint {
         this.path = path;
     }
 
+    public String getUriTemplate() {
+        return uriTemplate;
+    }
+
+    public void setUriTemplate(String uriTemplate) {
+        this.uriTemplate = uriTemplate;
+    }
+
     public String getConsumes() {
         return consumes;
     }
@@ -154,7 +164,7 @@ public class RestEndpoint extends DefaultEndpoint {
         }
 
         if (factory != null) {
-            Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getConsumes(), getProduces(), getParameters());
+            Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getUriTemplate(), getConsumes(), getProduces(), getParameters());
             configureConsumer(consumer);
 
             // if no explicit port/host configured, then use port from rest configuration
@@ -188,7 +198,17 @@ public class RestEndpoint extends DefaultEndpoint {
             if (!path.startsWith("/")) {
                 path = "/" + path;
             }
-            String url = scheme + "://" + host + (port != 80 ? ":" + port : "") + path;
+            String baseUrl = scheme + "://" + host + (port != 80 ? ":" + port : "") + path;
+
+            String url = baseUrl;
+            if (uriTemplate != null) {
+                // make sure to avoid double slashes
+                if (uriTemplate.startsWith("/")) {
+                    url = url + uriTemplate;
+                } else {
+                    url = url + "/" + uriTemplate;
+                }
+            }
 
             // optional binding type information
             String inType = (String) getParameters().get("inType");
@@ -197,7 +217,7 @@ public class RestEndpoint extends DefaultEndpoint {
             // add to rest registry so we can keep track of them, we will remove from the registry when the consumer is removed
             // the rest registry will automatic keep track when the consumer is removed,
             // and un-register the REST service from the registry
-            getCamelContext().getRestRegistry().addRestService(consumer, url, getVerb(), getPath(), getConsumes(), getProduces(), inType, outType);
+            getCamelContext().getRestRegistry().addRestService(consumer, url, baseUrl, getPath(), getUriTemplate(), getVerb(), getConsumes(), getProduces(), inType, outType);
 
             return consumer;
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
index 1d6d8f6..62194ad 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
@@ -38,9 +38,9 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
     private CamelContext camelContext;
     private final Map<Consumer, RestService> registry = new LinkedHashMap<Consumer, RestService>();
 
-    public void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces,
-                        String inType, String outType) {
-        RestServiceEntry entry = new RestServiceEntry(consumer, url, uriTemplate, method, consumes, produces, inType, outType);
+    public void addRestService(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method,
+                               String consumes, String produces, String inType, String outType) {
+        RestServiceEntry entry = new RestServiceEntry(consumer, url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType);
         registry.put(consumer, entry);
     }
 
@@ -85,18 +85,22 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
 
         private final Consumer consumer;
         private final String url;
-        private final String path;
+        private final String baseUrl;
+        private final String basePath;
+        private final String uriTemplate;
         private final String method;
         private final String consumes;
         private final String produces;
         private final String inType;
         private final String outType;
 
-        private RestServiceEntry(Consumer consumer, String url, String path, String method, String consumes, String produces,
-                                 String inType, String outType) {
+        private RestServiceEntry(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate,
+                                 String method, String consumes, String produces, String inType, String outType) {
             this.consumer = consumer;
             this.url = url;
-            this.path = path;
+            this.baseUrl = baseUrl;
+            this.basePath = basePath;
+            this.uriTemplate = uriTemplate;
             this.method = method;
             this.consumes = consumes;
             this.produces = produces;
@@ -112,8 +116,16 @@ public class DefaultRestRegistry extends ServiceSupport implements StaticService
             return url;
         }
 
+        public String getBaseUrl() {
+            return baseUrl;
+        }
+
+        public String getBasePath() {
+            return basePath;
+        }
+
         public String getUriTemplate() {
-            return path;
+            return uriTemplate;
         }
 
         public String getMethod() {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
index 37214b0..dfc9c19 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRestRegistry.java
@@ -60,15 +60,19 @@ public class ManagedRestRegistry extends ManagedService implements ManagedRestRe
             for (RestRegistry.RestService entry : services) {
                 CompositeType ct = CamelOpenMBeanTypes.listRestServicesCompositeType();
                 String url = entry.getUrl();
-                String method = entry.getMethod();
+                String baseUrl = entry.getBaseUrl();
+                String basePath = entry.getBasePath();
                 String uriTemplate = entry.getUriTemplate();
+                String method = entry.getMethod();
                 String consumes = entry.getConsumes();
                 String produces = entry.getProduces();
                 String state = entry.getState();
                 String inType = entry.getInType();
                 String outType = entry.getOutType();
-                CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "method", "uriTemplate", "consumes", "produces", "inType", "outType", "state"},
-                        new Object[]{url, method, uriTemplate, consumes, produces, inType, outType, state});
+
+                CompositeData data = new CompositeDataSupport(ct, new String[]
+                        {"url", "baseUrl", "basePath", "uriTemplate", "method", "consumes", "produces", "inType", "outType", "state"},
+                        new Object[]{url, baseUrl, basePath, uriTemplate, method, consumes, produces, inType, outType, state});
                 answer.put(data);
             }
             return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index a1c7bec..2039328 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -387,10 +387,7 @@ public class RestDefinition {
 
     private String buildUri(VerbDefinition verb) {
         if (uri != null && verb.getUri() != null) {
-            // make sure there is only one / slash separator between the two
-            String s = FileUtil.stripTrailingSeparator(uri);
-            String s2 = FileUtil.stripLeadingSeparator(verb.getUri());
-            return s + "/" + s2;
+            return uri + ":" + verb.getUri();
         } else if (uri != null) {
             return uri;
         } else if (verb.getUri() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
index 8af67c7..ac07fb7 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
@@ -32,13 +32,14 @@ public interface RestConsumerFactory {
      * @param camelContext the camel context
      * @param processor    the processor
      * @param verb         HTTP verb such as GET, POST
-     * @param path         HTTP context-path
+     * @param basePath     base path
+     * @param uriTemplate  uri template
      * @param consumes     media-types for what this REST service consume as input (accept-type), is <tt>null</tt> or <tt>&#42;/&#42;</tt> for anything
      * @param produces     media-types for what this REST service produces as output, can be <tt>null</tt>
      * @param parameters   additional parameters
      * @return a newly created REST consumer
      * @throws Exception can be thrown
      */
-    Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                             String consumes, String produces, Map<String, Object> parameters) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
index f8c894e..92ac05d 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestRegistry.java
@@ -43,12 +43,22 @@ public interface RestRegistry extends Service {
         String getState();
 
         /**
-         * Gets the absolute url to the REST service
+         * Gets the absolute url to the REST service (baseUrl + uriTemplate)
          */
         String getUrl();
 
         /**
-         * Gets the uri template (context path)
+         * Gets the base url to the REST service
+         */
+        String getBaseUrl();
+
+        /**
+         * Gets the base path to the REST service
+         */
+        String getBasePath();
+
+        /**
+         * Gets the uri template
          */
         String getUriTemplate();
 
@@ -88,12 +98,16 @@ public interface RestRegistry extends Service {
      *
      * @param consumer    the consumer
      * @param url         the absolute url of the REST service
+     * @param baseUrl     the base url of the REST service
+     * @param basePath    the base path
+     * @param uriTemplate the uri template
      * @param method      the HTTP method
-     * @param uriTemplate the uri template (context-path)
      * @param consumes    optional details about what media-types the REST service accepts
      * @param produces    optional details about what media-types the REST service returns
+     * @param inType      optional detail input binding to a FQN class name
+     * @param outType     optional detail output binding to a FQN class name
      */
-    void addRestService(Consumer consumer, String url, String method, String uriTemplate, String consumes, String produces,
+    void addRestService(Consumer consumer, String url, String baseUrl, String basePath, String uriTemplate, String method, String consumes, String produces,
                         String inType, String outType);
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
index 837933f..84819a4 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
@@ -28,10 +28,15 @@ import org.apache.camel.spi.RestConsumerFactory;
 public class DummyRestConsumerFactory implements RestConsumerFactory {
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
         // just use a seda endpoint for testing purpose
-        String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+        String id;
+        if (uriTemplate != null) {
+            id = ActiveMQUuidGenerator.generateSanitizedId(basePath + uriTemplate);
+        } else {
+            id = ActiveMQUuidGenerator.generateSanitizedId(basePath);
+        }
         // remove leading dash as we add that ourselves
         if (id.startsWith("-")) {
             id = id.substring(1);

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 757264d..48f4441 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -46,6 +46,7 @@ import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.HostUtils;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
@@ -940,18 +941,27 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
 
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
 
+        String path = basePath;
+        if (uriTemplate != null) {
+            // make sure to avoid double slashes
+            if (uriTemplate.startsWith("/")) {
+                path = path + uriTemplate;
+            } else {
+                path = path + "/" + uriTemplate;
+            }
+       }
         path = FileUtil.stripLeadingSeparator(path);
 
         String scheme = "http";
-        String host = "0.0.0.0";
+        String host = "";
         int port = 0;
 
         // if no explicit port/host configured, then use port from rest configuration
         RestConfiguration config = getCamelContext().getRestConfiguration();
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("jetty"))) {
+        if (config.getComponent() == null || config.getComponent().equals("jetty")) {
             if (config.getScheme() != null) {
                 scheme = config.getScheme();
             }
@@ -964,6 +974,15 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
             }
         }
 
+        // if no explicit hostname set then resolve the hostname
+        if (ObjectHelper.isEmpty(host)) {
+            if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+                host = HostUtils.getLocalHostName();
+            } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+                host = HostUtils.getLocalIp();
+            }
+        }
+
         Map<String, Object> map = new HashMap<String, Object>();
         // build query string, and append any endpoint configuration properties
         if (config != null && (config.getComponent() == null || config.getComponent().equals("jetty"))) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/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 90f09f1..cff2f1e 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
@@ -34,7 +34,9 @@ import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.HostUtils;
 import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
@@ -213,18 +215,27 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
     }
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
 
+        String path = basePath;
+        if (uriTemplate != null) {
+            // make sure to avoid double slashes
+            if (uriTemplate.startsWith("/")) {
+                path = path + uriTemplate;
+            } else {
+                path = path + "/" + uriTemplate;
+            }
+        }
         path = FileUtil.stripLeadingSeparator(path);
 
         String scheme = "http";
-        String host = "0.0.0.0";
+        String host = "";
         int port = 0;
 
         // if no explicit port/host configured, then use port from rest configuration
         RestConfiguration config = getCamelContext().getRestConfiguration();
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("netty-http"))) {
+        if (config.getComponent() == null || config.getComponent().equals("netty-http")) {
             if (config.getScheme() != null) {
                 scheme = config.getScheme();
             }
@@ -235,6 +246,15 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
             if (num > 0) {
                 port = num;
             }
+       }
+
+        // if no explicit hostname set then resolve the hostname
+        if (ObjectHelper.isEmpty(host)) {
+            if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+                host = HostUtils.getLocalHostName();
+            } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+                host = HostUtils.getLocalIp();
+            }
         }
 
         Map<String, Object> map = new HashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/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 ac90fde..6681f13 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
@@ -30,6 +30,8 @@ import org.apache.camel.impl.HeaderFilterStrategyComponent;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.HostUtils;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.restlet.Component;
@@ -501,18 +503,27 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
     }
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
 
+        String path = basePath;
+        if (uriTemplate != null) {
+            // make sure to avoid double slashes
+            if (uriTemplate.startsWith("/")) {
+                path = path + uriTemplate;
+            } else {
+                path = path + "/" + uriTemplate;
+            }
+        }
         path = FileUtil.stripLeadingSeparator(path);
 
         String scheme = "http";
-        String host = "0.0.0.0";
+        String host = "";
         int port = 0;
 
         // if no explicit port/host configured, then use port from rest configuration
         RestConfiguration config = getCamelContext().getRestConfiguration();
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("restlet"))) {
+        if (config.getComponent() == null || config.getComponent().equals("restlet")) {
             if (config.getScheme() != null) {
                 scheme = config.getScheme();
             }
@@ -525,6 +536,15 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
             }
         }
 
+        // if no explicit hostname set then resolve the hostname
+        if (ObjectHelper.isEmpty(host)) {
+            if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+                host = HostUtils.getLocalHostName();
+            } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+                host = HostUtils.getLocalIp();
+            }
+        }
+
         Map<String, Object> map = new HashMap<String, Object>();
         // build query string, and append any endpoint configuration properties
         if (config != null && (config.getComponent() == null || config.getComponent().equals("restlet"))) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/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 0fbe4d6..2dd57ac 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
@@ -163,10 +163,18 @@ public class ServletComponent extends HttpComponent implements RestConsumerFacto
         this.httpRegistry = httpRegistry;
     }
 
-
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
+        String path = basePath;
+        if (uriTemplate != null) {
+            // make sure to avoid double slashes
+            if (uriTemplate.startsWith("/")) {
+                path = path + uriTemplate;
+            } else {
+                path = path + "/" + uriTemplate;
+            }
+        }
         path = FileUtil.stripLeadingSeparator(path);
 
         // if no explicit port/host configured, then use port from rest configuration
@@ -174,7 +182,7 @@ public class ServletComponent extends HttpComponent implements RestConsumerFacto
 
         Map<String, Object> map = new HashMap<String, Object>();
         // build query string, and append any endpoint configuration properties
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("servlet"))) {
+        if (config.getComponent() == null || config.getComponent().equals("servlet")) {
             // setup endpoint options
             if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
                 map.putAll(config.getEndpointProperties());
@@ -183,7 +191,6 @@ public class ServletComponent extends HttpComponent implements RestConsumerFacto
 
         String query = URISupport.createQueryString(map);
 
-        // servlet:///hello
         String url = "servlet:///%s?httpMethodRestrict=%s";
         if (!query.isEmpty()) {
             url = url + "?" + query;

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/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 c3827ff..2dafa9d 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
@@ -28,6 +28,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
 import spark.Spark;
@@ -98,7 +99,7 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
         } else {
             // if no explicit port configured, then use port from rest configuration
             RestConfiguration config = getCamelContext().getRestConfiguration();
-            if (config != null && (config.getComponent() == null || config.getComponent().equals("spark-rest"))) {
+            if (config.getComponent() == null || config.getComponent().equals("spark-rest")) {
                 int port = config.getPort();
                 if (port > 0) {
                     Spark.setPort(port);
@@ -108,7 +109,7 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
 
         // configure component options
         RestConfiguration config = getCamelContext().getRestConfiguration();
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("spark-rest"))) {
+        if (config.getComponent() == null || config.getComponent().equals("spark-rest")) {
             // configure additional options on spark configuration
             if (config.getComponentProperties() != null && !config.getComponentProperties().isEmpty()) {
                 setProperties(sparkConfiguration, config.getComponentProperties());
@@ -123,9 +124,20 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
     }
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
 
+        String path = basePath;
+        if (uriTemplate != null) {
+            // make sure to avoid double slashes
+            if (uriTemplate.startsWith("/")) {
+                path = path + uriTemplate;
+            } else {
+                path = path + "/" + uriTemplate;
+            }
+        }
+        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);
@@ -141,7 +153,7 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
 
         // build query string, and append any endpoint configuration properties
         RestConfiguration config = getCamelContext().getRestConfiguration();
-        if (config != null && (config.getComponent() == null || config.getComponent().equals("spark-rest"))) {
+        if (config.getComponent() == null || config.getComponent().equals("spark-rest")) {
             // setup endpoint options
             if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
                 map.putAll(config.getEndpointProperties());

http://git-wip-us.apache.org/repos/asf/camel/blob/e239c0f2/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
index ad5c9e9..c87fae5 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
@@ -28,10 +28,15 @@ import org.apache.camel.spi.RestConsumerFactory;
 public class DummyRestConsumerFactory implements RestConsumerFactory {
 
     @Override
-    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path,
+    public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, String uriTemplate,
                                    String consumes, String produces, Map<String, Object> parameters) throws Exception {
         // just use a seda endpoint for testing purpose
-        String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+        String id;
+        if (uriTemplate != null) {
+            id = ActiveMQUuidGenerator.generateSanitizedId(path + uriTemplate);
+        } else {
+            id = ActiveMQUuidGenerator.generateSanitizedId(path);
+        }
         // remove leading dash as we add that ourselves
         if (id.startsWith("-")) {
             id = id.substring(1);


[3/4] git commit: CAMEL-7620: Rest DSL. Slight model change to have base path and uri template.

Posted by da...@apache.org.
CAMEL-7620: Rest DSL. Slight model change to have base path and uri template.


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

Branch: refs/heads/master
Commit: ff39d84160caf349f11ed1270be7b952b0588ba8
Parents: 7ff4020
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 6 15:30:10 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 6 15:30:10 2014 +0200

----------------------------------------------------------------------
 .../org/apache/camel/builder/RouteBuilder.java  |  6 ++---
 .../camel/component/rest/RestComponent.java     |  6 ++---
 .../camel/component/rest/RestEndpoint.java      | 14 +++++------
 .../apache/camel/model/rest/RestDefinition.java | 25 ++++++++++----------
 .../camel/model/rest/RestsDefinition.java       |  2 +-
 .../rest/FromRestExplicitComponentTest.java     |  2 +-
 .../rest/FromRestGetEmbeddedRouteTest.java      |  4 ++--
 .../component/rest/FromRestGetEndPathTest.java  |  4 ++--
 .../camel/component/rest/FromRestGetTest.java   |  4 ++--
 .../component/rest/FromRestUriPrefixTest.java   |  2 +-
 .../apache/camel/model/XmlRestParseTest.java    |  2 +-
 .../camel/blueprint/BlueprintJaxbRestTest.java  |  4 ++--
 .../camel/component/rest/RestRefTest.java       |  4 ++--
 .../rest/FromRestGetEmbeddedRouteTest.java      |  4 ++--
 .../component/rest/FromRestGetTest.java         |  4 ++--
 .../component/rest/FromRestUriPrefixTest.java   |  2 +-
 .../blueprint/component/rest/RestRefTest.java   |  4 ++--
 17 files changed, 46 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index c53979e..08c8abb 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -100,12 +100,12 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
     /**
      * Creates a new REST service
      *
-     * @param uri  the path
+     * @param path  the base path
      * @return the builder
      */
-    public RestDefinition rest(String uri) {
+    public RestDefinition rest(String path) {
         getRestCollection().setCamelContext(getContext());
-        RestDefinition answer = getRestCollection().rest(uri);
+        RestDefinition answer = getRestCollection().rest(path);
         configureRest(answer);
         return answer;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
index 687fb72..a39e722 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -36,10 +36,10 @@ public class RestComponent extends UriEndpointComponent {
         answer.setParameters(parameters);
 
         if (!remaining.contains(":")) {
-            throw new IllegalArgumentException("Invalid syntax. Must be rest:verb:path");
+            throw new IllegalArgumentException("Invalid syntax. Must be rest:method:path[:uriTemplate] where uriTemplate is optional");
         }
 
-        String verb = ObjectHelper.before(remaining, ":");
+        String method = ObjectHelper.before(remaining, ":");
         String s = ObjectHelper.after(remaining, ":");
 
         String path;
@@ -56,7 +56,7 @@ public class RestComponent extends UriEndpointComponent {
         path = FileUtil.stripTrailingSeparator(path);
         uriTemplate = FileUtil.stripTrailingSeparator(uriTemplate);
 
-        answer.setVerb(verb);
+        answer.setMethod(method);
         answer.setPath(path);
         answer.setUriTemplate(uriTemplate);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index 66001c5..7ce6564 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -36,7 +36,7 @@ import org.apache.camel.util.ObjectHelper;
 public class RestEndpoint extends DefaultEndpoint {
 
     @UriParam
-    private String verb;
+    private String method;
     @UriParam
     private String path;
     @UriParam
@@ -59,12 +59,12 @@ public class RestEndpoint extends DefaultEndpoint {
         return (RestComponent) super.getComponent();
     }
 
-    public String getVerb() {
-        return verb;
+    public String getMethod() {
+        return method;
     }
 
-    public void setVerb(String verb) {
-        this.verb = verb;
+    public void setMethod(String method) {
+        this.method = method;
     }
 
     public String getPath() {
@@ -164,7 +164,7 @@ public class RestEndpoint extends DefaultEndpoint {
         }
 
         if (factory != null) {
-            Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getUriTemplate(), getConsumes(), getProduces(), getParameters());
+            Consumer consumer = factory.createConsumer(getCamelContext(), processor, getMethod(), getPath(), getUriTemplate(), getConsumes(), getProduces(), getParameters());
             configureConsumer(consumer);
 
             // if no explicit port/host configured, then use port from rest configuration
@@ -217,7 +217,7 @@ public class RestEndpoint extends DefaultEndpoint {
             // add to rest registry so we can keep track of them, we will remove from the registry when the consumer is removed
             // the rest registry will automatic keep track when the consumer is removed,
             // and un-register the REST service from the registry
-            getCamelContext().getRestRegistry().addRestService(consumer, url, baseUrl, getPath(), getUriTemplate(), getVerb(), getConsumes(), getProduces(), inType, outType);
+            getCamelContext().getRestRegistry().addRestService(consumer, url, baseUrl, getPath(), getUriTemplate(), getMethod(), getConsumes(), getProduces(), inType, outType);
 
             return consumer;
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 2039328..cf322a9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -29,7 +29,6 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.apache.camel.CamelContext;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.ToDefinition;
-import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.URISupport;
 
 /**
@@ -40,7 +39,7 @@ import org.apache.camel.util.URISupport;
 public class RestDefinition {
 
     @XmlAttribute
-    private String uri;
+    private String path;
 
     @XmlAttribute
     private String consumes;
@@ -54,12 +53,12 @@ public class RestDefinition {
     @XmlElementRef
     private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
 
-    public String getUri() {
-        return uri;
+    public String getPath() {
+        return path;
     }
 
-    public void setUri(String uri) {
-        this.uri = uri;
+    public void setPath(String path) {
+        this.path = path;
     }
 
     public String getConsumes() {
@@ -98,10 +97,10 @@ public class RestDefinition {
     //-------------------------------------------------------------------------
 
     /**
-     * To set the uri
+     * To set the base path of this REST service
      */
-    public RestDefinition uri(String uri) {
-        setUri(uri);
+    public RestDefinition path(String path) {
+        setPath(path);
         return this;
     }
 
@@ -386,10 +385,10 @@ public class RestDefinition {
     }
 
     private String buildUri(VerbDefinition verb) {
-        if (uri != null && verb.getUri() != null) {
-            return uri + ":" + verb.getUri();
-        } else if (uri != null) {
-            return uri;
+        if (path != null && verb.getUri() != null) {
+            return path + ":" + verb.getUri();
+        } else if (path != null) {
+            return path;
         } else if (verb.getUri() != null) {
             return verb.getUri();
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
index 3386903..a195c3e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -92,7 +92,7 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
      */
     public RestDefinition rest(String uri) {
         RestDefinition rest = createRest();
-        rest.setUri(uri);
+        rest.setPath(uri);
         return rest(rest);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
index 3220f2e..0f98be2 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -31,7 +31,7 @@ public class FromRestExplicitComponentTest extends FromRestGetTest {
                 rest("/say/hello")
                         .get().to("direct:hello");
 
-                rest("dummy-rest").uri("/say/bye")
+                rest("dummy-rest").path("/say/bye")
                         .get().consumes("application/json").to("direct:bye")
                         .post().to("mock:update");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index 0caf36a..071c22e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -41,14 +41,14 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
         assertEquals("mock:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
index 6ef4fb2..a3108c1 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -28,14 +28,14 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 02864db..f6f73ec 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -41,14 +41,14 @@ public class FromRestGetTest extends ContextTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
index 3a5da15..790226d 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -28,7 +28,7 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
         assertEquals(1, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/", rest.getUri());
+        assertEquals("/say/", rest.getPath());
         assertEquals(3, rest.getVerbs().size());
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
         assertEquals("bye", rest.getVerbs().get(1).getUri());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java b/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java
index a9d7acc..e112369 100644
--- a/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java
+++ b/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java
@@ -26,7 +26,7 @@ public class XmlRestParseTest extends XmlTestSupport {
 
     public void testParseSimpleRestXml() throws Exception {
         RestDefinition rest = assertOneRest("simpleRest.xml");
-        assertEquals("/users", rest.getUri());
+        assertEquals("/users", rest.getPath());
 
         assertEquals(1, rest.getVerbs().size());
         GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0);

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index a8fd5cf..bc38614 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -70,8 +70,8 @@ public class BlueprintJaxbRestTest extends TestSupport {
 
         CamelContextFactoryBean cfb = (CamelContextFactoryBean) object;
         assertEquals(2, cfb.getRests().size());
-        assertEquals("/say/hello", cfb.getRests().get(0).getUri());
-        assertEquals("/say/bye", cfb.getRests().get(1).getUri());
+        assertEquals("/say/hello", cfb.getRests().get(0).getPath());
+        assertEquals("/say/bye", cfb.getRests().get(1).getPath());
 
         assertEquals(1, cfb.getRests().get(0).getVerbs().size());
         assertEquals(2, cfb.getRests().get(1).getVerbs().size());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java
index 322107a..3d9af1b 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java
@@ -33,14 +33,14 @@ public class RestRefTest extends SpringTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index 3446f25..c9cafe8 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -39,14 +39,14 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
         assertEquals("mock:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 68f1547..8b97268 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -39,14 +39,14 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
index 1f22a26..2fd6d3e 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
@@ -39,7 +39,7 @@ public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
         assertEquals(1, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/", rest.getUri());
+        assertEquals("/say/", rest.getPath());
         assertEquals(3, rest.getVerbs().size());
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
         assertEquals("bye", rest.getVerbs().get(1).getUri());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff39d841/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java
index 4d4d7b6..e25af30 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java
@@ -39,14 +39,14 @@ public class RestRefTest extends CamelBlueprintTestSupport {
         assertEquals(2, context.getRestDefinitions().size());
         RestDefinition rest = context.getRestDefinitions().get(0);
         assertNotNull(rest);
-        assertEquals("/say/hello", rest.getUri());
+        assertEquals("/say/hello", rest.getPath());
         assertEquals(1, rest.getVerbs().size());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
         assertNotNull(rest);
-        assertEquals("/say/bye", rest.getUri());
+        assertEquals("/say/bye", rest.getPath());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());


[2/4] git commit: CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.

Posted by da...@apache.org.
CAMEL-7620: Rest DSL. Enlist rest services in RestRegistry and JMX.


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

Branch: refs/heads/master
Commit: 7ff40206553e5d920ae72fc1c087f89880071125
Parents: e239c0f
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 6 14:02:57 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 6 14:42:23 2014 +0200

----------------------------------------------------------------------
 ...JettyRestServletResolveConsumerStrategy.java | 79 +++++++++++++++---
 .../jetty/rest/RestPathMatchingTest.java        | 84 +++++++++++++-------
 ...rvletRestServletResolveConsumerStrategy.java | 81 ++++++++++++++++---
 .../camel/example/rest/UserRouteBuilder.java    | 10 +--
 .../src/main/resources/camel-config-xml.xml     | 14 ++--
 .../src/main/webapp/index.html                  | 18 ++---
 6 files changed, 215 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
index 34f8ce2..1a7e05a 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.component.jetty;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpServletResolveConsumerStrategy;
-import org.apache.camel.util.ObjectHelper;
 
 /**
  * A {@link org.apache.camel.component.http.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
@@ -30,24 +33,61 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
 
     @Override
     public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
+        HttpConsumer answer = null;
+
         String path = request.getPathInfo();
         if (path == null) {
             return null;
         }
+        String method = request.getMethod();
+        if (method == null) {
+            return null;
+        }
 
-        for (String key : consumers.keySet()) {
-            if (useRestMatching(key) && matchRestPath(path, key)) {
-                return consumers.get(key);
+        List<HttpConsumer> candidates = new ArrayList<HttpConsumer>();
+
+        // first match by http method
+        for (Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
+            String restrict = entry.getValue().getEndpoint().getHttpMethodRestrict();
+            if (matchRestMethod(method, restrict)) {
+                candidates.add(entry.getValue());
             }
         }
 
-        // fallback to default
-        return super.resolve(request, consumers);
-    }
+        // then see if we got a direct match
+        Iterator<HttpConsumer> it = candidates.iterator();
+        while (it.hasNext()) {
+            HttpConsumer consumer = it.next();
+            String consumerPath = consumer.getPath();
+            if (matchRestPath(path, consumerPath, false)) {
+                answer = consumer;
+                break;
+            }
+        }
+
+        // then match by non wildcard path
+        if (answer == null) {
+            it = candidates.iterator();
+            while (it.hasNext()) {
+                HttpConsumer consumer = it.next();
+                String consumerPath = consumer.getPath();
+                if (!matchRestPath(path, consumerPath, true)) {
+                    it.remove();
+                }
+            }
+
+            // there should only be one
+            if (candidates.size() == 1) {
+                answer = candidates.get(0);
+            }
+        }
+
+        if (answer == null) {
+            // fallback to default
+            answer = super.resolve(request, consumers);
+        }
 
-    private boolean useRestMatching(String path) {
-        // only need to do rest matching if using { } placeholders
-        return path.indexOf('{') > -1;
+        return answer;
     }
 
     /**
@@ -57,7 +97,7 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
      * @param consumerPath  the consumer path which may use { } tokens
      * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
      */
-    public boolean matchRestPath(String requestPath, String consumerPath) {
+    public boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
         // remove starting/ending slashes
         if (requestPath.startsWith("/")) {
             requestPath = requestPath.substring(1);
@@ -86,7 +126,7 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
             String p1 = requestPaths[i];
             String p2 = consumerPaths[i];
 
-            if (p2.startsWith("{") && p2.endsWith("}")) {
+            if (wildcard && p2.startsWith("{") && p2.endsWith("}")) {
                 // always matches
                 continue;
             }
@@ -100,4 +140,19 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
         return true;
     }
 
+    /**
+     * Matches the given request HTTP method with the configured HTTP method of the consumer
+     *
+     * @param method    the request HTTP method
+     * @param restrict  the consumer configured HTTP restrict method
+     * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
+     */
+    public boolean matchRestMethod(String method, String restrict) {
+        if (restrict == null) {
+            return true;
+        }
+
+        return method.toLowerCase(Locale.US).endsWith(restrict.toLowerCase(Locale.US));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
index df66449..5e0d726 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
@@ -24,32 +24,62 @@ public class RestPathMatchingTest extends TestCase {
     private JettyRestServletResolveConsumerStrategy matcher = new JettyRestServletResolveConsumerStrategy();
 
     public void testRestPathMatcher() throws Exception {
-        assertTrue(matcher.matchRestPath("/foo/", "/foo/"));
-        assertTrue(matcher.matchRestPath("/foo/", "foo/"));
-        assertTrue(matcher.matchRestPath("/foo/", "foo"));
-        assertTrue(matcher.matchRestPath("foo/", "foo"));
-        assertTrue(matcher.matchRestPath("foo", "foo"));
-        assertTrue(matcher.matchRestPath("foo/", "foo"));
-        assertTrue(matcher.matchRestPath("/foo/", "foo"));
-
-        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014"));
-        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014"));
-        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/"));
-        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/"));
-        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}"));
-
-        assertFalse(matcher.matchRestPath("/foo/", "/bar/"));
-        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015"));
-        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015"));
-        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/"));
-        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/"));
-        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/"));
-
-        assertTrue(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}"));
-        assertTrue(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}"));
-        assertTrue(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}"));
-
-        assertTrue(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}"));
-        assertTrue(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}"));
+        assertTrue(matcher.matchRestPath("/foo/", "/foo/", true));
+        assertTrue(matcher.matchRestPath("/foo/", "foo/", true));
+        assertTrue(matcher.matchRestPath("/foo/", "foo", true));
+        assertTrue(matcher.matchRestPath("foo/", "foo", true));
+        assertTrue(matcher.matchRestPath("foo", "foo", true));
+        assertTrue(matcher.matchRestPath("foo/", "foo", true));
+        assertTrue(matcher.matchRestPath("/foo/", "foo", true));
+
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", true));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", true));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", true));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", true));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true));
+
+        assertFalse(matcher.matchRestPath("/foo/", "/bar/", true));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", true));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", true));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", true));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", true));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", true));
+
+        assertTrue(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", true));
+        assertTrue(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", true));
+        assertTrue(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", true));
+
+        assertTrue(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", true));
+        assertTrue(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", true));
+    }
+
+    public void testRestPathMatcherNoWildcard() throws Exception {
+        assertTrue(matcher.matchRestPath("/foo/", "/foo/", false));
+        assertTrue(matcher.matchRestPath("/foo/", "foo/", false));
+        assertTrue(matcher.matchRestPath("/foo/", "foo", false));
+        assertTrue(matcher.matchRestPath("foo/", "foo", false));
+        assertTrue(matcher.matchRestPath("foo", "foo", false));
+        assertTrue(matcher.matchRestPath("foo/", "foo", false));
+        assertTrue(matcher.matchRestPath("/foo/", "foo", false));
+
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", false));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", false));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", false));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", false));
+        assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true));
+
+        assertFalse(matcher.matchRestPath("/foo/", "/bar/", false));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", false));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", false));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", false));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", false));
+        assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", false));
+
+        assertFalse(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", false));
+        assertFalse(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", false));
+        assertFalse(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", false));
+
+        assertFalse(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", false));
+        assertFalse(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", false));
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
index 7a5a57b..ac24ef0 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
@@ -16,9 +16,16 @@
  */
 package org.apache.camel.component.servlet;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.camel.component.bean.MethodInfo;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpServletResolveConsumerStrategy;
 
@@ -29,24 +36,61 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
 
     @Override
     public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
+        HttpConsumer answer = null;
+
         String path = request.getPathInfo();
         if (path == null) {
             return null;
         }
+        String method = request.getMethod();
+        if (method == null) {
+            return null;
+        }
 
-        for (String key : consumers.keySet()) {
-            if (useRestMatching(key) && matchRestPath(path, key)) {
-                return consumers.get(key);
+        List<HttpConsumer> candidates = new ArrayList<HttpConsumer>();
+
+        // first match by http method
+        for (Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
+            String restrict = entry.getValue().getEndpoint().getHttpMethodRestrict();
+            if (matchRestMethod(method, restrict)) {
+                candidates.add(entry.getValue());
             }
         }
 
-        // fallback to default
-        return super.resolve(request, consumers);
-    }
+        // then see if we got a direct match
+        Iterator<HttpConsumer> it = candidates.iterator();
+        while (it.hasNext()) {
+            HttpConsumer consumer = it.next();
+            String consumerPath = consumer.getPath();
+            if (matchRestPath(path, consumerPath, false)) {
+                answer = consumer;
+                break;
+            }
+        }
+
+        // then match by non wildcard path
+        if (answer == null) {
+            it = candidates.iterator();
+            while (it.hasNext()) {
+                HttpConsumer consumer = it.next();
+                String consumerPath = consumer.getPath();
+                if (!matchRestPath(path, consumerPath, true)) {
+                    it.remove();
+                }
+            }
+
+            // there should only be one
+            if (candidates.size() == 1) {
+                answer = candidates.get(0);
+            }
+        }
+
+        if (answer == null) {
+            // fallback to default
+            answer = super.resolve(request, consumers);
+        }
 
-    private boolean useRestMatching(String path) {
-        // only need to do rest matching if using { } placeholders
-        return path.indexOf('{') > -1;
+        return answer;
     }
 
     /**
@@ -56,7 +100,7 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
      * @param consumerPath  the consumer path which may use { } tokens
      * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
      */
-    public boolean matchRestPath(String requestPath, String consumerPath) {
+    public boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
         // remove starting/ending slashes
         if (requestPath.startsWith("/")) {
             requestPath = requestPath.substring(1);
@@ -85,7 +129,7 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
             String p1 = requestPaths[i];
             String p2 = consumerPaths[i];
 
-            if (p2.startsWith("{") && p2.endsWith("}")) {
+            if (wildcard && p2.startsWith("{") && p2.endsWith("}")) {
                 // always matches
                 continue;
             }
@@ -99,4 +143,19 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
         return true;
     }
 
+    /**
+     * Matches the given request HTTP method with the configured HTTP method of the consumer
+     *
+     * @param method    the request HTTP method
+     * @param restrict  the consumer configured HTTP restrict method
+     * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
+     */
+    public boolean matchRestMethod(String method, String restrict) {
+        if (restrict == null) {
+            return true;
+        }
+
+        return method.toLowerCase(Locale.US).endsWith(restrict.toLowerCase(Locale.US));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
index 46280cd..7b4729a 100644
--- a/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/java/org/apache/camel/example/rest/UserRouteBuilder.java
@@ -36,14 +36,14 @@ public class UserRouteBuilder extends RouteBuilder {
         // this user REST service is json only
         rest("/user").consumes("application/json").produces("application/json")
 
-            .get("/view/{id}").outType(User.class)
+            .get("/{id}").outType(User.class)
                 .to("bean:userService?method=getUser(${header.id})")
 
-            .get("/list").outTypeList(User.class)
-                .to("bean:userService?method=listUsers")
+            .put().type(User.class).outType(User.class)
+                .to("bean:userService?method=updateUser")
 
-            .put("/update").type(User.class).outType(User.class)
-                .to("bean:userService?method=updateUser");
+            .get("/findAll").outTypeList(User.class)
+                .to("bean:userService?method=listUsers");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml
index ccb9a15..0ef2fcc 100755
--- a/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml
@@ -38,20 +38,20 @@
     <rest uri="/user" consumes="application/json" produces="application/json">
 
       <!-- this is a rest GET to view an user by the given id -->
-      <get uri="/view/{id}" outType="org.apache.camel.example.rest.User">
+      <get uri="/{id}" outType="org.apache.camel.example.rest.User">
         <to uri="bean:userService?method=getUser(${header.id})"/>
       </get>
 
-      <!-- this is a rest GET to view all users -->
-      <get uri="/list" outList="true" outType="org.apache.camel.example.rest.User">
-        <to uri="bean:userService?method=listUsers"/>
-      </get>
-
       <!-- this is a rest PUT to create/update an user -->
-      <put uri="/update" type="org.apache.camel.example.rest.User" outType="org.apache.camel.example.rest.User">
+      <put type="org.apache.camel.example.rest.User" outType="org.apache.camel.example.rest.User">
         <to uri="bean:userService?method=updateUser"/>
       </put>
 
+      <!-- this is a rest GET to find all users -->
+      <get uri="/findAll" outList="true" outType="org.apache.camel.example.rest.User">
+        <to uri="bean:userService?method=listUsers"/>
+      </get>
+
     </rest>
 
   </camelContext>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ff40206/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html
index beccdc1..e48aed4 100644
--- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html
+++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html
@@ -33,25 +33,25 @@ And for XML DSL the routes are define in XML code, in the <tt>src/main/resources
 <p/>
 There is a <i>user</i> REST service that supports the following operations
  <ul>
-   <li>view/<i>id</i> - to view a user with the given id </li>
-   <li>list - to view all users</li>
-   <li>update - to update/create an user</li>
+   <li>GET /user/{id} - to view a user with the given id </li>
+   <li>GET /user/final - to view all users</li>
+   <li>PUT /user - to update/create an user</li>
  </ul>
 
-The view and list operations are HTTP GET, and update is using HTTP PUT.
+The view operations are HTTP GET, and update is using HTTP PUT.
 
 From a web browser you can access the first two services using the following links
 
 <ul>
-  <li><a href="rest/user/view/123">user/view/123</a> - to view the user with id 123</li>
-  <li><a href="rest/user/list">user/list</a> - to list all users</li>
+  <li><a href="rest/user/123">user/123</a> - to view the user with id 123</li>
+  <li><a href="rest/user/findAll">user/findAll</a> - to list all users</li>
 </ul>
 
 From the command shell you can use curl to access the service as shown below:
 <pre>
-    curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user/view/123
-    curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user/list
-    curl -X PUT -d "{ \"id\": 666, \"name\": \"The devil\"}" -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user/update
+    curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user/123
+    curl -X GET -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user/findAll
+    curl -X PUT -d "{ \"id\": 666, \"name\": \"The devil\"}" -H "Accept: application/json" http://localhost:8080/camel-example-servlet-rest-tomcat-{version}/rest/user
 </pre>
 
 This assume you installed the example by copying the .war as <tt>camel-example-servlet-rest-tomcat-VERSION.war</tt>


[4/4] git commit: CAMEL-7620: Rest DSL. Fixed tests due recent changes.

Posted by da...@apache.org.
CAMEL-7620: Rest DSL. Fixed tests due recent changes.


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

Branch: refs/heads/master
Commit: ff842d3b0422628323c92fa23a7c85241b1c81f2
Parents: ff39d84
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 6 17:53:33 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Aug 7 08:58:41 2014 +0200

----------------------------------------------------------------------
 .../component/rest/FromRestUriPrefixTest.java   | 10 ++---
 .../impl/MultipleLifecycleStrategyTest.java     |  2 +-
 .../ManagedFromRestGetEmbeddedRouteTest.java    |  4 +-
 .../management/ManagedFromRestGetTest.java      |  4 +-
 ...roducerRouteAddRemoveRegisterAlwaysTest.java |  6 +--
 .../management/ManagedRouteAddRemoveTest.java   | 42 ++++++++++----------
 .../org/apache/camel/model/simpleRest.xml       |  2 +-
 .../src/test/resources/test-rest.xml            |  4 +-
 .../restlet/SpringRestRestletPojoInOutTest.xml  |  2 +-
 .../spring/LifecycleStrategyInjectionTest.java  |  2 +-
 .../MultipleLifecycleStrategyInjectionTest.java |  2 +-
 .../apache/camel/component/rest/RestRefTest.xml |  4 +-
 .../rest/SpringFromRestConfigurationTest.xml    |  4 +-
 .../rest/SpringFromRestGetEmbeddedRouteTest.xml |  4 +-
 .../component/rest/SpringFromRestGetTest.xml    |  4 +-
 .../rest/SpringFromRestUriPrefixTest.xml        |  6 +--
 .../component/rest/FromRestUriPrefixTest.java   |  6 +--
 .../rest/FromRestConfigurationTest.xml          |  4 +-
 .../rest/FromRestGetEmbeddedRouteTest.xml       |  4 +-
 .../component/rest/FromRestGetTest.xml          |  4 +-
 .../component/rest/FromRestUriPrefixTest.xml    |  6 +--
 .../blueprint/component/rest/RestRefTest.xml    |  4 +-
 22 files changed, 65 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
index 790226d..7eade0c 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -31,8 +31,8 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
         assertEquals("/say/", rest.getPath());
         assertEquals(3, rest.getVerbs().size());
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
-        assertEquals("bye", rest.getVerbs().get(1).getUri());
-        assertEquals("/bye", rest.getVerbs().get(2).getUri());
+        assertEquals("/bye", rest.getVerbs().get(1).getUri());
+        assertEquals("/hi", rest.getVerbs().get(2).getUri());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
@@ -40,7 +40,7 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
         getMockEndpoint("mock:update").expectedMessageCount(1);
-        template.sendBody("seda:post-say-bye", "I was here");
+        template.sendBody("seda:post-say-hi", "I was here");
         assertMockEndpointsSatisfied();
 
         String out = template.requestBody("seda:get-say-hello", "Me", String.class);
@@ -57,8 +57,8 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
                 // we have logic to cleanup those paths so there is only one / between the paths
                 rest("/say/")
                     .get("/hello").to("direct:hello")
-                    .get("bye").consumes("application/json").to("direct:bye")
-                    .post("/bye").to("mock:update");
+                    .get("/bye").consumes("application/json").to("direct:bye")
+                    .post("/hi").to("mock:update");
 
                 from("direct:hello")
                     .transform().constant("Hello World");

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java b/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
index dd417ac..0907c1f 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
@@ -51,7 +51,7 @@ public class MultipleLifecycleStrategyTest extends TestSupport {
         context.stop();
 
         List<String> expectedEvents = Arrays.asList("onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd",
-                                                    "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop");
+                "onServiceAdd", "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop");
         
         assertEquals(expectedEvents, dummy1.getEvents());
         assertEquals(expectedEvents, dummy2.getEvents());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
index 9e09b89..bfce4a1 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
@@ -49,8 +49,8 @@ public class ManagedFromRestGetEmbeddedRouteTest extends ManagementTestSupport {
         log.info(xml);
 
         assertTrue(xml.contains("<rests"));
-        assertTrue(xml.contains("<rest uri=\"/say/hello\">"));
-        assertTrue(xml.contains("<rest uri=\"/say/bye\">"));
+        assertTrue(xml.contains("<rest path=\"/say/hello\">"));
+        assertTrue(xml.contains("<rest path=\"/say/bye\">"));
         assertTrue(xml.contains("</rest>"));
         assertTrue(xml.contains("<get>"));
         assertTrue(xml.contains("<route"));

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index d1c627e..6bc98be 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -49,8 +49,8 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
         log.info(xml);
 
         assertTrue(xml.contains("<rests"));
-        assertTrue(xml.contains("<rest uri=\"/say/hello\">"));
-        assertTrue(xml.contains("<rest uri=\"/say/bye\">"));
+        assertTrue(xml.contains("<rest path=\"/say/hello\">"));
+        assertTrue(xml.contains("<rest path=\"/say/bye\">"));
         assertTrue(xml.contains("</rest>"));
         assertTrue(xml.contains("<get>"));
         assertTrue(xml.contains("application/json"));

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
index 1a807b4..60432b1 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
@@ -49,7 +49,7 @@ public class ManagedProducerRouteAddRemoveRegisterAlwaysTest extends ManagementT
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // number of producers
         ObjectName onP = ObjectName.getInstance("org.apache.camel:context=camel-1,type=producers,*");
@@ -74,7 +74,7 @@ public class ManagedProducerRouteAddRemoveRegisterAlwaysTest extends ManagementT
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // but as its recipient list which is dynamic-to we add new producers because we have register always
         namesP = mbeanServer.queryNames(onP, null);
@@ -89,7 +89,7 @@ public class ManagedProducerRouteAddRemoveRegisterAlwaysTest extends ManagementT
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // and we still have the other producers, but not the one from the 2nd route that was removed
         namesP = mbeanServer.queryNames(onP, null);

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
index 58c0176..4ba5c04 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
@@ -59,7 +59,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
         // number of services
         ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,*");
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // number of producers
         ObjectName onP = ObjectName.getInstance("org.apache.camel:context=camel-1,type=producers,*");
@@ -84,7 +84,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // but we should have one more producer
         namesP = mbeanServer.queryNames(onP, null);
@@ -99,7 +99,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // and the 2nd producer should be removed
         namesP = mbeanServer.queryNames(onP, null);
@@ -119,7 +119,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // number of producers
         ObjectName onP = ObjectName.getInstance("org.apache.camel:context=camel-1,type=producers,*");
@@ -144,7 +144,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // but as its recipient list which is dynamic-to we do not add a new producer
         namesP = mbeanServer.queryNames(onP, null);
@@ -159,7 +159,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // and we still have the original producer
         namesP = mbeanServer.queryNames(onP, null);
@@ -179,7 +179,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // number of producers
         ObjectName onP = ObjectName.getInstance("org.apache.camel:context=camel-1,type=producers,*");
@@ -204,7 +204,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // but as its recipient list which is dynamic-to we do not add a new producer
         namesP = mbeanServer.queryNames(onP, null);
@@ -219,7 +219,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // and we still have the original producer
         namesP = mbeanServer.queryNames(onP, null);
@@ -239,7 +239,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Adding 2nd route");
 
@@ -269,7 +269,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // now stop and remove the 2nd route
         log.info("Stopping 2nd route");
@@ -281,7 +281,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Shutting down...");
     }
@@ -297,7 +297,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Adding 2nd route");
 
@@ -328,7 +328,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // now stop and remove the 2nd route
         log.info("Stopping 2nd route");
@@ -340,7 +340,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Shutting down...");
     }
@@ -356,7 +356,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Adding 2nd route");
 
@@ -385,7 +385,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // now stop and remove the 2nd route
         log.info("Stopping 2nd route");
@@ -397,7 +397,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Shutting down...");
     }
@@ -413,7 +413,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Adding 2nd route");
 
@@ -443,7 +443,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         // now stop and remove the 2nd route
         log.info("Stopping 2nd route");
@@ -455,7 +455,7 @@ public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
 
         // there should still be the same number of services
         names = mbeanServer.queryNames(on, null);
-        assertEquals(7, names.size());
+        assertEquals(8, names.size());
 
         log.info("Shutting down...");
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml b/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml
index de6ba7f..ea99960 100644
--- a/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml
+++ b/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml
@@ -18,7 +18,7 @@
 <rests xmlns="http://camel.apache.org/schema/spring"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
-  <rest uri="/users">
+  <rest path="/users">
     <get uri="/view/{id}">
       <to uri="direct:getUser"/>
     </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index f2a4598..b372d71 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -23,12 +23,12 @@
 
     <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get>
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.xml b/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.xml
index 5b2d6be..56558c7 100644
--- a/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.xml
+++ b/components/camel-restlet/src/test/resources/org/apache/camel/component/restlet/SpringRestRestletPojoInOutTest.xml
@@ -33,7 +33,7 @@
 
     <restConfiguration bindingMode="auto" component="restlet"/>
 
-    <rest uri="/users">
+    <rest path="/users">
       <post uri="/lives" type="org.apache.camel.component.restlet.UserPojo" outType="org.apache.camel.component.restlet.CountryPojo">
         <route>
           <bean beanType="org.apache.camel.component.restlet.UserService" method="livesWhere"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
index 4a9c3bb..5f41504 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/LifecycleStrategyInjectionTest.java
@@ -32,7 +32,7 @@ public class LifecycleStrategyInjectionTest extends SpringTestSupport {
     }
 
     public void testInjectedStrategy() throws Exception {
-        assertEquals(2, context.getLifecycleStrategies().size());
+        assertEquals(3, context.getLifecycleStrategies().size());
         assertIsInstanceOf(DummyLifecycleStrategy.class, context.getLifecycleStrategies().get(1));
     }
     

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/java/org/apache/camel/spring/MultipleLifecycleStrategyInjectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/MultipleLifecycleStrategyInjectionTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/MultipleLifecycleStrategyInjectionTest.java
index 92c54b9..eae218a 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/MultipleLifecycleStrategyInjectionTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/MultipleLifecycleStrategyInjectionTest.java
@@ -32,7 +32,7 @@ public class MultipleLifecycleStrategyInjectionTest extends SpringTestSupport {
     }
 
     public void testInjectedStrategy() throws Exception {
-        assertEquals(3, context.getLifecycleStrategies().size());
+        assertEquals(4, context.getLifecycleStrategies().size());
         assertIsInstanceOf(DummyLifecycleStrategy.class, context.getLifecycleStrategies().get(1));
         assertIsInstanceOf(DummyLifecycleStrategy.class, context.getLifecycleStrategies().get(2));
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
index c381953..9d87eaa 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
@@ -26,7 +26,7 @@
   <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
 
   <restContext id="myCoolRest" xmlns="http://camel.apache.org/schema/spring">
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
@@ -37,7 +37,7 @@
 
     <restContextRef ref="myCoolRest"/>
 
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
index 5a41c65..2be2f49 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
@@ -34,12 +34,12 @@
       <consumerProperty key="pollTimeout" value="1000"/>
     </restConfiguration>
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index 4961e7e..6d365ba 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -27,7 +27,7 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <route>
           <to uri="mock:hello"/>
@@ -37,7 +37,7 @@
         </route>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <route>
           <to uri="mock:bye"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 4fa30ec..fc83f40 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -27,12 +27,12 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
index c2a8aa7..b0b07e2 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
@@ -27,14 +27,14 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-    <rest uri="/say/">
+    <rest path="/say/">
       <get uri="/hello">
         <to uri="direct:hello"/>
       </get>
-      <get uri="bye" consumes="application/json">
+      <get uri="/bye" consumes="application/json">
         <to uri="direct:bye"/>
       </get>
-      <post uri="/bye">
+      <post uri="/hi">
         <to uri="mock:update"/>
       </post>
     </rest>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
index 2fd6d3e..11417ca 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
@@ -42,8 +42,8 @@ public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
         assertEquals("/say/", rest.getPath());
         assertEquals(3, rest.getVerbs().size());
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
-        assertEquals("bye", rest.getVerbs().get(1).getUri());
-        assertEquals("/bye", rest.getVerbs().get(2).getUri());
+        assertEquals("/bye", rest.getVerbs().get(1).getUri());
+        assertEquals("/hi", rest.getVerbs().get(2).getUri());
         ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
@@ -51,7 +51,7 @@ public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
         getMockEndpoint("mock:update").expectedMessageCount(1);
-        template.sendBody("seda:post-say-bye", "I was here");
+        template.sendBody("seda:post-say-hi", "I was here");
         assertMockEndpointsSatisfied();
 
         String out = template.requestBody("seda:get-say-hello", "Me", String.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
index cd1f3cd..0c8c8f9 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
@@ -32,12 +32,12 @@
       <consumerProperty key="pollTimeout" value="1000"/>
     </restConfiguration>
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
index 3a1fb99..8d9e5be 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -25,7 +25,7 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <route>
           <to uri="mock:hello"/>
@@ -35,7 +35,7 @@
         </route>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <route>
           <to uri="mock:bye"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index 578ed92..f0e8c56 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -25,12 +25,12 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
     </rest>
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
index 2319f0d..7dc42ea 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
@@ -25,14 +25,14 @@
 
   <camelContext xmlns="http://camel.apache.org/schema/blueprint">
 
-    <rest uri="/say/">
+    <rest path="/say/">
       <get uri="/hello">
         <to uri="direct:hello"/>
       </get>
-      <get uri="bye" consumes="application/json">
+      <get uri="/bye" consumes="application/json">
         <to uri="direct:bye"/>
       </get>
-      <post uri="/bye">
+      <post uri="/hi">
         <to uri="mock:update"/>
       </post>
     </rest>

http://git-wip-us.apache.org/repos/asf/camel/blob/ff842d3b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml
index c12c6e3..f1fd55f 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml
@@ -24,7 +24,7 @@
   <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
 
   <restContext id="myCoolRest" xmlns="http://camel.apache.org/schema/blueprint">
-    <rest uri="/say/hello">
+    <rest path="/say/hello">
       <get>
         <to uri="direct:hello"/>
       </get>
@@ -35,7 +35,7 @@
 
     <restContextRef ref="myCoolRest"/>
 
-    <rest uri="/say/bye">
+    <rest path="/say/bye">
       <get consumes="application/json">
         <to uri="direct:bye"/>
       </get>