camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [26/33] git commit: CAMEL-7364: Rest DSL allow rest to setup uri prefix and verbs to specify postfix uri.
Date Sun, 20 Jul 2014 06:53:32 GMT
CAMEL-7364: Rest DSL allow rest to setup uri prefix and verbs to specify postfix uri.


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

Branch: refs/heads/master
Commit: b3a717fe1915bcd5d192deb35fb4e2881f739e65
Parents: 3c52555
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 17 10:40:41 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200

----------------------------------------------------------------------
 .../org/apache/camel/builder/RouteBuilder.java  | 12 ++++
 .../apache/camel/model/rest/RestDefinition.java | 53 ++++++++++++++-
 .../camel/model/rest/RestsDefinition.java       | 18 ++++-
 .../apache/camel/model/rest/VerbDefinition.java | 35 ++++++++++
 .../rest/FromRestExplicitComponentTest.java     | 43 ++++++++++++
 .../camel/component/rest/FromRestGetTest.java   |  2 +-
 .../component/rest/FromRestUriPrefixTest.java   | 71 ++++++++++++++++++++
 .../rest/SpringFromRestUriPrefixTest.java       | 29 ++++++++
 .../rest/SpringFromRestUriPrefixTest.xml        | 57 ++++++++++++++++
 .../component/rest/FromRestUriPrefixTest.java   | 63 +++++++++++++++++
 .../component/rest/FromRestUriPrefixTest.xml    | 55 +++++++++++++++
 .../example/spark/MySparkRouteBuilder.java      |  2 +-
 12 files changed, 435 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 0fb2a52..e5d36bf 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
@@ -74,6 +74,18 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
     /**
      * Creates a new REST service
      *
+     * @return the builder
+     */
+    public RestDefinition rest() {
+        getRestCollection().setCamelContext(getContext());
+        RestDefinition answer = getRestCollection().rest();
+        configureRest(answer);
+        return answer;
+    }
+
+    /**
+     * Creates a new REST service
+     *
      * @param uri  the path
      * @return the builder
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 460e081..7257d37 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,6 +29,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.ToDefinition;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.URISupport;
 
 /**
@@ -73,6 +74,14 @@ public class RestDefinition {
     //-------------------------------------------------------------------------
 
     /**
+     * To set the uri
+     */
+    public RestDefinition uri(String uri) {
+        setUri(uri);
+        return this;
+    }
+
+    /**
      * To use a specific Camel rest component
      */
     public RestDefinition component(String componentId) {
@@ -84,26 +93,50 @@ public class RestDefinition {
         return addVerb("get", null);
     }
 
+    public RestDefinition get(String uri) {
+        return addVerb("get", uri);
+    }
+
     public RestDefinition post() {
         return addVerb("post", null);
     }
 
+    public RestDefinition post(String uri) {
+        return addVerb("post", uri);
+    }
+
     public RestDefinition put() {
         return addVerb("put", null);
     }
 
+    public RestDefinition put(String uri) {
+        return addVerb("put", uri);
+    }
+
     public RestDefinition delete() {
         return addVerb("delete", null);
     }
 
+    public RestDefinition delete(String uri) {
+        return addVerb("delete", uri);
+    }
+
     public RestDefinition head() {
         return addVerb("head", null);
     }
 
+    public RestDefinition head(String uri) {
+        return addVerb("head", uri);
+    }
+
     public RestDefinition verb(String verb) {
         return addVerb(verb, null);
     }
 
+    public RestDefinition verb(String verb, String uri) {
+        return addVerb(verb, uri);
+    }
+
     public RestDefinition consumes(String accept) {
         // add to last verb
         if (getVerbs().isEmpty()) {
@@ -132,7 +165,7 @@ public class RestDefinition {
     // Implementation
     //-------------------------------------------------------------------------
 
-    private RestDefinition addVerb(String verb, String url) {
+    private RestDefinition addVerb(String verb, String uri) {
         VerbDefinition answer;
 
         if ("get".equals(verb)) {
@@ -151,6 +184,7 @@ public class RestDefinition {
         }
 
         answer.setRest(this);
+        answer.setUri(uri);
         getVerbs().add(answer);
         return this;
     }
@@ -164,7 +198,7 @@ public class RestDefinition {
         List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
 
         for (VerbDefinition verb : getVerbs()) {
-            String from = "rest:" + verb.asVerb() + ":" + uri;
+            String from = "rest:" + verb.asVerb() + ":" + buildUri(verb);
             // append options
             Map<String, Object> options = new HashMap<String, Object>();
             if (getComponent() != null) {
@@ -187,4 +221,19 @@ public class RestDefinition {
         return answer;
     }
 
+    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;
+        } else if (uri != null) {
+            return uri;
+        } else if (verb.getUri() != null) {
+            return verb.getUri();
+        } else {
+            return "";
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 ebc3057..3386903 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
@@ -28,7 +28,7 @@ import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.OptionalIdentifiedDefinition;
 
 /**
- * Represents a collection of RESTs
+ * Represents a collection of {@link org.apache.camel.model.rest.RestDefinition REST's}
  */
 @XmlRootElement(name = "rests")
 @XmlAccessorType(XmlAccessType.FIELD)
@@ -77,12 +77,28 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
     // Fluent API
     //-------------------------------------------------------------------------
 
+    /**
+     * Creates a rest DSL
+     */
+    public RestDefinition rest() {
+        RestDefinition rest = createRest();
+        return rest(rest);
+    }
+
+    /**
+     * Creates a rest DSL
+     *
+     * @param uri the rest path
+     */
     public RestDefinition rest(String uri) {
         RestDefinition rest = createRest();
         rest.setUri(uri);
         return rest(rest);
     }
 
+    /**
+     * Adds the {@link org.apache.camel.model.rest.RestsDefinition}
+     */
     public RestDefinition rest(RestDefinition rest) {
         getRests().add(rest);
         return rest;

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 282e562..4347e75 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
@@ -32,6 +32,9 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition>
{
     private String method;
 
     @XmlAttribute
+    private String uri;
+
+    @XmlAttribute
     private String consumes;
 
     @XmlTransient
@@ -53,6 +56,14 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition>
{
         this.method = method;
     }
 
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
     public String getConsumes() {
         return consumes;
     }
@@ -68,26 +79,50 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition>
{
         return rest.get();
     }
 
+    public RestDefinition get(String uri) {
+        return rest.get(uri);
+    }
+
     public RestDefinition post() {
         return rest.post();
     }
 
+    public RestDefinition post(String uri) {
+        return rest.post(uri);
+    }
+
     public RestDefinition put() {
         return rest.put();
     }
 
+    public RestDefinition put(String uri) {
+        return rest.put(uri);
+    }
+
     public RestDefinition delete() {
         return rest.delete();
     }
 
+    public RestDefinition delete(String uri) {
+        return rest.delete(uri);
+    }
+
     public RestDefinition head() {
         return rest.head();
     }
 
+    public RestDefinition head(String uri) {
+        return rest.head(uri);
+    }
+
     public RestDefinition verb(String verb) {
         return rest.verb(verb);
     }
 
+    public RestDefinition verb(String verb, String uri) {
+        return rest.verb(verb, uri);
+    }
+
     public String asVerb() {
         // we do not want the jaxb model to repeat itself, by outputting <get method="get">
         // so we defer the verb from the instance type

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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
new file mode 100644
index 0000000..63a1e48
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.component.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class FromRestExplicitComponentTest extends FromRestGetTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                rest("/say/hello").component("dummy-rest")
+                        .get().to("direct:hello");
+
+                rest().component("dummy-rest").uri("/say/bye")
+                        .get().consumes("application/json").to("direct:bye").endRest()
+                        .post().to("mock:update");
+
+                from("direct:hello")
+                    .transform().constant("Hello World");
+
+                from("direct:bye")
+                    .transform().constant("Bye World");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 fdbe60a..2b40fd4 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
@@ -27,7 +27,7 @@ public class FromRestGetTest extends ContextTestSupport {
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry jndi = super.createRegistry();
-        jndi.bind("dummy-test", new DummyRestConsumerFactory());
+        jndi.bind("dummy-rest", new DummyRestConsumerFactory());
         return jndi;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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
new file mode 100644
index 0000000..5369d4a
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.component.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class FromRestUriPrefixTest extends FromRestGetTest {
+
+    public void testFromRestModel() throws Exception {
+        assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+        assertEquals(1, context.getRestDefinitions().size());
+        RestDefinition rest = context.getRestDefinitions().get(0);
+        assertNotNull(rest);
+        assertEquals("/say/", rest.getUri());
+        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());
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        assertEquals("direct:hello", to.getUri());
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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() {
+            @Override
+            public void configure() throws Exception {
+                // 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");
+
+                from("direct:hello")
+                    .transform().constant("Hello World");
+
+                from("direct:bye")
+                    .transform().constant("Bye World");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
new file mode 100644
index 0000000..6eafd23
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.component.rest;
+
+import org.apache.camel.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestUriPrefixTest extends FromRestUriPrefixTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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
new file mode 100644
index 0000000..c2a8aa7
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- use a dummy rest consumer factory for the rest engine -->
+  <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+    <rest uri="/say/">
+      <get uri="/hello">
+        <to uri="direct:hello"/>
+      </get>
+      <get uri="bye" consumes="application/json">
+        <to uri="direct:bye"/>
+      </get>
+      <post uri="/bye">
+        <to uri="mock:update"/>
+      </post>
+    </rest>
+
+    <route>
+      <from uri="direct:hello"/>
+      <transform>
+        <constant>Hello World</constant>
+      </transform>
+    </route>
+    <route>
+      <from uri="direct:bye"/>
+      <transform>
+        <constant>Bye World</constant>
+      </transform>
+    </route>
+
+  </camelContext>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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
new file mode 100644
index 0000000..cf6d7b8
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Test;
+
+public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml";
+    }
+
+    protected int getExpectedNumberOfRoutes() {
+        return 2 + 3;
+    }
+
+    @Test
+    public void testFromRestModel() throws Exception {
+        assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+        assertEquals(1, context.getRestDefinitions().size());
+        RestDefinition rest = context.getRestDefinitions().get(0);
+        assertNotNull(rest);
+        assertEquals("/say/", rest.getUri());
+        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());
+        ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+        assertEquals("direct:hello", to.getUri());
+        to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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
new file mode 100644
index 0000000..2319f0d
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  <!-- use a dummy rest consumer factory for the rest engine -->
+  <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
+
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+    <rest uri="/say/">
+      <get uri="/hello">
+        <to uri="direct:hello"/>
+      </get>
+      <get uri="bye" consumes="application/json">
+        <to uri="direct:bye"/>
+      </get>
+      <post uri="/bye">
+        <to uri="mock:update"/>
+      </post>
+    </rest>
+
+    <route>
+      <from uri="direct:hello"/>
+      <transform>
+        <constant>Hello World</constant>
+      </transform>
+    </route>
+    <route>
+      <from uri="direct:bye"/>
+      <transform>
+        <constant>Bye World</constant>
+      </transform>
+    </route>
+
+  </camelContext>
+
+</blueprint>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 891746a..504a9a6 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
@@ -28,7 +28,7 @@ public class MySparkRouteBuilder extends RouteBuilder {
 
         // we only have a GET service, but we have PUT, POST, and all the other REST verbs
we can use
 
-       rest("hello/:me").component("spark-rest")
+       rest().component("spark-rest").uri("hello/:me")
            .get().consumes("text/plain")
                .to("log:input")
                .transform().simple("Hello ${header.me}").endRest()


Mime
View raw message