camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject camel git commit: [CAMEL-8645] Camel Netty component should not intercept consumers with httpMethodRestrict=OPTIONS. Thanks for @stijnvanbael for the patch! (cherry picked from commit ca1aaa1)
Date Thu, 16 Apr 2015 10:09:43 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x ff554c053 -> bb59db2d8


[CAMEL-8645] Camel Netty component should not intercept consumers with httpMethodRestrict=OPTIONS.
Thanks for @stijnvanbael for the patch!
(cherry picked from commit ca1aaa1)


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

Branch: refs/heads/camel-2.15.x
Commit: bb59db2d81af634364bb9a3f09c2745565d114c3
Parents: ff554c0
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Thu Apr 16 12:02:50 2015 +0200
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Thu Apr 16 12:09:29 2015 +0200

----------------------------------------------------------------------
 .../http/handlers/HttpServerChannelHandler.java |  4 +-
 .../netty/http/NettyHttpCustomOptionsTest.java  | 44 ++++++++++++++++++++
 .../http/handlers/HttpServerChannelHandler.java |  4 +-
 .../netty4/http/NettyHttpCustomOptionsTest.java | 44 ++++++++++++++++++++
 4 files changed, 94 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bb59db2d/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
index 4888b8c..cd6dfed 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
@@ -94,7 +94,9 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
         }
 
         // if its an OPTIONS request then return which methods is allowed
-        if ("OPTIONS".equals(request.getMethod().getName())) {
+        boolean isRestrictedToOptions = consumer.getEndpoint().getHttpMethodRestrict() !=
null
+                && consumer.getEndpoint().getHttpMethodRestrict().contains("OPTIONS");
+        if ("OPTIONS".equals(request.getMethod().getName()) && !isRestrictedToOptions)
{
             String s;
             if (consumer.getEndpoint().getHttpMethodRestrict() != null) {
                 s = "OPTIONS," + consumer.getEndpoint().getHttpMethodRestrict();

http://git-wip-us.apache.org/repos/asf/camel/blob/bb59db2d/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCustomOptionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCustomOptionsTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCustomOptionsTest.java
new file mode 100644
index 0000000..0e2bb06
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCustomOptionsTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+import static org.apache.camel.Exchange.HTTP_METHOD;
+
+public class NettyHttpCustomOptionsTest extends BaseNettyTest {
+
+    String expectedResponse = "response";
+
+    @Test
+    public void shouldReturnCustomResponseForOptions() throws Exception {
+        String response = template.requestBodyAndHeader("netty-http:http://localhost:{{port}}/foo",
"", HTTP_METHOD, "OPTIONS", String.class);
+        assertEquals(expectedResponse, response);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty-http:http://0.0.0.0:{{port}}/foo?httpMethodRestrict=OPTIONS").setBody().constant(expectedResponse);
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/bb59db2d/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
index 9645dc0..548de46 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
@@ -88,7 +88,9 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
         }
 
         // if its an OPTIONS request then return which methods is allowed
-        if ("OPTIONS".equals(request.getMethod().name())) {
+        boolean isRestrictedToOptions = consumer.getEndpoint().getHttpMethodRestrict() !=
null
+                && consumer.getEndpoint().getHttpMethodRestrict().contains("OPTIONS");
+        if ("OPTIONS".equals(request.getMethod().name()) && !isRestrictedToOptions)
{
             String s;
             if (consumer.getEndpoint().getHttpMethodRestrict() != null) {
                 s = "OPTIONS," + consumer.getEndpoint().getHttpMethodRestrict();

http://git-wip-us.apache.org/repos/asf/camel/blob/bb59db2d/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpCustomOptionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpCustomOptionsTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpCustomOptionsTest.java
new file mode 100644
index 0000000..d976625
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpCustomOptionsTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+import static org.apache.camel.Exchange.HTTP_METHOD;
+
+public class NettyHttpCustomOptionsTest extends BaseNettyTest {
+
+    String expectedResponse = "response";
+
+    @Test
+    public void shouldReturnCustomResponseForOptions() throws Exception {
+        String response = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo",
"", HTTP_METHOD, "OPTIONS", String.class);
+        assertEquals(expectedResponse, response);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty4-http:http://0.0.0.0:{{port}}/foo?httpMethodRestrict=OPTIONS").setBody().constant(expectedResponse);
+            }
+        };
+    }
+
+}


Mime
View raw message