camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-8734: camel-netty-http should do context-path matching case insensitive.
Date Fri, 17 Jul 2015 09:07:11 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 9f26e12a6 -> d83aea2b1


CAMEL-8734: camel-netty-http should do context-path matching case insensitive.


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

Branch: refs/heads/camel-2.15.x
Commit: d83aea2b12b17786cd33ab9f1959072fc10759f7
Parents: 9f26e12
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jul 17 11:03:58 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jul 17 11:10:36 2015 +0200

----------------------------------------------------------------------
 .../netty/http/DefaultNettyHttpBinding.java     |  9 +++-
 .../http/handlers/HttpServerChannelHandler.java | 10 ++++-
 .../netty/http/NettyProxyMixedCasePathTest.java | 44 ++++++++++++++++++++
 .../netty4/http/DefaultNettyHttpBinding.java    |  9 +++-
 .../http/handlers/HttpServerChannelHandler.java |  8 +++-
 .../http/NettyProxyMixedCasePathTest.java       | 44 ++++++++++++++++++++
 6 files changed, 117 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index bbdbfc3..f451e67 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -133,8 +133,13 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable
{
 
         // strip the starting endpoint path so the path is relative to the endpoint uri
         String path = uri.getPath();
-        if (configuration.getPath() != null && path.startsWith(configuration.getPath()))
{
-            path = path.substring(configuration.getPath().length());
+        if (path != null) {
+            // need to match by lower case as we want to ignore case on context-path
+            path = path.toLowerCase(Locale.US);
+            String match = configuration.getPath() != null ? configuration.getPath().toLowerCase(Locale.US)
: null;
+            if (match != null && path.startsWith(match)) {
+                path = path.substring(configuration.getPath().length());
+            }
         }
         headers.put(Exchange.HTTP_PATH, path);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/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 cd6dfed..7c46bec 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
@@ -20,6 +20,7 @@ import java.net.URI;
 import java.nio.channels.ClosedChannelException;
 import java.nio.charset.Charset;
 import java.util.Iterator;
+import java.util.Locale;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
@@ -161,8 +162,13 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
 
             // strip the starting endpoint path so the target is relative to the endpoint
uri
             String path = consumer.getConfiguration().getPath();
-            if (path != null && target.startsWith(path)) {
-                target = target.substring(path.length());
+            if (path != null) {
+                // need to match by lower case as we want to ignore case on context-path
+                path = path.toLowerCase(Locale.US);
+                String match = target.toLowerCase(Locale.US);
+                if (match.startsWith(path)) {
+                    target = target.substring(path.length());
+                }
             }
 
             // is it a restricted resource?

http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyProxyMixedCasePathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyProxyMixedCasePathTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyProxyMixedCasePathTest.java
new file mode 100644
index 0000000..4aaf0d9
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyProxyMixedCasePathTest.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;
+
+public class NettyProxyMixedCasePathTest extends BaseNettyTest {
+
+    @Test
+    public void testMixedCase() throws Exception {
+        String out = template.requestBody("netty-http:http://0.0.0.0:{{port}}/Shopping",
"Camel", String.class);
+        assertEquals("Bye Camel", out);
+
+        out = template.requestBody("netty-http:http://0.0.0.0:{{port}}/shopping", "World",
String.class);
+        assertEquals("Bye World", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty-http:http://0.0.0.0:{{port}}/Shopping").to("netty-http:http://0.0.0.0:{{port}}/ws/svc/Shopping");
+
+                from("netty-http:http://0.0.0.0:{{port}}/ws/svc/Shopping").transform(body().prepend("Bye
"));
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
index 29f6bdf..3a0c2c9 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
@@ -135,8 +135,13 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable
{
 
         // strip the starting endpoint path so the path is relative to the endpoint uri
         String path = uri.getPath();
-        if (configuration.getPath() != null && path.startsWith(configuration.getPath()))
{
-            path = path.substring(configuration.getPath().length());
+        if (configuration.getPath() != null) {
+            // need to match by lower case as we want to ignore case on context-path
+            path = path.toLowerCase(Locale.US);
+            String match = configuration.getPath() != null ? configuration.getPath().toLowerCase(Locale.US)
: null;
+            if (match != null && path.startsWith(match)) {
+                path = path.substring(configuration.getPath().length());
+            }
         }
         headers.put(Exchange.HTTP_PATH, path);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/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 548de46..4cb610f 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
@@ -20,6 +20,7 @@ import java.net.URI;
 import java.nio.channels.ClosedChannelException;
 import java.nio.charset.Charset;
 import java.util.Iterator;
+import java.util.Locale;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
@@ -150,7 +151,12 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
             // strip the starting endpoint path so the target is relative to the endpoint
uri
             String path = consumer.getConfiguration().getPath();
             if (path != null && target.startsWith(path)) {
-                target = target.substring(path.length());
+                // need to match by lower case as we want to ignore case on context-path
+                path = path.toLowerCase(Locale.US);
+                String match = target.toLowerCase(Locale.US);
+                if (match.startsWith(path)) {
+                    target = target.substring(path.length());
+                }
             }
 
             // is it a restricted resource?

http://git-wip-us.apache.org/repos/asf/camel/blob/d83aea2b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyProxyMixedCasePathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyProxyMixedCasePathTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyProxyMixedCasePathTest.java
new file mode 100644
index 0000000..f4cbfa7
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyProxyMixedCasePathTest.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;
+
+public class NettyProxyMixedCasePathTest extends BaseNettyTest {
+
+    @Test
+    public void testMixedCase() throws Exception {
+        String out = template.requestBody("netty4-http:http://0.0.0.0:{{port}}/Shopping",
"Camel", String.class);
+        assertEquals("Bye Camel", out);
+
+        out = template.requestBody("netty4-http:http://0.0.0.0:{{port}}/shopping", "World",
String.class);
+        assertEquals("Bye World", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty4-http:http://0.0.0.0:{{port}}/Shopping").to("netty4-http:http://0.0.0.0:{{port}}/ws/svc/Shopping");
+
+                from("netty4-http:http://0.0.0.0:{{port}}/ws/svc/Shopping").transform(body().prepend("Bye
"));
+            }
+        };
+    }
+}
\ No newline at end of file


Mime
View raw message