felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1685074 - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/dispatch/ main/java/org/apache/felix/http/base/internal/util/ test/java/org/apache/felix/http/base/internal/util/
Date Fri, 12 Jun 2015 12:02:13 GMT
Author: cziegeler
Date: Fri Jun 12 12:02:13 2015
New Revision: 1685074

URL: http://svn.apache.org/r1685074
Log:
FELIX-4925 : Request path is not decoded

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1685074&r1=1685073&r2=1685074&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
Fri Jun 12 12:02:13 2015
@@ -31,6 +31,8 @@ import static org.apache.felix.http.base
 import static org.apache.felix.http.base.internal.util.UriUtils.removeDotSegments;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -577,11 +579,31 @@ public final class Dispatcher implements
             final Set<Long> ids = HttpSessionWrapper.getExpiredSessionContextIds(session);
             this.whiteboardManager.sessionDestroyed(session, ids);
         }
-        String requestURI = getRequestURI(req);
-        if ( requestURI == null )
+
+        // get full requested path
+        // we can't use req.getRequestURI() as this is returning the encoded path
+        String path = "";
+        try
         {
-            requestURI = "";
+            final URL url = new URL(req.getRequestURL().toString());
+            path = UriUtils.relativePath(req.getContextPath(), url.getPath());
+
+        }
+        catch (final MalformedURLException mue)
+        {
+            // we ignore this and revert to servlet path and path info
+            path = req.getServletPath();
+            if ( path == null )
+            {
+                path = "";
+            }
+            if ( req.getPathInfo() != null )
+            {
+                path = path.concat(req.getPathInfo());
+            }
+
         }
+        final String requestURI = path;
 
         // Determine which servlet we should forward the request to...
         final PathResolution pr = this.handlerRegistry.resolveServlet(requestURI);
@@ -694,7 +716,7 @@ public final class Dispatcher implements
         invokeChain(resolution.handler, filterHandlers, request, response);
     }
 
-    private String getRequestURI(HttpServletRequest req)
+    private String getRequestURI(final HttpServletRequest req)
     {
         return UriUtils.relativePath(req.getContextPath(), req.getRequestURI());
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java?rev=1685074&r1=1685073&r2=1685074&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
Fri Jun 12 12:02:13 2015
@@ -26,6 +26,9 @@ import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
 /**
  * Some convenience methods for handling URI(-parts).
  */
@@ -63,11 +66,11 @@ public abstract class UriUtils
         return sb.toString();
     }
 
-    public static String relativePath(String base, String path)
+    public static @Nonnull String relativePath(@CheckForNull String base, @CheckForNull String
path)
     {
         if (path == null)
         {
-            return null;
+            return "";
         }
         if (base == null)
         {
@@ -90,7 +93,7 @@ public abstract class UriUtils
         }
         if ("".equals(path) || "/".equals(path))
         {
-            return null;
+            return "";
         }
         return path;
     }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java?rev=1685074&r1=1685073&r2=1685074&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
(original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
Fri Jun 12 12:02:13 2015
@@ -50,10 +50,10 @@ public class UriUtilsTest
     @Test
     public void testRelativePath()
     {
-        assertEquals(null, relativePath("/foo", null));
-        assertEquals(null, relativePath("/foo", ""));
-        assertEquals(null, relativePath("/foo", "/foo"));
-        assertEquals(null, relativePath("/foo", "/foo/")); // XXX or "/"?
+        assertEquals("", relativePath("/foo", null));
+        assertEquals("", relativePath("/foo", ""));
+        assertEquals("", relativePath("/foo", "/foo"));
+        assertEquals("", relativePath("/foo", "/foo/")); // XXX or "/"?
         assertEquals("/foo", relativePath("/", "/foo"));
         assertEquals("/foo/", relativePath("/", "/foo/"));
         assertEquals("/foo/", relativePath(null, "/foo/"));



Mime
View raw message