camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [7/9] camel git commit: CAMEL-11624: rest-dsl producer should use upper-case HTTP verb.
Date Fri, 08 Sep 2017 13:34:37 GMT
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/7b8bb3dc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7b8bb3dc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7b8bb3dc

Branch: refs/heads/camel-2.19.x
Commit: 7b8bb3dc5a742b46998c9788f6c253f5e05547a4
Parents: 062016e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Sep 8 14:58:39 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 8 15:33:31 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/7b8bb3dc/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/7b8bb3dc/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");
+                            }
+                        });
+            }
+        };
+    }
+
+}


Mime
View raw message