CAMEL-11624: rest-dsl producer should use upper-case HTTP verb.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/85f143e4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/85f143e4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/85f143e4 Branch: refs/heads/master Commit: 85f143e4f0fc88a1db0c1da422af14945475620e Parents: ea3b6be Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Sep 8 14:58:39 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Sep 8 15:32:58 2017 +0200 ---------------------------------------------------------------------- .../camel/component/rest/RestProducer.java | 8 ++- .../JettyRestProducerVerbUpperCaseTest.java | 62 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/85f143e4/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java index bbdc476..0da7ab4 100644 --- a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java +++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java @@ -21,6 +21,7 @@ import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import javax.xml.bind.JAXBContext; @@ -200,15 +201,16 @@ public class RestProducer extends DefaultAsyncProducer { // HTTP_PATH header will be present, we remove it here // as the REST_HTTP_URI contains the full URI for the // request and every other HTTP producer will concatenate - // REST_HTTP_URI with HTTP_PATH resulting in incorrect - // URIs + // REST_HTTP_URI with HTTP_PATH resulting in incorrect URIs inMessage.removeHeader(Exchange.HTTP_PATH); } // method String method = getEndpoint().getMethod(); if (method != null) { - inMessage.setHeader(Exchange.HTTP_METHOD, method); + // the method should be in upper case + String upper = method.toUpperCase(Locale.US); + inMessage.setHeader(Exchange.HTTP_METHOD, upper); } final String produces = getEndpoint().getProduces(); http://git-wip-us.apache.org/repos/asf/camel/blob/85f143e4/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerVerbUpperCaseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerVerbUpperCaseTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerVerbUpperCaseTest.java new file mode 100644 index 0000000..33dd973 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerVerbUpperCaseTest.java @@ -0,0 +1,62 @@ +/** + * 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.jetty.rest.producer; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +public class JettyRestProducerVerbUpperCaseTest extends BaseJettyTest { + + @Test + public void testVerbUpperCase() throws Exception { + String out = fluentTemplate.withHeader("id", "123").to("direct:start").request(String.class); + assertEquals("123;Donald Duck", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use localhost with the given port + restConfiguration().component("jetty").host("localhost").port(getPort()); + + from("direct:start") + .to("rest:get:users/{id}/basic"); + + // use the rest DSL to define the rest services + rest("/users/") + .get("{id}/basic") + .route() + .to("mock:input") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String method = exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class); + assertEquals("GET", method); + + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }); + } + }; + } + +}