This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.23.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.23.x by this push: new 650c090 CAMEL-13022: camel-restlet - sending PATCH operation should include body 650c090 is described below commit 650c090eb4888caacbd2906fe0bff2a99e86a6a6 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Dec 20 14:38:07 2018 +0100 CAMEL-13022: camel-restlet - sending PATCH operation should include body --- .../component/restlet/DefaultRestletBinding.java | 4 +- .../restlet/RestletProducerPatchTest.java | 50 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) 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 195e394..5b759f5 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 @@ -286,8 +286,8 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate request.setEntity(form.getWebRepresentation()); LOG.debug("Populate Restlet {} request from exchange body as form using media type {}", method, mediaType); } else { - // include body if PUT or POST - if (request.getMethod().equals(Method.PUT) || request.getMethod().equals(Method.POST)) { + // include body if PUT, POST or PATCH + if (request.getMethod().equals(Method.PUT) || request.getMethod().equals(Method.POST) || request.getMethod().equals(Method.PATCH)) { Representation body = createRepresentationFromBody(exchange, mediaType); request.setEntity(body); LOG.debug("Populate Restlet {} request from exchange body: {} using media type {}", method, body, mediaType); diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerPatchTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerPatchTest.java new file mode 100644 index 0000000..2099501 --- /dev/null +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerPatchTest.java @@ -0,0 +1,50 @@ +/** + * 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; + +public class RestletProducerPatchTest extends RestletTestSupport { + + @Test + public void testRestletProducerPatch() throws Exception { + String out = template.requestBodyAndHeader("direct:patch", "Donald Duck", "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:patch").to("restlet:http://localhost:" + portNum + "/users/{id}/basic?restletMethod=PATCH"); + + from("restlet:http://localhost:" + portNum + "/users/{id}/basic?restletMethods=PATCH") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + Object body = exchange.getIn().getBody(); + exchange.getOut().setBody(id + ";" + body); + } + }); + } + }; + } +}