camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-7619: Rest DSL - adding support for xml/json binding using Camel's data formats. Work in progress.
Date Wed, 23 Jul 2014 15:38:09 GMT
CAMEL-7619: Rest DSL - adding support for xml/json binding using Camel's data formats. 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/4669b172
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4669b172
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4669b172

Branch: refs/heads/master
Commit: 4669b1723e7e600f6b11bdec463db24a6d603b03
Parents: 6879385
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 23 15:59:36 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jul 23 17:37:59 2014 +0200

----------------------------------------------------------------------
 .../org/apache/camel/model/rest/RestDefinition.java | 16 ++++++++++++++--
 .../org/apache/camel/model/rest/VerbDefinition.java | 11 +++++++++++
 .../camel/component/rest/FromRestGetTest.java       |  3 ++-
 .../camel/management/ManagedFromRestGetTest.java    |  4 +++-
 .../camel/component/rest/SpringFromRestGetTest.xml  |  2 +-
 .../blueprint/component/rest/FromRestGetTest.java   |  1 +
 .../blueprint/component/rest/FromRestGetTest.xml    |  2 +-
 7 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/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 c163a1b..2c3c4b5 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
@@ -119,14 +119,26 @@ public class RestDefinition {
         return addVerb(verb, uri);
     }
 
-    public RestDefinition consumes(String accept) {
+    public RestDefinition consumes(String mediaType) {
         // add to last verb
         if (getVerbs().isEmpty()) {
             throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
         }
 
         VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
-        verb.setConsumes(accept);
+        verb.setConsumes(mediaType);
+
+        return this;
+    }
+
+    public RestDefinition produces(String mediaType) {
+        // add to last verb
+        if (getVerbs().isEmpty()) {
+            throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+        }
+
+        VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+        verb.setProduces(mediaType);
 
         return this;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/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 6dda444..4f7ebd3 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
@@ -42,6 +42,9 @@ public class VerbDefinition {
     private String consumes;
 
     @XmlAttribute
+    private String produces;
+
+    @XmlAttribute
     private String type;
 
     @XmlAttribute
@@ -93,6 +96,14 @@ public class VerbDefinition {
         this.consumes = consumes;
     }
 
+    public String getProduces() {
+        return produces;
+    }
+
+    public void setProduces(String produces) {
+        this.produces = produces;
+    }
+
     public String getType() {
         return type;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 02864db..3a2e16d 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
@@ -51,6 +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());
+        assertEquals("application/xml", rest.getVerbs().get(0).getProduces());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:bye", to.getUri());
 
@@ -74,7 +75,7 @@ public class FromRestGetTest extends ContextTestSupport {
                     .get().to("direct:hello");
 
                 rest("/say/bye")
-                    .get().consumes("application/json").to("direct:bye")
+                    .get().consumes("application/json").produces("application/xml").to("direct:bye")
                     .post().to("mock:update");
 
                 from("direct:hello")

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/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 651359b..8de5c23 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
@@ -53,6 +53,8 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
         assertTrue(xml.contains("<rest uri=\"/say/bye\">"));
         assertTrue(xml.contains("</rest>"));
         assertTrue(xml.contains("<get>"));
+        assertTrue(xml.contains("application/json"));
+        assertTrue(xml.contains("application/xml"));
         assertTrue(xml.contains("<post>"));
         assertTrue(xml.contains("application/json"));
         assertTrue(xml.contains("</rests>"));
@@ -75,7 +77,7 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
                     .get().to("direct:hello");
 
                 rest("/say/bye")
-                    .get().consumes("application/json").to("direct:bye")
+                    .get().consumes("application/json").produces("application/xml").to("direct:bye")
                     .post().to("mock:update");
 
                 from("direct:hello")

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 4fa30ec..d176889 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -33,7 +33,7 @@
       </get>
     </rest>
     <rest uri="/say/bye">
-      <get consumes="application/json">
+      <get consumes="application/json" produces="application/json">
         <to uri="direct:bye"/>
       </get>
       <post>

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 68f1547..44cdddc 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
@@ -49,6 +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());
+        assertEquals("application/json", rest.getVerbs().get(0).getProduces());
         to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
         assertEquals("direct:bye", to.getUri());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4669b172/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index 578ed92..7d566b1 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -31,7 +31,7 @@
       </get>
     </rest>
     <rest uri="/say/bye">
-      <get consumes="application/json">
+      <get consumes="application/json" produces="application/json">
         <to uri="direct:bye"/>
       </get>
       <post>


Mime
View raw message