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/3580582d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3580582d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3580582d Branch: refs/remotes/origin/camel-2.13.x Commit: 3580582d42358ec073c6d7bf7bdcf59420052b9f Parents: d843918 Author: Willem Jiang <[email protected]> Authored: Wed Oct 8 22:16:39 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Thu Oct 9 10:32:49 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/3580582d/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/3580582d/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/3580582d/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"); + } + }); + } + }; + } +}
