Repository: camel
Updated Branches:
  refs/heads/master d58fd1107 -> 09bd4db06


CAMEL-7354: Rest DSL. Integrate with camel-netty-http.


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

Branch: refs/heads/master
Commit: 09bd4db06266265f5a9bd8834a3219fe48338514
Parents: 248f8cd
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Jul 29 10:09:19 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Jul 29 10:12:10 2014 +0200

----------------------------------------------------------------------
 .../RestJettyBindingModeAutoWithJsonTest.java   |  2 +-
 components/camel-netty-http/pom.xml             | 11 +++
 .../component/netty/http/rest/CountryPojo.java  | 40 ++++++++++
 ...estNettyHttpBindingModeAutoWithJsonTest.java | 59 +++++++++++++++
 ...RestNettyHttpBindingModeAutoWithXmlTest.java | 59 +++++++++++++++
 .../rest/RestNettyHttpBindingModeJsonTest.java  | 76 +++++++++++++++++++
 .../rest/RestNettyHttpBindingModeXmlTest.java   | 77 +++++++++++++++++++
 .../http/rest/RestNettyHttpPojoInOutTest.java   | 55 ++++++++++++++
 .../rest/RestNettyHttpPostJsonJaxbPojoTest.java | 63 ++++++++++++++++
 .../rest/RestNettyHttpPostJsonPojoListTest.java | 68 +++++++++++++++++
 .../rest/RestNettyHttpPostJsonPojoTest.java     | 63 ++++++++++++++++
 .../rest/RestNettyHttpPostXmlJaxbPojoTest.java  | 79 ++++++++++++++++++++
 .../component/netty/http/rest/UserJaxbPojo.java | 48 ++++++++++++
 .../component/netty/http/rest/UserPojo.java     | 40 ++++++++++
 .../component/netty/http/rest/UserService.java  | 33 ++++++++
 15 files changed, 772 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java
index c4fb469..43ec8f3 100644
--- 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java
@@ -50,7 +50,7 @@ public class RestJettyBindingModeAutoWithJsonTest extends 
BaseJettyTest {
 
                 // use the rest DSL to define the rest services
                 rest("/users/")
-                        
.post("new").consumes("application/json").type(UserPojo.class)
+                    
.post("new").consumes("application/json").type(UserPojo.class)
                         .to("mock:input");
             }
         };

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/pom.xml 
b/components/camel-netty-http/pom.xml
index 8eb6962..6e56b2d 100644
--- a/components/camel-netty-http/pom.xml
+++ b/components/camel-netty-http/pom.xml
@@ -57,6 +57,17 @@
                        <artifactId>junit</artifactId>
                        <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>
 
                <!-- logging -->
                <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/CountryPojo.java
new file mode 100644
index 0000000..99d41fe
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/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.netty.http.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/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
new file mode 100644
index 0000000..006a69f
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.netty.http.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpBindingModeAutoWithJsonTest extends BaseNettyTest {
+
+    @Test
+    public void testBindingMode() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserPojo.class);
+
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    
.post("new").consumes("application/json").type(UserPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithXmlTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithXmlTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithXmlTest.java
new file mode 100644
index 0000000..0381a0b
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeAutoWithXmlTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.netty.http.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpBindingModeAutoWithXmlTest extends BaseNettyTest {
+
+    @Test
+    public void testBindingMode() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    
.post("new").consumes("application/xml").type(UserJaxbPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
new file mode 100644
index 0000000..aff2610
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.netty.http.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpBindingModeJsonTest extends BaseNettyTest {
+
+    @Test
+    public void testBindingMode() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Test
+    public void testBindingModeWrong() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(0);
+
+        // we bind to json, but send in xml, which is not possible
+        String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+        try {
+            template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+            fail("Should have thrown exception");
+        } catch (Exception e) {
+            // expected
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.json);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").type(UserJaxbPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
new file mode 100644
index 0000000..5fd5ae7
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.netty.http.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpBindingModeXmlTest extends BaseNettyTest {
+
+    @Test
+    public void testBindingMode() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Test
+    public void testBindingModeWrong() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(0);
+
+        // we bind to xml, but send in json, which is not possible
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        try {
+            template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+            fail("Should have thrown exception");
+        } catch (Exception e) {
+            // expected
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.xml);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").type(UserJaxbPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
new file mode 100644
index 0000000..06f4c28
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.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.netty.http.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
+
+    @Test
+    public void testJettyPojoInOut() throws Exception {
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        String out = template.requestBody("netty-http: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 netty-http on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("netty-http").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/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonJaxbPojoTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonJaxbPojoTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonJaxbPojoTest.java
new file mode 100644
index 0000000..7f7b53b
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonJaxbPojoTest.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.component.netty.http.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpPostJsonJaxbPojoTest extends BaseNettyTest {
+
+    @Test
+    public void testPostJaxbPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty-http on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").type(UserJaxbPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoListTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoListTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoListTest.java
new file mode 100644
index 0000000..2acd377
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoListTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.netty.http.rest;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpPostJsonPojoListTest extends BaseNettyTest {
+
+    @Test
+    public void testPostPojoList() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+
+        String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 
456, \"name\": \"John Doe\"} ]";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        List list = 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(list);
+        assertEquals(2, list.size());
+
+        UserPojo user = (UserPojo) list.get(0);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+        user = (UserPojo) list.get(1);
+        assertEquals(456, user.getId());
+        assertEquals("John Doe", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty-http on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").typeList(UserPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoTest.java
new file mode 100644
index 0000000..89774a0
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostJsonPojoTest.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.component.netty.http.rest;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpPostJsonPojoTest extends BaseNettyTest {
+
+    @Test
+    public void testPostPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserPojo.class);
+
+        String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty-http on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").type(UserPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostXmlJaxbPojoTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostXmlJaxbPojoTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostXmlJaxbPojoTest.java
new file mode 100644
index 0000000..53c2c0e
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPostXmlJaxbPojoTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.netty.http.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpPostXmlJaxbPojoTest extends BaseNettyTest {
+
+    @Test
+    public void testPostJaxbPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+        template.sendBodyAndHeader("netty-http:http://localhost:"; + getPort() 
+ "/users/new", body, Exchange.CONTENT_TYPE, "text/xml");
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(123, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Test
+    public void testPostJaxbPojoNoContentType() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+        String body = "<user name=\"Donald Duck\" id=\"456\"></user>";
+        template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
+
+        assertMockEndpointsSatisfied();
+
+        UserJaxbPojo user = 
mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+        assertNotNull(user);
+        assertEquals(456, user.getId());
+        assertEquals("Donald Duck", user.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty-http on localhost with the given port
+                // and enable auto binding mode
+                
restConfiguration().component("netty-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .post("new").type(UserJaxbPojo.class)
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserJaxbPojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserJaxbPojo.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserJaxbPojo.java
new file mode 100644
index 0000000..5afbef7
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserJaxbPojo.java
@@ -0,0 +1,48 @@
+/**
+ * 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.netty.http.rest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "user")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class UserJaxbPojo {
+
+    @XmlAttribute
+    private int id;
+    @XmlAttribute
+    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/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserPojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserPojo.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserPojo.java
new file mode 100644
index 0000000..ac9782d
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/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.netty.http.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/09bd4db0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserService.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserService.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/UserService.java
new file mode 100644
index 0000000..6b209a7
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/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.netty.http.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