Repository: camel
Updated Branches:
  refs/heads/master f1cf1397b -> cba6e2e8f


CAMEL-7354: Rest DSL. Integrate with camel-jetty. Work in progress.


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

Branch: refs/heads/master
Commit: b1e23971d8517f438d6d27003c9441b4cc1337eb
Parents: 36d6420
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun Jul 27 09:55:58 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Jul 28 10:50:48 2014 +0200

----------------------------------------------------------------------
 components/camel-jetty/pom.xml                  | 11 ++++
 .../camel/component/jetty/rest/CountryPojo.java | 40 ++++++++++++++
 .../jetty/rest/RestJettyPojoInOutTest.java      | 55 ++++++++++++++++++++
 .../camel/component/jetty/rest/UserPojo.java    | 40 ++++++++++++++
 .../camel/component/jetty/rest/UserService.java | 33 ++++++++++++
 5 files changed, 179 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b1e23971/components/camel-jetty/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-jetty/pom.xml b/components/camel-jetty/pom.xml
index be65b67..d23486d 100644
--- a/components/camel-jetty/pom.xml
+++ b/components/camel-jetty/pom.xml
@@ -103,6 +103,17 @@
             <optional>true</optional>
             <scope>test</scope>
         </dependency>
+        <!-- for testing rest-dsl -->
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-jackson</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-jaxb</artifactId>
+          <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/camel/blob/b1e23971/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java
new file mode 100644
index 0000000..022da99
--- /dev/null
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.jetty.rest;
+
+public class CountryPojo {
+
+    private String iso;
+    private String country;
+
+    public String getIso() {
+        return iso;
+    }
+
+    public void setIso(String iso) {
+        this.iso = iso;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b1e23971/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
new file mode 100644
index 0000000..7d3c6fa
--- /dev/null
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.jetty.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore
+public class RestJettyPojoInOutTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyPojoInOut() throws Exception {
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        String out = template.requestBody("http://localhost:"; + getPort() + 
"/users/lives", body, String.class);
+
+        assertNotNull(out);
+        assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use restlet on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    
.post("lives").type(UserPojo.class).outType(CountryPojo.class)
+                        .route()
+                        .bean(new UserService(), "livesWhere");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b1e23971/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java
new file mode 100644
index 0000000..caf65e7
--- /dev/null
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.jetty.rest;
+
+public class UserPojo {
+
+    private int id;
+    private String name;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b1e23971/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserService.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserService.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserService.java
new file mode 100644
index 0000000..7665b40
--- /dev/null
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/UserService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.jetty.rest;
+
+public class UserService {
+
+    public CountryPojo livesWhere(UserPojo user) {
+        CountryPojo answer = new CountryPojo();
+        if (user.getId() < 500) {
+            answer.setIso("EN");
+            answer.setCountry("England");
+        } else {
+            answer.setIso("SE");
+            answer.setCountry("Sweden");
+        }
+        return answer;
+    }
+
+}

Reply via email to