You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/09 04:34:09 UTC

[7/7] git commit: CAMEL-7892 Fixed the restlet DELETE with no entity issue

CAMEL-7892 Fixed the restlet DELETE with no entity issue


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

Branch: refs/heads/camel-2.12.x
Commit: 92a87937fa6d1aa79fa0687c96c0b1081397b321
Parents: ce4a939
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Oct 8 22:16:39 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 10:33:37 2014 +0800

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          |  6 +-
 .../restlet/RestletProducerGetTest.java         | 52 -----------------
 .../component/restlet/RestletProducerTest.java  | 60 ++++++++++++++++++++
 3 files changed, 65 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/92a87937/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index cd3d62d..e671749 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -171,7 +171,11 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
             request.setEntity(form.getWebRepresentation());
         } else {
-            request.setEntity(body, mediaType);
+            if (body == null) {
+                request.setEntity(null);
+            } else {
+                request.setEntity(body, mediaType);
+            }
         }
 
         MediaType acceptedMediaType = exchange.getIn().getHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/92a87937/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java
deleted file mode 100644
index 8a81980..0000000
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerGetTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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.restlet;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-/**
- * @version 
- */
-public class RestletProducerGetTest extends RestletTestSupport {
-
-    @Test
-    public void testRestletProducerGet() throws Exception {
-        String out = template.requestBodyAndHeader("direct:start", null, "id", 123, String.class);
-        assertEquals("123;Donald Duck", out);
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").to("restlet:http://localhost:" + portNum + "/users/123/basic").to("log:reply");
-
-                from("restlet:http://localhost:" + portNum + "/users/{id}/basic")
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            String id = exchange.getIn().getHeader("id", String.class);
-                            exchange.getOut().setBody(id + ";Donald Duck");
-                        }
-                    });
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/92a87937/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerTest.java
new file mode 100644
index 0000000..4ea65b6
--- /dev/null
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.restlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class RestletProducerTest extends RestletTestSupport {
+
+    @Test
+    public void testRestletProducerGet() throws Exception {
+        String out = template.requestBodyAndHeader("direct:start", null, "id", 123, String.class);
+        assertEquals("123;Donald Duck", out);
+    }
+    
+    @Test
+    public void testRestletProducerDelete() throws Exception {
+        String out = template.requestBodyAndHeader("direct:delete", null, "id", 123, String.class);
+        assertEquals("123;Donald Duck", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("restlet:http://localhost:" + portNum + "/users/123/basic").to("log:reply");
+                
+                from("direct:delete").to("restlet:http://localhost:" + portNum + "/users/123/basic?restletMethod=DELETE");
+
+                from("restlet:http://localhost:" + portNum + "/users/{id}/basic?restletMethods=GET,DELETE")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            String id = exchange.getIn().getHeader("id", String.class);
+                            exchange.getOut().setBody(id + ";Donald Duck");
+                        }
+                    });
+            }
+        };
+    }
+}