FELIX-4451 : HttpContext#getResource is called with a relative path


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1575691 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
index e0fa187..e35aa18 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
@@ -238,7 +238,7 @@
 
     public String getRealPath(String name)
     {
-        URL url = getResource(normalizePath(name));
+        URL url = getResource(name);
         if (url == null)
         {
             return null;
@@ -253,7 +253,7 @@
 
     public URL getResource(String path)
     {
-        return this.httpContext.getResource(normalizePath(path));
+        return this.httpContext.getResource(normalizeResourcePath(path));
     }
 
     public InputStream getResourceAsStream(String path)
@@ -416,7 +416,7 @@
             return null;
         }
 
-        String normalizedPath = path.trim().replaceAll("/+", "/");
+        String normalizedPath = normalizeResourcePath(path);
         if (normalizedPath.startsWith("/") && (normalizedPath.length() > 1))
         {
             normalizedPath = normalizedPath.substring(1);
@@ -424,4 +424,15 @@
 
         return normalizedPath;
     }
+
+    private String normalizeResourcePath(String path)
+    {
+        if ( path == null)
+        {
+            return null;
+        }
+        String normalizedPath = path.trim().replaceAll("/+", "/");
+
+        return normalizedPath;
+    }
 }
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
index c82b336..17b025d 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
@@ -470,7 +470,7 @@
         URL url = getClass().getResource("resource.txt");
         Assert.assertNotNull(url);
 
-        Mockito.when(this.httpContext.getResource("resource.txt")).thenReturn(url);
+        Mockito.when(this.httpContext.getResource("/resource.txt")).thenReturn(url);
         Assert.assertNull(this.context.getResource("/notfound.txt"));
         Assert.assertEquals(url, this.context.getResource("/resource.txt"));
     }
@@ -481,7 +481,7 @@
         URL url = getClass().getResource("resource.txt");
         Assert.assertNotNull(url);
 
-        Mockito.when(this.httpContext.getResource("resource.txt")).thenReturn(url);
+        Mockito.when(this.httpContext.getResource("/resource.txt")).thenReturn(url);
         Assert.assertNull(this.context.getResourceAsStream("/notfound.txt"));
         Assert.assertNotNull(this.context.getResourceAsStream("/resource.txt"));
     }