You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2015/04/16 12:02:57 UTC
camel git commit: [CAMEL-8645] Camel Netty component should not
intercept consumers with httpMethodRestrict=OPTIONS. Thanks for @stijnvanbael
for the patch!
Repository: camel
Updated Branches:
refs/heads/master 1b99e8c53 -> ca1aaa1b2
[CAMEL-8645] Camel Netty component should not intercept consumers with httpMethodRestrict=OPTIONS. Thanks for @stijnvanbael for the patch!
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ca1aaa1b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ca1aaa1b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ca1aaa1b
Branch: refs/heads/master
Commit: ca1aaa1b292ac7275853f2f27e6c5f7d5de618ac
Parents: 1b99e8c
Author: Henryk Konsek <he...@gmail.com>
Authored: Thu Apr 16 12:02:50 2015 +0200
Committer: Henryk Konsek <he...@gmail.com>
Committed: Thu Apr 16 12:02:50 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/ca1aaa1b/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/ca1aaa1b/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/ca1aaa1b/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/ca1aaa1b/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);
+ }
+ };
+ }
+
+}