FELIX-4925 : Request path is not decoded

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1685074 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
index 2f72fd8..aafe00d 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
@@ -31,6 +31,8 @@
 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 @@
             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 @@
         invokeChain(resolution.handler, filterHandlers, request, response);
     }
 
-    private String getRequestURI(HttpServletRequest req)
+    private String getRequestURI(final HttpServletRequest req)
     {
         return UriUtils.relativePath(req.getContextPath(), req.getRequestURI());
     }
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java b/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
index c7704e0..e514c7b 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
@@ -26,6 +26,9 @@
 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 @@
         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 @@
         }
         if ("".equals(path) || "/".equals(path))
         {
-            return null;
+            return "";
         }
         return path;
     }
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
index e3923bb..36717c7 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/util/UriUtilsTest.java
@@ -50,10 +50,10 @@
     @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/"));