FELIX-763 - improvements to alias resolution mechanism. Closer to standard, but still poss not quite right. 

Alias "matching" uses the underlying Jetty path matching approach. The fixes in this version seem to avoid errant matches i.e. resource contexts with a completely different alias are no longer called, and matching aliases are now called correctly. There are possibly still deviations from standard.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@704136 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http.jetty/pom.xml b/http.jetty/pom.xml
index 4da8638..4d0a653 100644
--- a/http.jetty/pom.xml
+++ b/http.jetty/pom.xml
@@ -49,17 +49,17 @@
         <dependency>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>servlet-api-2.5</artifactId>
-            <version>6.1.7</version>
+            <version>6.1.12.rc3</version>
         </dependency>
         <dependency>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>jetty</artifactId>
-            <version>6.1.7</version>
+            <version>6.1.12.rc3</version>
         </dependency>
         <dependency>
             <groupId>org.mortbay.jetty</groupId>
             <artifactId>jetty-util</artifactId>
-            <version>6.1.7</version>
+            <version>6.1.12.rc3</version>
         </dependency>
     </dependencies>
     <build>
diff --git a/http.jetty/src/main/java/org/apache/felix/http/jetty/HttpServiceImpl.java b/http.jetty/src/main/java/org/apache/felix/http/jetty/HttpServiceImpl.java
index 02995a7..2943703 100644
--- a/http.jetty/src/main/java/org/apache/felix/http/jetty/HttpServiceImpl.java
+++ b/http.jetty/src/main/java/org/apache/felix/http/jetty/HttpServiceImpl.java
@@ -136,7 +136,12 @@
 
         if ( !aliasValid( alias ) )
         {
-            throw new IllegalArgumentException( "malformed alias" );
+            throw new IllegalArgumentException( "malformed alias: " + alias);
+        }
+        
+        if ( !nameValid( name ) )
+        {
+            throw new IllegalArgumentException( "malformed name: " + name);
         }
 
         // add alias with null details
@@ -238,7 +243,28 @@
 
     protected boolean aliasValid( String alias )
     {
-        if ( !alias.equals( "/" ) && ( !alias.startsWith( "/" ) || alias.endsWith( "/" ) ) )
+        if (alias == null)
+        {
+            return false;
+        }
+            
+        if (!alias.equals( "/" ) && ( !alias.startsWith( "/" ) || alias.endsWith( "/" ) ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+    
+    
+    protected boolean nameValid( String name )
+    {
+        if (name == null)
+        {
+            return false;
+        }
+            
+        if (name.endsWith( "/" ))
         {
             return false;
         }
diff --git a/http.jetty/src/main/java/org/apache/felix/http/jetty/ServletContextGroup.java b/http.jetty/src/main/java/org/apache/felix/http/jetty/ServletContextGroup.java
index 3872123..c99ec50 100644
--- a/http.jetty/src/main/java/org/apache/felix/http/jetty/ServletContextGroup.java
+++ b/http.jetty/src/main/java/org/apache/felix/http/jetty/ServletContextGroup.java
@@ -122,7 +122,7 @@
     void addResource( String alias, String path )
     {
         String wAlias = aliasWildcard( alias );
-        ServletHolder holder = new OsgiResourceHolder( m_hdlr, path, this );
+        ServletHolder holder = new OsgiResourceHolder( m_hdlr, alias, path, this );
         m_hdlr.addOsgiServletHolder( wAlias, holder );
         Activator.debug( " adding resources for " + wAlias + " at: " + path );
     }
diff --git a/http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiResourceHolder.java b/http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiResourceHolder.java
index 4addc28..5b44972 100644
--- a/http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiResourceHolder.java
+++ b/http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiResourceHolder.java
@@ -51,9 +51,10 @@
     private ServletContextGroup m_servletContextGroup;
     private HttpContext m_osgiHttpContext;
     private AccessControlContext m_acc;
+    private String m_path;
 
 
-    public OsgiResourceHolder( ServletHandler handler, String name, ServletContextGroup servletContextGroup )
+    public OsgiResourceHolder( ServletHandler handler, String name, String path, ServletContextGroup servletContextGroup )
     {
         super();
 
@@ -62,7 +63,12 @@
 
         m_servletContextGroup = servletContextGroup;
         m_osgiHttpContext = servletContextGroup.getOsgiHttpContext();
-
+        m_path = path;
+        if (m_path == null)
+        {
+            m_path = "";
+        }
+        
         if ( System.getSecurityManager() != null )
         {
             m_acc = AccessController.getContext();
@@ -91,11 +97,17 @@
         // get the relative path (assume empty path if there is no path info)
         // (FELIX-503)
         String target = request.getPathInfo();
-        if (target == null) {
+        if (target == null) 
+        {
             target = "";
         }
+        
+        if (!target.startsWith("/"))
+        {
+            target += "/" + target;
+        }
 
-        Activator.debug( "handle for name:" + getName() + "(path=" + target + ")" );
+        Activator.debug( "handle for name:" + m_path + " (path=" + target + ")" );
 
         if ( !m_osgiHttpContext.handleSecurity( request, response ) )
         {
@@ -103,7 +115,7 @@
         }
 
         // Create resource based name and see if we can resolve it
-        String resName = getName() + target;
+        String resName = m_path + target;
         Activator.debug( "** looking for: " + resName );
         URL url = m_osgiHttpContext.getResource( resName );
 
@@ -267,11 +279,14 @@
     {
         long lastModified = 0;
         
+        System.out.println("url: " + resUrl);
+        
         try 
         {
             // Get last modified time
             URLConnection conn = resUrl.openConnection();
             lastModified = conn.getLastModified();
+            System.out.println("modified - " + lastModified);
         } 
         catch (Exception e) 
         {