You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by ti...@apache.org on 2017/03/14 22:31:19 UTC

asterixdb git commit: HttpServer path matching fixes

Repository: asterixdb
Updated Branches:
  refs/heads/master a23fac154 -> 2e03fd673


HttpServer path matching fixes

Change-Id: I1429629210c16fc73d2a9e3d8c01e00d30de0c66
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1581
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <ba...@gmail.com>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>


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

Branch: refs/heads/master
Commit: 2e03fd673a5ca2100b52c07aff0434fafe6aa9ce
Parents: a23fac1
Author: Till Westmann <ti...@apache.org>
Authored: Tue Mar 14 14:12:22 2017 -0700
Committer: Till Westmann <ti...@apache.org>
Committed: Tue Mar 14 15:31:01 2017 -0700

----------------------------------------------------------------------
 .../apache/hyracks/http/server/HttpServer.java  | 24 +++++++-----
 .../hyracks/http/server/PathMatchTest.java      | 41 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2e03fd67/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServer.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServer.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServer.java
index 74361b8..cdfc492 100644
--- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServer.java
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/HttpServer.java
@@ -218,23 +218,23 @@ public class HttpServer {
         if (i >= 0) {
             uri = uri.substring(0, i);
         }
-        for (IServlet let : servlets) {
-            for (String path : let.getPaths()) {
+        for (IServlet servlet : servlets) {
+            for (String path : servlet.getPaths()) {
                 if (match(path, uri)) {
-                    return let;
+                    return servlet;
                 }
             }
         }
+        LOGGER.warning("No servlet for " + uri);
         return null;
     }
 
-    private static boolean match(String pathSpec, String path) {
+    static boolean match(String pathSpec, String path) {
         char c = pathSpec.charAt(0);
         if (c == '/') {
-            if (pathSpec.length() == 1 || pathSpec.equals(path)) {
+            if (pathSpec.equals(path) || (pathSpec.length() == 1 && path.isEmpty())) {
                 return true;
             }
-
             if (isPathWildcardMatch(pathSpec, path)) {
                 return true;
             }
@@ -244,10 +244,14 @@ public class HttpServer {
         return false;
     }
 
-    private static boolean isPathWildcardMatch(String pathSpec, String path) {
-        int cpl = pathSpec.length() - 2;
-        return (pathSpec.endsWith("/*") && path.regionMatches(0, pathSpec, 0, cpl))
-                && (path.length() == cpl || '/' == path.charAt(cpl));
+    static boolean isPathWildcardMatch(String pathSpec, String path) {
+        final int length = pathSpec.length();
+        if (length < 2) {
+            return false;
+        }
+        final int cpl = length - 2;
+        final boolean b = pathSpec.endsWith("/*") && path.regionMatches(0, pathSpec, 0, cpl);
+        return b && (path.length() == cpl || '/' == path.charAt(cpl));
     }
 
     public ExecutorService getExecutor() {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2e03fd67/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/server/PathMatchTest.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/server/PathMatchTest.java b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/server/PathMatchTest.java
new file mode 100644
index 0000000..89260c5
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-http/src/test/java/org/apache/hyracks/http/server/PathMatchTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.hyracks.http.server;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PathMatchTest {
+    @Test
+    public void test() {
+        Assert.assertTrue(HttpServer.match("/", ""));
+
+        Assert.assertTrue(HttpServer.match("/", "/"));
+        Assert.assertFalse(HttpServer.match("/", "/a"));
+
+        Assert.assertFalse(HttpServer.match("/a", "/"));
+        Assert.assertTrue(HttpServer.match("/a", "/a"));
+
+        Assert.assertTrue(HttpServer.match("/*", "/"));
+        Assert.assertTrue(HttpServer.match("/*", "/a"));
+
+        Assert.assertFalse(HttpServer.match("/a/*", "/"));
+        Assert.assertTrue(HttpServer.match("/a/*", "/a"));
+    }
+}