camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [29/33] git commit: CAMEL-7364: Rest DSL allow to configure embedded routes. And have a shorthand for a singular to without the needed for explicit defining route.
Date Sun, 20 Jul 2014 06:53:35 GMT
CAMEL-7364: Rest DSL allow to configure embedded routes. And have a shorthand for a singular
to without the needed for explicit defining route.


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

Branch: refs/heads/master
Commit: df7b90c4972281961d975e897eff10fbaefc547c
Parents: 7bbb88b
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jul 19 08:35:43 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jul 19 09:38:53 2014 +0200

----------------------------------------------------------------------
 .../apache/camel/model/ProcessorDefinition.java | 23 +----
 .../org/apache/camel/model/RouteDefinition.java | 11 +++
 .../apache/camel/model/rest/RestDefinition.java | 43 +++++++--
 .../apache/camel/model/rest/VerbDefinition.java | 75 +++++++++++++---
 .../rest/FromRestConfigurationTest.java         |  2 +-
 .../rest/FromRestExplicitComponentTest.java     |  2 +-
 .../rest/FromRestGetEmbeddedRouteTest.java      |  7 +-
 .../component/rest/FromRestGetEndPathTest.java  | 34 ++++++-
 .../camel/component/rest/FromRestGetTest.java   |  4 +-
 .../component/rest/FromRestUriPrefixTest.java   |  4 +-
 .../ManagedFromRestGetEmbeddedRouteTest.java    | 93 ++++++++++++++++++++
 .../management/ManagedFromRestGetTest.java      |  3 +
 .../component/restlet/RestRestletGetTest.java   |  1 +
 .../sparkrest/RestCamelSparkAcceptTest.java     |  1 +
 .../sparkrest/RestCamelSparkParamTest.java      |  1 +
 .../RestCamelSparkRequestBeanTest.java          |  1 +
 .../sparkrest/RestCamelSparkSplatTest.java      |  1 +
 .../rest/SpringFromRestGetEmbeddedRouteTest.xml | 20 +++--
 .../rest/FromRestGetEmbeddedRouteTest.java      |  4 +-
 .../component/rest/FromRestGetTest.java         |  4 +-
 .../component/rest/FromRestUriPrefixTest.java   |  4 +-
 .../rest/FromRestGetEmbeddedRouteTest.xml       | 20 +++--
 .../example/spark/MySparkRouteBuilder.java      |  5 +-
 23 files changed, 296 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index b7095fc..0f98218 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -53,7 +53,6 @@ import org.apache.camel.model.language.ConstantExpression;
 import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.model.language.LanguageExpression;
 import org.apache.camel.model.rest.RestDefinition;
-import org.apache.camel.model.rest.VerbDefinition;
 import org.apache.camel.processor.InterceptEndpointProcessor;
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
@@ -1325,27 +1324,13 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
      */
     public RestDefinition endRest() {
         ProcessorDefinition<?> def = this;
-        if (def.getParent() instanceof VerbDefinition) {
-            return ((VerbDefinition) def.getParent()).getRest();
-        }
-
-        // are we already a choice?
-        if (def instanceof VerbDefinition) {
-            return ((VerbDefinition) def).getRest();
-        }
 
-        // okay end this and get back to the choice
-        def = end();
-        if (def.getParent() instanceof VerbDefinition) {
-            return ((VerbDefinition) def.getParent()).getRest();
-        }
-
-        // are we already a choice?
-        if (def instanceof VerbDefinition) {
-            return ((VerbDefinition) def).getRest();
+        RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
+        if (route != null) {
+            return route.getRestDefinition();
         }
 
-        throw new IllegalArgumentException("Cannot find VerbDefinition to allow endRest");
+        throw new IllegalArgumentException("Cannot find RouteDefinition to allow endRest");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 7f12ccf..5ecd5a4 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -44,6 +44,7 @@ import org.apache.camel.builder.AdviceWithTask;
 import org.apache.camel.builder.ErrorHandlerBuilderRef;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultRouteContext;
+import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.processor.interceptor.HandleFault;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.RouteContext;
@@ -81,6 +82,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition>
{
     // (will by default be context scoped of no explicit error handler configured)
     private boolean contextScopedErrorHandler = true;
     private Boolean rest;
+    private RestDefinition restDefinition;
 
     public RouteDefinition() {
     }
@@ -779,6 +781,15 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition>
{
         return rest;
     }
 
+    public RestDefinition getRestDefinition() {
+        return restDefinition;
+    }
+
+    @XmlTransient
+    public void setRestDefinition(RestDefinition restDefinition) {
+        this.restDefinition = restDefinition;
+    }
+
     @SuppressWarnings("deprecation")
     public boolean isContextScopedErrorHandler(CamelContext context) {
         if (!contextScopedErrorHandler) {

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9301ef9..e40c663 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
@@ -131,17 +131,39 @@ public class RestDefinition {
         return this;
     }
 
-    @Deprecated
-    public VerbDefinition to(String url) {
+    /**
+     * Routes directly to the given endpoint.
+     * <p/>
+     * If you need additional routing capabilities, then use {@link #route()} instead.
+     *
+     * @param uri the uri of the endpoint
+     * @return this builder
+     */
+    public RestDefinition to(String uri) {
         // add to last verb
         if (getVerbs().isEmpty()) {
             throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
         }
 
+        ToDefinition to = new ToDefinition(uri);
+
         VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
-        verb.addOutput(new ToDefinition(url));
+        verb.setTo(to);
+        return this;
+    }
 
-        return verb;
+    public RouteDefinition route() {
+        // add to last verb
+        if (getVerbs().isEmpty()) {
+            throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+        }
+
+        // link them together so we can navigate using Java DSL
+        RouteDefinition route = new RouteDefinition();
+        route.setRestDefinition(this);
+        VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+        verb.setRoute(route);
+        return route;
     }
 
     // Implementation
@@ -191,10 +213,19 @@ public class RestDefinition {
                 from = from + "?" + query;
             }
 
-            RouteDefinition route = new RouteDefinition();
+            // either the verb has a singular to or a embedded route
+            RouteDefinition route = verb.getRoute();
+            if (route == null) {
+                // it was a singular to, so add a new route and add the singular
+                // to as output to this route
+                route = new RouteDefinition();
+                route.getOutputs().add(verb.getTo());
+            }
+
+            // the route should be from this rest endpoint
             route.fromRest(from);
+            route.setRestDefinition(this);
             answer.add(route);
-            route.getOutputs().addAll(verb.getOutputs());
         }
 
         return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
index 4347e75..fd73f02 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
@@ -19,14 +19,18 @@ package org.apache.camel.model.rest;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
-import org.apache.camel.model.OutputDefinition;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
 
 @XmlRootElement(name = "verb")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class VerbDefinition extends OutputDefinition<VerbDefinition> {
+public class VerbDefinition {
 
     @XmlAttribute
     private String method;
@@ -37,17 +41,22 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition>
{
     @XmlAttribute
     private String consumes;
 
+    // used by XML DSL to either select a <to> or <route>
+    // so we need to use the common type OptionalIdentifiedDefinition
+    @XmlElements({
+            @XmlElement(required = false, name = "to", type = ToDefinition.class),
+            @XmlElement(required = false, name = "route", type = RouteDefinition.class)}
+    )
+    private OptionalIdentifiedDefinition toOrRoute;
+
+    // the Java DSL uses the to or route definition directory
+    @XmlTransient
+    private ToDefinition to;
+    @XmlTransient
+    private RouteDefinition route;
     @XmlTransient
     private RestDefinition rest;
 
-    public RestDefinition getRest() {
-        return rest;
-    }
-
-    public void setRest(RestDefinition rest) {
-        this.rest = rest;
-    }
-
     public String getMethod() {
         return method;
     }
@@ -72,6 +81,52 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition>
{
         this.consumes = consumes;
     }
 
+    public RestDefinition getRest() {
+        return rest;
+    }
+
+    public void setRest(RestDefinition rest) {
+        this.rest = rest;
+    }
+
+    public RouteDefinition getRoute() {
+        if (route != null) {
+            return route;
+        } else if (toOrRoute instanceof RouteDefinition) {
+            return (RouteDefinition) toOrRoute;
+        } else {
+            return null;
+        }
+    }
+
+    public void setRoute(RouteDefinition route) {
+        this.route = route;
+        this.toOrRoute = route;
+    }
+
+    public ToDefinition getTo() {
+        if (to != null) {
+            return to;
+        } else if (toOrRoute instanceof ToDefinition) {
+            return (ToDefinition) toOrRoute;
+        } else {
+            return null;
+        }
+    }
+
+    public void setTo(ToDefinition to) {
+        this.to = to;
+        this.toOrRoute = to;
+    }
+
+    public OptionalIdentifiedDefinition getToOrRoute() {
+        return toOrRoute;
+    }
+
+    public void setToOrRoute(OptionalIdentifiedDefinition toOrRoute) {
+        this.toOrRoute = toOrRoute;
+    }
+
     // Fluent API
     // -------------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
index 49fb6c8..3f22c0f 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
@@ -41,7 +41,7 @@ public class FromRestConfigurationTest extends FromRestGetTest {
                         .get().to("direct:hello");
 
                 rest("/say/bye")
-                        .get().consumes("application/json").to("direct:bye").endRest()
+                        .get().consumes("application/json").to("direct:bye")
                         .post().to("mock:update");
 
                 from("direct:hello")

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9e6d44c..3220f2e 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
@@ -32,7 +32,7 @@ public class FromRestExplicitComponentTest extends FromRestGetTest {
                         .get().to("direct:hello");
 
                 rest("dummy-rest").uri("/say/bye")
-                        .get().consumes("application/json").to("direct:bye").endRest()
+                        .get().consumes("application/json").to("direct:bye")
                         .post().to("mock:update");
 
                 from("direct:hello")

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 088085d..ce96957 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
@@ -43,7 +43,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
         assertNotNull(rest);
         assertEquals("/say/hello", rest.getUri());
         assertEquals(1, rest.getVerbs().size());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
         assertEquals("mock:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
@@ -51,7 +51,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
         assertEquals("/say/bye", rest.getUri());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
         assertEquals("mock:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
@@ -72,13 +72,16 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
             public void configure() throws Exception {
                 rest("/say/hello")
                     .get()
+                        .route()
                         .to("mock:hello")
                         .transform(constant("Hello World"));
 
                 rest("/say/bye")
                     .get().consumes("application/json")
+                        .route()
                         .to("mock:bye")
                         .transform(constant("Bye World"))
+                        .endRest()
                     .post()
                         .to("mock:update");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9a09a7d..7f2d439 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
@@ -17,9 +17,41 @@
 package org.apache.camel.component.rest;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
 
 public class FromRestGetEndPathTest extends FromRestGetTest {
 
+    public void testFromRestModel() throws Exception {
+        assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+        assertEquals(2, context.getRestDefinitions().size());
+        RestDefinition rest = context.getRestDefinitions().get(0);
+        assertNotNull(rest);
+        assertEquals("/say/hello", rest.getUri());
+        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(2, rest.getVerbs().size());
+        assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
+        assertEquals("direct:bye", to.getUri());
+
+        // 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");
+        assertMockEndpointsSatisfied();
+
+        String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+        assertEquals("Hello World", out);
+        String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+        assertEquals("Bye World", out2);
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -29,7 +61,7 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
                         .get().to("direct:hello");
 
                 rest("/say/bye")
-                        .get().consumes("application/json").to("direct:bye").endRest()
+                        .get().consumes("application/json").route().to("direct:bye").endRest()
                         .post().to("mock:update");
 
                 from("direct:hello")

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 2b40fd4..02864db 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
@@ -43,7 +43,7 @@ public class FromRestGetTest extends ContextTestSupport {
         assertNotNull(rest);
         assertEquals("/say/hello", rest.getUri());
         assertEquals(1, rest.getVerbs().size());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
@@ -51,7 +51,7 @@ public class FromRestGetTest extends ContextTestSupport {
         assertEquals("/say/bye", rest.getUri());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 5369d4a..3a5da15 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
@@ -33,9 +33,9 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
         assertEquals("bye", rest.getVerbs().get(1).getUri());
         assertEquals("/bye", rest.getVerbs().get(2).getUri());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
         assertEquals("direct:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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
new file mode 100644
index 0000000..9e09b89
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.SimpleRegistry;
+
+public class ManagedFromRestGetEmbeddedRouteTest extends ManagementTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        SimpleRegistry registry = new SimpleRegistry();
+        registry.put("dummy-test", new DummyRestConsumerFactory());
+        return new DefaultCamelContext(registry);
+    }
+
+    public void testFromRestModel() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
+        assertNotNull(xml);
+        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>"));
+        assertTrue(xml.contains("<get>"));
+        assertTrue(xml.contains("<route"));
+        assertTrue(xml.contains("<transform"));
+        assertTrue(xml.contains("<post>"));
+        assertTrue(xml.contains("application/json"));
+        assertTrue(xml.contains("</rests>"));
+
+        String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+        log.info(xml2);
+        // and we should have rest in the routes that indicate its from a rest dsl
+        assertTrue(xml2.contains("rest=\"true\""));
+
+        // there should be 2 + 1 routes
+        assertEquals(2 + 1, context.getRouteDefinitions().size());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                rest("/say/hello")
+                    .get()
+                        .route()
+                        .to("mock:hello")
+                        .transform(constant("Hello World"));
+
+                rest("/say/bye")
+                    .get().consumes("application/json")
+                        .route()
+                        .to("mock:bye")
+                        .transform(constant("Bye World"))
+                    .endRest()
+                    .post()
+                        .to("mock:update");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 47a307e..651359b 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
@@ -61,6 +61,9 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
         log.info(xml2);
         // and we should have rest in the routes that indicate its from a rest dsl
         assertTrue(xml2.contains("rest=\"true\""));
+
+        // there should be 3 + 2 routes
+        assertEquals(3 + 2, context.getRouteDefinitions().size());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
index 409a401..5c1809e 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
@@ -43,6 +43,7 @@ public class RestRestletGetTest extends RestletTestSupport {
                 // use the rest DSL to define the rest services
                 rest("/users/")
                     .get("{id}/basic")
+                        .route()
                         .to("mock:input")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
index 92ebbcf..cb00875 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
@@ -27,6 +27,7 @@ public class RestCamelSparkAcceptTest extends CamelSparkAcceptTest {
             public void configure() throws Exception {
                 rest("/hello")
                     .get().consumes("application/json")
+                        .route()
                         .to("mock:foo")
                         .transform().constant("{ \"reply\": \"Bye World\" }");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
index c9d014f..2ae55fe 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
@@ -27,6 +27,7 @@ public class RestCamelSparkParamTest extends CamelSparkParamTest {
             @Override
             public void configure() throws Exception {
                 rest("/hello/{name}").get()
+                    .route()
                     .to("mock:foo")
                     .transform().simple("Bye ${header.name}");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
index eb7da29..0685e02 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
@@ -26,6 +26,7 @@ public class RestCamelSparkRequestBeanTest extends CamelSparkRequestBeanTest
{
             @Override
             public void configure() throws Exception {
                 rest("/hello/*/to/*").get()
+                    .route()
                     .to("mock:foo")
                     .bean(RestCamelSparkRequestBeanTest.class, "doSomething");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
index 08f0b83..470623b 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
@@ -26,6 +26,7 @@ public class RestCamelSparkSplatTest extends CamelSparkSplatTest {
             @Override
             public void configure() throws Exception {
                 rest("/hello/*/to/*").get()
+                    .route()
                     .to("mock:foo")
                     .transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 1b26601..4961e7e 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
@@ -29,18 +29,22 @@
 
     <rest uri="/say/hello">
       <get>
-        <to uri="mock:hello"/>
-        <transform>
-          <constant>Hello World</constant>
-        </transform>
+        <route>
+          <to uri="mock:hello"/>
+          <transform>
+            <constant>Hello World</constant>
+          </transform>
+        </route>
       </get>
     </rest>
     <rest uri="/say/bye">
       <get consumes="application/json">
-        <to uri="mock:bye"/>
-        <transform>
-          <constant>Bye World</constant>
-        </transform>
+        <route>
+          <to uri="mock:bye"/>
+          <transform>
+            <constant>Bye World</constant>
+          </transform>
+        </route>
       </get>
       <post>
         <to uri="mock:update"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9074f40..e0c9af6 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
@@ -41,7 +41,7 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport
{
         assertNotNull(rest);
         assertEquals("/say/hello", rest.getUri());
         assertEquals(1, rest.getVerbs().size());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
         assertEquals("mock:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
@@ -49,7 +49,7 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport
{
         assertEquals("/say/bye", rest.getUri());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
         assertEquals("mock:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 af89205..68f1547 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
@@ -41,7 +41,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
         assertNotNull(rest);
         assertEquals("/say/hello", rest.getUri());
         assertEquals(1, rest.getVerbs().size());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
 
         rest = context.getRestDefinitions().get(1);
@@ -49,7 +49,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
         assertEquals("/say/bye", rest.getUri());
         assertEquals(2, rest.getVerbs().size());
         assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 cf6d7b8..1f22a26 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
@@ -44,9 +44,9 @@ public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
         assertEquals("/hello", rest.getVerbs().get(0).getUri());
         assertEquals("bye", rest.getVerbs().get(1).getUri());
         assertEquals("/bye", rest.getVerbs().get(2).getUri());
-        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:hello", to.getUri());
-        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
         assertEquals("direct:bye", to.getUri());
 
         // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9caa545..3a1fb99 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
@@ -27,18 +27,22 @@
 
     <rest uri="/say/hello">
       <get>
-        <to uri="mock:hello"/>
-        <transform>
-          <constant>Hello World</constant>
-        </transform>
+        <route>
+          <to uri="mock:hello"/>
+          <transform>
+            <constant>Hello World</constant>
+          </transform>
+        </route>
       </get>
     </rest>
     <rest uri="/say/bye">
       <get consumes="application/json">
-        <to uri="mock:bye"/>
-        <transform>
-          <constant>Bye World</constant>
-        </transform>
+        <route>
+          <to uri="mock:bye"/>
+          <transform>
+            <constant>Bye World</constant>
+          </transform>
+        </route>
       </get>
       <post>
         <to uri="mock:update"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index b8edb71..4c125f5 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -29,15 +29,18 @@ public class MySparkRouteBuilder extends RouteBuilder {
         // configure we want to use spark-rest as the component for the rest DSL
         restConfiguration().component("spark-rest");
 
-        // use the rest DSL to define rest services
+        // use the rest DSL to define rest services, and use embedded routes
         rest().uri("hello/:me")
             .get().consumes("text/plain")
+                .route()
                 .to("log:input")
                 .transform().simple("Hello ${header.me}").endRest()
             .get().consumes("application/json")
+                .route()
                 .to("log:input")
                 .transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest()
             .get().consumes("text/xml")
+                .route()
                 .to("log:input")
                 .transform().simple("<message>Hello ${header.me}</message>");
     }


Mime
View raw message