Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x bd83484f9 -> be0558d40
  refs/heads/master 4c1e05f80 -> 015f6e290


CAMEL-11293: Fixed rest-dsl producer to use HTTP verb/method from uri when 
calling remote REST service.


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

Branch: refs/heads/master
Commit: 015f6e2905b7282aa0fc33a5b5065f106526241d
Parents: 4c1e05f
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue May 23 14:12:29 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue May 23 14:12:29 2017 +0200

----------------------------------------------------------------------
 .../camel/component/rest/RestProducer.java      |  6 +++
 .../rest/producer/Http4RestProducerPutTest.java | 53 +++++++++++++++++++
 .../rest/producer/HttpRestProducerPutTest.java  | 53 +++++++++++++++++++
 .../rest/producer/JettyRestProducerPutTest.java | 53 +++++++++++++++++++
 .../component/netty4/http/NettyHttpHelper.java  |  2 +
 .../http/rest/RestNettyProducerPutTest.java     | 53 +++++++++++++++++++
 .../restlet/RestletRestProducerPutTest.java     | 55 ++++++++++++++++++++
 .../component/undertow/UndertowHelper.java      |  2 +
 .../rest/RestUndertowProducerPutTest.java       | 53 +++++++++++++++++++
 9 files changed, 330 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/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 860308c..bbdc476 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
@@ -205,6 +205,12 @@ public class RestProducer extends DefaultAsyncProducer {
             inMessage.removeHeader(Exchange.HTTP_PATH);
         }
 
+        // method
+        String method = getEndpoint().getMethod();
+        if (method != null) {
+            inMessage.setHeader(Exchange.HTTP_METHOD, method);
+        }
+
         final String produces = getEndpoint().getProduces();
         if (isEmpty(inMessage.getHeader(Exchange.CONTENT_TYPE)) && 
isNotEmpty(produces)) {
             inMessage.setHeader(Exchange.CONTENT_TYPE, produces);

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/Http4RestProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/Http4RestProducerPutTest.java
 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/Http4RestProducerPutTest.java
new file mode 100644
index 0000000..e06792d
--- /dev/null
+++ 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/Http4RestProducerPutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+public class Http4RestProducerPutTest extends BaseJettyTest {
+
+    @Test
+    public void testHttp4ProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use localhost with the given port
+                
restConfiguration().producerComponent("http4").component("jetty").host("localhost").port(getPort());
+
+                from("direct:start")
+                        .to("rest:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/HttpRestProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/HttpRestProducerPutTest.java
 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/HttpRestProducerPutTest.java
new file mode 100644
index 0000000..79f18c7
--- /dev/null
+++ 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/HttpRestProducerPutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+public class HttpRestProducerPutTest extends BaseJettyTest {
+
+    @Test
+    public void testHttpProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use localhost with the given port
+                
restConfiguration().producerComponent("http").component("jetty").host("localhost").port(getPort());
+
+                from("direct:start")
+                        .to("rest:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerPutTest.java
 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerPutTest.java
new file mode 100644
index 0000000..0b23bb1
--- /dev/null
+++ 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerPutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+public class JettyRestProducerPutTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @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:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                        .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java
index 3dc8d7e..937cc9c 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java
@@ -110,6 +110,8 @@ public final class NettyHttpHelper {
         }
         String name = message.getHeader(Exchange.HTTP_METHOD, String.class);
         if (name != null) {
+            // must be in upper case
+            name = name.toUpperCase();
             return HttpMethod.valueOf(name);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerPutTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerPutTest.java
new file mode 100644
index 0000000..3de008e
--- /dev/null
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerPutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.netty4.http.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty4.http.BaseNettyTest;
+import org.junit.Test;
+
+public class RestNettyProducerPutTest extends BaseNettyTest {
+
+    @Test
+    public void testNettyProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @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("netty4-http").host("localhost").port(getPort());
+
+                from("direct:start")
+                    .to("rest:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                    .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRestProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRestProducerPutTest.java
 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRestProducerPutTest.java
new file mode 100644
index 0000000..fe3dc5b
--- /dev/null
+++ 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletRestProducerPutTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class RestletRestProducerPutTest extends RestletTestSupport {
+
+    @Test
+    public void testRestletProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @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("restlet").host("localhost").port(portNum);
+
+                from("direct:start")
+                    .to("rest:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                    .to("mock:input");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java
----------------------------------------------------------------------
diff --git 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java
 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java
index 3500cae..cd8ff73 100644
--- 
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java
+++ 
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHelper.java
@@ -157,6 +157,8 @@ public final class UndertowHelper {
         String m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, 
String.class);
         if (m != null) {
             // always use what end-user provides in a header
+            // must be in upper case
+            m = m.toUpperCase();
             answer = new HttpString(m);
         } else if (queryString != null) {
             // if a query string is provided then use GET

http://git-wip-us.apache.org/repos/asf/camel/blob/015f6e29/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerPutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerPutTest.java
 
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerPutTest.java
new file mode 100644
index 0000000..021a5ad
--- /dev/null
+++ 
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerPutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.junit.Test;
+
+public class RestUndertowProducerPutTest extends BaseUndertowTest {
+
+    @Test
+    public void testUndertowProducerPut() throws Exception {
+        getMockEndpoint("mock:input").expectedMessageCount(1);
+
+        fluentTemplate.withBody("Donald Duck").withHeader("id", 
"123").to("direct:start").send();
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @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("undertow").host("localhost").port(getPort());
+
+                from("direct:start")
+                    .to("rest:put:users/{id}");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .put("{id}")
+                    .to("mock:input");
+            }
+        };
+    }
+
+}

Reply via email to