felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1656064 [2/2] - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/dispatch/ main/java/org/apache/felix/http/base/internal/handler/ main/java/org/apache/felix/http/base/internal/runtime/ main/java/org/apache/felix...
Date Fri, 30 Jan 2015 17:22:32 GMT
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java Fri Jan 30 17:22:31 2015
@@ -21,8 +21,6 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
 
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
@@ -37,6 +35,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.handler.HandlerRegistry;
 import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.runtime.ContextInfo;
 import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
 import org.apache.felix.http.base.internal.whiteboard.HttpContextBridge;
@@ -53,8 +52,6 @@ public final class HttpServiceImpl imple
     private final HashSet<Filter> localFilters;
     private final ServletContextManager contextManager;
 
-    private final AtomicLong serviceIdCounter = new AtomicLong(-1);
-
     public HttpServiceImpl(Bundle bundle, ServletContext context, HandlerRegistry handlerRegistry, ServletContextAttributeListener servletAttributeListener, boolean sharedContextAttributes)
     {
         this.bundle = bundle;
@@ -97,36 +94,29 @@ public final class HttpServiceImpl imple
     }
 
     /**
-     * TODO As the filter can be registered with multiple patterns
-     *      we shouldn't pass the filter object around in order to
-     *      be able to get different instances (prototype scope).
-     *      Or we do the splitting into single pattern registrations
-     *      already before calling registerFilter()
-     * @param servlet
-     * @param servletInfo
-     * @throws ServletException
-     * @throws NamespaceException
+     * Register a filter
      */
-    public void registerFilter(final Filter filter, final FilterInfo filterInfo)
+    public void registerFilter(final ServletContextHelper context,
+            final ContextInfo contextInfo,
+            final FilterInfo filterInfo)
     {
-        if (filter == null)
+        final ExtServletContext httpContext;
+        if ( context != null )
         {
-            throw new IllegalArgumentException("Filter cannot be null!");
+            httpContext = getServletContext(new HttpContextBridge(context));
         }
-        if (filterInfo == null)
-        {
-            throw new IllegalArgumentException("FilterInfo cannot be null!");
-        }
-        if (isEmpty(filterInfo.patterns) && isEmpty(filterInfo.regexs) && isEmpty(filterInfo.servletNames))
+        else
         {
-            throw new IllegalArgumentException("FilterInfo must have at least one pattern or regex, or provide at least one servlet name!");
+            httpContext = getServletContext(filterInfo.getContext());
         }
-        if (isEmpty(filterInfo.name))
+        Filter filter = filterInfo.getFilter();
+        if ( filter == null )
         {
-            filterInfo.name = filter.getClass().getName();
+            filter = this.bundle.getBundleContext().getServiceObjects(filterInfo.getServiceReference()).getService();
+            // TODO create failure DTO if null
         }
 
-        FilterHandler handler = new FilterHandler(getServletContext(filterInfo.context), filter, filterInfo);
+        FilterHandler handler = new FilterHandler(httpContext, filter, filterInfo);
         try {
             this.handlerRegistry.addFilter(handler);
         } catch (ServletException e) {
@@ -145,10 +135,10 @@ public final class HttpServiceImpl imple
         {
             throw new IllegalArgumentException("Filter must not be null");
         }
-        final FilterInfo info = new FilterInfo();
+
+        final Map<String, String> paramMap = new HashMap<String, String>();
         if ( initParams != null && initParams.size() > 0 )
         {
-            info.initParams = new HashMap<String, String>();
             Enumeration e = initParams.keys();
             while (e.hasMoreElements())
             {
@@ -157,16 +147,17 @@ public final class HttpServiceImpl imple
 
                 if ((key instanceof String) && (value instanceof String))
                 {
-                    info.initParams.put((String) key, (String) value);
+                    paramMap.put((String) key, (String) value);
                 }
             }
         }
-        info.patterns = new String[] {pattern};
-        info.context = context;
-        info.ranking = ranking;
-        info.serviceId = serviceIdCounter.getAndDecrement();
 
-        this.registerFilter(filter, info);
+        final FilterInfo info = new FilterInfo(null, pattern, ranking, paramMap, filter, context);
+        if ( !info.isValid() )
+        {
+            throw new ServletException("Invalid registration information for filter.");
+        }
+        this.registerFilter(null, null, info);
     }
 
     @Override
@@ -189,9 +180,11 @@ public final class HttpServiceImpl imple
     }
 
     /**
+     * Register a servlet with a {@link ServletContextHelper}.
+     * The prefix is the path where the servlet context helper is mounted.
      */
     public void registerServlet(final ServletContextHelper context,
-    		final String prefix,
+    		final ContextInfo contextInfo,
     		final ServletInfo servletInfo)
     {
         if (servletInfo == null)
@@ -212,55 +205,52 @@ public final class HttpServiceImpl imple
         {
         	httpContext = getServletContext(servletInfo.getContext());
         }
-        for(final String alias : servletInfo.getPatterns())
+        Servlet servlet = servletInfo.getServlet();
+        if ( servlet == null )
         {
-            // create a handler for each alias
-            Servlet servlet = servletInfo.getServlet();
-            if ( servlet == null )
-            {
-                servlet = this.bundle.getBundleContext().getServiceObjects(servletInfo.getServiceReference()).getService();
-                // TODO - handle null
-            }
-            final String pattern = (prefix == null ? alias : prefix + alias);
-            final ServletHandler handler = new ServletHandler(httpContext,
-                    servletInfo,
-                    servlet,
-                    pattern);
-            try {
-                this.handlerRegistry.addServlet(handler);
-            } catch (ServletException e) {
-                // TODO create failure DTO
-            } catch (NamespaceException e) {
-                // TODO create failure DTO
-            }
-            this.localServlets.add(servlet);
+            servlet = this.bundle.getBundleContext().getServiceObjects(servletInfo.getServiceReference()).getService();
+            // TODO create failure DTO if null
         }
+
+        final ServletHandler handler = new ServletHandler(contextInfo,
+                httpContext,
+                servletInfo,
+                servlet);
+        try {
+            this.handlerRegistry.addServlet(contextInfo, handler);
+        } catch (ServletException e) {
+            // TODO create failure DTO
+        } catch (NamespaceException e) {
+            // TODO create failure DTO
+        }
+
+        this.localServlets.add(servlet);
     }
 
-    public void unregisterServlet(final ServletInfo servletInfo)
+    public void unregisterServlet(final ContextInfo contextInfo, final ServletInfo servletInfo)
     {
         if (servletInfo == null)
         {
             throw new IllegalArgumentException("ServletInfo cannot be null!");
         }
-        if ( servletInfo.getPatterns() != null )
+        final Servlet servlet = this.handlerRegistry.removeServlet(contextInfo, servletInfo, true);
+        if ( servlet != null )
         {
-            final Set<Servlet> instances = this.handlerRegistry.removeServlet(servletInfo, true);
-            for(final Servlet servlet : instances)
-            {
-                this.localServlets.remove(servlet);
-            }
+            this.localServlets.remove(servlet);
         }
     }
 
-    public void unregisterFilter(final Filter filter, final FilterInfo filterInfo)
+    public void unregisterFilter(final ContextInfo contextInfo, final FilterInfo filterInfo)
     {
         if (filterInfo == null)
         {
             throw new IllegalArgumentException("FilterInfo cannot be null!");
         }
-        this.handlerRegistry.removeFilter(filter, true);
-        this.localFilters.remove(filter);
+        final Filter instance = this.handlerRegistry.removeFilter(filterInfo, true);
+        if ( instance != null )
+        {
+            this.localFilters.remove(instance);
+        }
     }
 
     /**

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=1656064&r1=1656063&r2=1656064&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 Jan 30 17:22:31 2015
@@ -37,6 +37,66 @@ public class UriUtils
     private static final char DOT = '.';
     private static final char SLASH = '/';
 
+    public static String compactPath(String path)
+    {
+        if (path == null)
+        {
+            return null;
+        }
+
+        StringBuilder sb = new StringBuilder();
+
+        int len = path.length();
+        boolean inQuery = false;
+        for (int i = 0; i < len; i++)
+        {
+            char ch = path.charAt(i);
+            if (!inQuery && ch == SLASH && la(path, i + 1) == SLASH)
+            {
+                continue;
+            }
+            if (ch == '?')
+            {
+                inQuery = true;
+            }
+            sb.append(ch);
+        }
+
+        return sb.toString();
+    }
+
+    public static String relativePath(String base, String path)
+    {
+        if (path == null)
+        {
+            return null;
+        }
+        if (base == null)
+        {
+            return path;
+        }
+
+        int len = base.length();
+        if (base.endsWith("/"))
+        {
+            len--;
+        }
+        else if (!base.equals(path))
+        {
+            base = base.concat("/");
+        }
+
+        if (path.startsWith(base))
+        {
+            path = path.substring(len);
+        }
+        if ("".equals(path) || "/".equals(path))
+        {
+            return null;
+        }
+        return path;
+    }
+
     /**
      * Concatenates two paths keeping their respective path-parts into consideration.
      * 

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ExtenderManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ExtenderManager.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ExtenderManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ExtenderManager.java Fri Jan 30 17:22:31 2015
@@ -21,11 +21,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-
 import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.apache.felix.http.base.internal.service.HttpServiceImpl;
 import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
 import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker;
@@ -42,18 +38,6 @@ public final class ExtenderManager
 {
     static final String TYPE_RESOURCE = "r";
 
-    /**
-     * Properties starting with this prefix are passed as servlet init parameters to the
-     * {@code init()} method of the servlet.
-     */
-    public static final String SERVLET_INIT_PREFIX = "servlet.init.";
-
-    /**
-     * Properties starting with this prefix are passed as filter
-     * init parameters to the {@code init()} method of the filter.
-     */
-    public static final String FILTER_INIT_PREFIX = "filter.init.";
-
     private final Map<String, AbstractMapping> mapping;
 
     private final ServletContextHelperManager contextManager;
@@ -67,7 +51,7 @@ public final class ExtenderManager
         this.mapping = new HashMap<String, AbstractMapping>();
         this.contextManager = new ServletContextHelperManager(bundleContext, httpService);
         this.httpService = httpService;
-        addTracker(new FilterTracker(bundleContext, this));
+        addTracker(new FilterTracker(bundleContext, contextManager));
         addTracker(new ServletTracker(bundleContext, this.contextManager));
         addTracker(new ServletContextHelperTracker(bundleContext, this.contextManager));
     }
@@ -134,64 +118,6 @@ public final class ExtenderManager
         return null;
     }
 
-    private boolean getBooleanProperty(ServiceReference ref, String key)
-    {
-        Object value = ref.getProperty(key);
-        if (value instanceof String)
-        {
-            return Boolean.valueOf((String) value);
-        }
-        else if (value instanceof Boolean)
-        {
-            return ((Boolean) value).booleanValue();
-        }
-        return false;
-    }
-
-    private int getIntProperty(ServiceReference ref, String key, int defValue)
-    {
-        Object value = ref.getProperty(key);
-        if (value == null)
-        {
-            return defValue;
-        }
-
-        try
-        {
-            return Integer.parseInt(value.toString());
-        }
-        catch (Exception e)
-        {
-            return defValue;
-        }
-    }
-
-    /**
-     * Get the init parameters.
-     */
-    private Map<String, String> getInitParams(final ServiceReference<?> ref, final String prefix)
-    {
-        Map<String, String> result = null;
-        for (final String key : ref.getPropertyKeys())
-        {
-            if ( key.startsWith(prefix))
-            {
-                final String paramKey = key.substring(prefix.length());
-                final String paramValue = getStringProperty(ref, key);
-
-                if (paramValue != null)
-                {
-                    if ( result == null )
-                    {
-                        result = new HashMap<String, String>();
-                    }
-                    result.put(paramKey, paramValue);
-                }
-            }
-        }
-        return result;
-    }
-
     public void addResource(final ServiceReference ref)
     {
         final String[] pattern = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN);
@@ -227,58 +153,6 @@ public final class ExtenderManager
         this.removeMapping(TYPE_RESOURCE, ref);
     }
 
-    public void add(final Filter service, final ServiceReference ref)
-    {
-        final FilterInfo filterInfo = createFilterInfo(ref, true);
-        if ( filterInfo != null )
-        {
-            ((HttpServiceImpl)this.httpService).registerFilter(service, filterInfo);
-        }
-    }
-
-    private FilterInfo createFilterInfo(final ServiceReference<?> filterRef, final boolean log)
-    {
-        final FilterInfo filterInfo = new FilterInfo();
-        filterInfo.name = getStringProperty(filterRef, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME);
-        filterInfo.asyncSupported = getBooleanProperty(filterRef, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED);
-        filterInfo.servletNames = getStringArrayProperty(filterRef, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET);
-        filterInfo.patterns = getStringArrayProperty(filterRef, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN);
-        filterInfo.ranking = getIntProperty(filterRef, Constants.SERVICE_RANKING, 0);
-        filterInfo.serviceId = (Long)filterRef.getProperty(Constants.SERVICE_ID);
-        filterInfo.initParams = getInitParams(filterRef, FILTER_INIT_PREFIX);
-        String[] dispatcherNames = getStringArrayProperty(filterRef, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_DISPATCHER);
-        if (dispatcherNames != null && dispatcherNames.length > 0)
-        {
-            DispatcherType[] dispatchers = new DispatcherType[dispatcherNames.length];
-            for (int i = 0; i < dispatchers.length; i++)
-            {
-                dispatchers[i] = DispatcherType.valueOf(dispatcherNames[i].toUpperCase());
-            }
-            filterInfo.dispatcher = dispatchers;
-        }
-
-        if (isEmpty(filterInfo.patterns))
-        {
-            if ( log )
-            {
-                SystemLogger.debug("Ignoring Filter Service " + filterRef + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN +
-                        " is missing or empty");
-            }
-            return null;
-        }
-
-        return filterInfo;
-    }
-
-    public void removeFilter(final Filter service, ServiceReference<Filter> ref)
-    {
-        final FilterInfo filterInfo = createFilterInfo(ref, false);
-        if ( filterInfo != null )
-        {
-            ((HttpServiceImpl)this.httpService).unregisterFilter(service, filterInfo);
-        }
-    }
-
     private synchronized void unregisterAll()
     {
         AbstractMapping[] mappings = null;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java Fri Jan 30 17:22:31 2015
@@ -20,16 +20,14 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.felix.http.base.internal.runtime.AbstractInfo;
 import org.apache.felix.http.base.internal.runtime.ContextInfo;
+import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
 import org.apache.felix.http.base.internal.service.HttpServiceImpl;
 import org.osgi.framework.Bundle;
@@ -44,13 +42,13 @@ public final class ServletContextHelperM
     /** A map containing all servlet context registrations. Mapped by context name */
     private final Map<String, List<ContextHolder>> contextMap = new HashMap<String, List<ContextHolder>>();
 
-    /** A map with all servlet registrations, mapped by servlet info. */
-    private final Map<ServletInfo, List<ContextHolder>> servletList = new HashMap<ServletInfo, List<ContextHolder>>();
+    /** A map with all servlet/filter registrations, mapped by abstract info. */
+    private final Map<AbstractInfo<?>, List<ContextHolder>> servicesMap = new HashMap<AbstractInfo<?>, List<ContextHolder>>();
 
     private final HttpServiceImpl httpService;
 
     private final ServiceRegistration<ServletContextHelper> defaultContextRegistration;
-    
+
     /**
      * Create a new servlet context helper manager
      * and the default context
@@ -94,25 +92,39 @@ public final class ServletContextHelperM
 
     private void activate(final ContextHolder holder)
     {
-        for(final Map.Entry<ServletInfo, List<ContextHolder>> entry : this.servletList.entrySet())
+        for(final Map.Entry<AbstractInfo<?>, List<ContextHolder>> entry : this.servicesMap.entrySet())
         {
             if ( entry.getKey().getContextSelectionFilter().match(holder.getInfo().getServiceReference()) )
             {
                 entry.getValue().add(holder);
-            	this.registerServlet(entry.getKey(), holder);
+                if ( entry.getKey() instanceof ServletInfo )
+                {
+                    this.registerServlet((ServletInfo)entry.getKey(), holder);
+                }
+                else if ( entry.getKey() instanceof FilterInfo )
+                {
+                    this.registerFilter((FilterInfo)entry.getKey(), holder);
+                }
             }
         }
     }
 
     private void deactivate(final ContextHolder holder)
     {
-        final Iterator<Map.Entry<ServletInfo, List<ContextHolder>>> i = this.servletList.entrySet().iterator();
+        final Iterator<Map.Entry<AbstractInfo<?>, List<ContextHolder>>> i = this.servicesMap.entrySet().iterator();
         while ( i.hasNext() )
         {
-            final Map.Entry<ServletInfo, List<ContextHolder>> entry = i.next();
+            final Map.Entry<AbstractInfo<?>, List<ContextHolder>> entry = i.next();
             if ( entry.getValue().remove(holder) )
             {
-                this.unregisterServlet(entry.getKey(), holder);
+                if ( entry.getKey() instanceof ServletInfo )
+                {
+                    this.unregisterServlet((ServletInfo)entry.getKey(), holder);
+                }
+                else if ( entry.getKey() instanceof FilterInfo )
+                {
+                    this.unregisterFilter((FilterInfo)entry.getKey(), holder);
+                }
                 if ( entry.getValue().isEmpty() ) {
                     i.remove();
                 }
@@ -206,13 +218,23 @@ public final class ServletContextHelperM
     private void registerServlet(final ServletInfo servletInfo, final ContextHolder holder)
     {
     	final ServletContextHelper helper = holder.getContext(servletInfo.getServiceReference().getBundle());
-    	String prefix = holder.getPrefix();
-        this.httpService.registerServlet(helper, prefix, servletInfo);    	
+        this.httpService.registerServlet(helper, holder.getInfo(), servletInfo);
     }
 
     private void unregisterServlet(final ServletInfo servletInfo, final ContextHolder holder)
     {
-        this.httpService.unregisterServlet(servletInfo);    	
+        this.httpService.unregisterServlet(holder.getInfo(), servletInfo);
+    }
+
+    private void registerFilter(final FilterInfo filterInfo, final ContextHolder holder)
+    {
+        final ServletContextHelper helper = holder.getContext(filterInfo.getServiceReference().getBundle());
+        this.httpService.registerFilter(helper, holder.getInfo(), filterInfo);
+    }
+
+    private void unregisterFilter(final FilterInfo filterInfo, final ContextHolder holder)
+    {
+        this.httpService.unregisterFilter(holder.getInfo(), filterInfo);
     }
 
     /**
@@ -224,7 +246,7 @@ public final class ServletContextHelperM
         synchronized ( this.contextMap )
         {
             final List<ContextHolder> holderList = this.getMatchingContexts(servletInfo);
-            this.servletList.put(servletInfo, holderList);
+            this.servicesMap.put(servletInfo, holderList);
             for(final ContextHolder h : holderList)
             {
             	this.registerServlet(servletInfo, h);
@@ -240,7 +262,7 @@ public final class ServletContextHelperM
     {
         synchronized ( this.contextMap )
         {
-            final List<ContextHolder> holderList = this.servletList.remove(servletInfo);
+            final List<ContextHolder> holderList = this.servicesMap.remove(servletInfo);
             if ( holderList != null )
             {
                 for(final ContextHolder h : holderList)
@@ -258,19 +280,9 @@ public final class ServletContextHelperM
     {
         private final ContextInfo info;
 
-        private final String prefix;
-        
         public ContextHolder(final ContextInfo info)
         {
             this.info = info;
-            if ( info.getPath().equals("/") )
-            {
-            	prefix = null;
-            }
-            else
-            {
-            	prefix = info.getPath().substring(0, info.getPath().length() - 1);
-            }
         }
 
         public ContextInfo getInfo()
@@ -278,22 +290,42 @@ public final class ServletContextHelperM
             return this.info;
         }
 
-        public String getPrefix() 
-        {
-        	return this.prefix;
-        }
-        
         @Override
         public int compareTo(final ContextHolder o)
         {
             return this.info.compareTo(o.info);
         }
-        
-        public ServletContextHelper getContext(final Bundle b) 
+
+        public ServletContextHelper getContext(final Bundle b)
         {
         	// TODO - we should somehow keep track of these objects to later on dispose them
         	return b.getBundleContext().getServiceObjects(this.info.getServiceReference()).getService();
         }
     }
 
+    public void addFilter(final FilterInfo info) {
+        synchronized ( this.contextMap )
+        {
+            final List<ContextHolder> holderList = this.getMatchingContexts(info);
+            this.servicesMap.put(info, holderList);
+            for(final ContextHolder h : holderList)
+            {
+                this.registerFilter(info, h);
+            }
+        }
+    }
+
+    public void removeFilter(final FilterInfo info) {
+        synchronized ( this.contextMap )
+        {
+            final List<ContextHolder> holderList = this.servicesMap.remove(info);
+            if ( holderList != null )
+            {
+                for(final ContextHolder h : holderList)
+                {
+                    this.unregisterFilter(info, h);
+                }
+            }
+        }
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/FilterTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/FilterTracker.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/FilterTracker.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/FilterTracker.java Fri Jan 30 17:22:31 2015
@@ -18,15 +18,17 @@ package org.apache.felix.http.base.inter
 
 import javax.servlet.Filter;
 
-import org.apache.felix.http.base.internal.whiteboard.ExtenderManager;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.runtime.FilterInfo;
+import org.apache.felix.http.base.internal.whiteboard.ServletContextHelperManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
-public final class FilterTracker extends AbstractTracker<Filter>
+public final class FilterTracker extends AbstractReferenceTracker<Filter>
 {
-    private final ExtenderManager manager;
+    private final ServletContextHelperManager contextManager;
 
     private static org.osgi.framework.Filter createFilter(final BundleContext btx)
     {
@@ -45,28 +47,35 @@ public final class FilterTracker extends
         return null; // we never get here - and if we get an NPE which is fine
     }
 
-    public FilterTracker(BundleContext context, ExtenderManager manager)
+    public FilterTracker(final BundleContext context, final ServletContextHelperManager manager)
     {
         super(context, createFilter(context));
-        this.manager = manager;
+        this.contextManager = manager;
     }
 
     @Override
-    protected void added(Filter service, ServiceReference ref)
+    protected void added(final ServiceReference<Filter> ref)
     {
-        this.manager.add(service, ref);
-    }
+        final FilterInfo info = new FilterInfo(ref);
 
-    @Override
-    protected void modified(Filter service, ServiceReference ref)
-    {
-        removed(service, ref);
-        added(service, ref);
+        if ( info.isValid() )
+        {
+            this.contextManager.addFilter(info);
+        }
+        else
+        {
+            SystemLogger.debug("Ignoring Filter service " + ref);
+        }
     }
 
     @Override
-    protected void removed(Filter service, ServiceReference ref)
+    protected void removed(final ServiceReference<Filter> ref)
     {
-        this.manager.removeFilter(service, ref);
+        final FilterInfo info = new FilterInfo(ref);
+
+        if ( info.isValid() )
+        {
+            this.contextManager.removeFilter(info);
+        }
     }
 }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java Fri Jan 30 17:22:31 2015
@@ -16,8 +16,8 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
-import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Map;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.junit.Assert;
@@ -30,6 +30,8 @@ public abstract class AbstractHandlerTes
 
     protected abstract AbstractHandler createHandler();
 
+    protected abstract AbstractHandler createHandler(Map<String, String> map);
+
     public void setUp()
     {
         this.context = Mockito.mock(ExtServletContext.class);
@@ -52,10 +54,10 @@ public abstract class AbstractHandlerTes
         AbstractHandler handler = createHandler();
         Assert.assertEquals(0, handler.getInitParams().size());
 
-        Dictionary<String, String> map = new Hashtable<String, String>();
+        Map<String, String> map = new Hashtable<String, String>();
         map.put("key1", "value1");
 
-        handler.setInitParams(map);
+        handler = createHandler(map);
         Assert.assertEquals(1, handler.getInitParams().size());
         Assert.assertEquals("value1", handler.getInitParams().get("key1"));
     }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java Fri Jan 30 17:22:31 2015
@@ -20,14 +20,15 @@ import static javax.servlet.http.HttpSer
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static javax.servlet.http.HttpServletResponse.SC_PAYMENT_REQUIRED;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.Map;
+
+import javax.servlet.DispatcherType;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -53,17 +54,24 @@ public class FilterHandlerTest extends A
     @Test
     public void testCompare()
     {
-        FilterHandler h1 = createHandler("a", 0);
-        FilterHandler h2 = createHandler("b", 10);
+        FilterHandler h1 = createHandler(0, "a");
+        FilterHandler h2 = createHandler(10, "b");
+        FilterHandler h3 = createHandler(10, "c");
+
+        assertEquals(0, h1.compareTo(h1));
 
         assertEquals(1, h1.compareTo(h2));
         assertEquals(-1, h2.compareTo(h1));
+
+        // h2 is actually registered first, so should be called first...
+        assertEquals(-1, h2.compareTo(h3));
+        assertEquals(1, h3.compareTo(h2));
     }
 
     @Test
     public void testDestroy()
     {
-        FilterHandler h1 = createHandler("/a", 0);
+        FilterHandler h1 = createHandler(0, "/a");
         h1.destroy();
         verify(this.filter).destroy();
     }
@@ -71,13 +79,13 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleFound() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
         when(this.context.handleSecurity(req, res)).thenReturn(true);
 
-        when(req.getPathInfo()).thenReturn("/a");
+        when(req.getRequestURI()).thenReturn("/a");
         h1.handle(req, res, chain);
 
         verify(this.filter).doFilter(req, res, chain);
@@ -87,13 +95,13 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleFoundContextRoot() throws Exception
     {
-        FilterHandler h1 = createHandler("/", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
         when(this.context.handleSecurity(req, res)).thenReturn(true);
 
-        when(req.getPathInfo()).thenReturn(null);
+        when(req.getRequestURI()).thenReturn(null);
         h1.handle(req, res, chain);
 
         verify(this.filter).doFilter(req, res, chain);
@@ -106,12 +114,12 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleFoundForbidden() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
 
-        when(req.getPathInfo()).thenReturn("/a");
+        when(req.getRequestURI()).thenReturn("/a");
         // Default behaviour: uncomitted response and default status code...
         when(res.isCommitted()).thenReturn(false);
         when(res.getStatus()).thenReturn(SC_OK);
@@ -131,12 +139,12 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleFoundForbiddenCommittedOwnResponse() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
 
-        when(req.getPathInfo()).thenReturn("/a");
+        when(req.getRequestURI()).thenReturn("/a");
         // Simulate an already committed response...
         when(res.isCommitted()).thenReturn(true);
         when(res.getStatus()).thenReturn(SC_OK);
@@ -157,12 +165,12 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleFoundForbiddenCustomStatusCode() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
 
-        when(req.getPathInfo()).thenReturn("/a");
+        when(req.getRequestURI()).thenReturn("/a");
         // Simulate an uncommitted response with a non-default status code...
         when(res.isCommitted()).thenReturn(false);
         when(res.getStatus()).thenReturn(SC_PAYMENT_REQUIRED);
@@ -180,76 +188,78 @@ public class FilterHandlerTest extends A
     @Test
     public void testHandleNotFound() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
 
-        when(req.getPathInfo()).thenReturn("/");
+        when(req.getRequestURI()).thenReturn("/");
         h1.handle(req, res, chain);
 
         verify(this.filter, never()).doFilter(req, res, chain);
-        verify(chain).doFilter(req, res);
+        verify(chain, never()).doFilter(req, res);
     }
 
     @Test
     public void testHandleNotFoundContextRoot() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
-        HttpServletRequest req = mock(HttpServletRequest.class);
-        HttpServletResponse res = mock(HttpServletResponse.class);
+        FilterHandler h1 = createHandler(0, "/a");
+        HttpServletRequest req = createServletRequest();
+        HttpServletResponse res = createServletResponse();
         FilterChain chain = mock(FilterChain.class);
 
-        when(req.getPathInfo()).thenReturn(null);
+        when(req.getRequestURI()).thenReturn(null);
         h1.handle(req, res, chain);
 
         verify(this.filter, never()).doFilter(req, res, chain);
-        verify(chain).doFilter(req, res);
+        verify(chain, never()).doFilter(req, res);
     }
 
     @Test
     public void testInit() throws Exception
     {
-        FilterHandler h1 = createHandler("/a", 0);
+        FilterHandler h1 = createHandler(0, "/a");
         h1.init();
         verify(this.filter).init(any(FilterConfig.class));
     }
 
-    @Test
-    public void testMatches()
+   @Override
+    protected AbstractHandler createHandler()
     {
-        FilterHandler h1 = createHandler("/a/b", 0);
-        FilterHandler h2 = createHandler("/a/b/.+", 0);
-        FilterHandler h3 = createHandler("/", 0);
-        FilterHandler h4 = createHandler("/.*", 0);
-
-        assertFalse(h1.matches(null));
-        assertFalse(h1.matches("/a"));
-        assertTrue(h1.matches("/a/b"));
-        assertFalse(h1.matches("/a/b/c"));
-        assertFalse(h2.matches(null));
-        assertFalse(h1.matches("/a"));
-        assertTrue(h2.matches("/a/b/c"));
-        assertFalse(h2.matches("/a/b/"));
-        assertTrue(h3.matches(null));
-        assertTrue(h3.matches("/"));
-        assertFalse(h3.matches("/a/b/"));
-        assertTrue(h4.matches(null));
-        assertTrue(h4.matches("/"));
-        assertTrue(h4.matches("/a/b/"));
+        return createHandler(0, "dummy");
     }
 
     @Override
-    protected AbstractHandler createHandler()
+    protected AbstractHandler createHandler(final Map<String, String> initParams)
+    {
+        return createHandler("dummy", 0, initParams);
+    }
+
+    private FilterHandler createHandler(int ranking, String pattern)
     {
-        return createHandler("dummy", 0);
+        return createHandler(pattern, ranking, null);
     }
 
-    private FilterHandler createHandler(String pattern, int ranking)
+    private FilterHandler createHandler(String pattern, int ranking, final Map<String, String> initParams)
     {
-        final FilterInfo info = new FilterInfo();
-        info.regexs = new String[] {pattern};
-        info.ranking = ranking;
+        final FilterInfo info = new FilterInfo(null, pattern, ranking, initParams, this.filter, null);
         return new FilterHandler(this.context, this.filter, info);
     }
+
+    private HttpServletRequest createServletRequest()
+    {
+        return createServletRequest(DispatcherType.REQUEST);
+    }
+
+    private HttpServletRequest createServletRequest(DispatcherType type)
+    {
+        HttpServletRequest result = mock(HttpServletRequest.class);
+        when(result.getDispatcherType()).thenReturn(type);
+        return result;
+    }
+
+    private HttpServletResponse createServletResponse()
+    {
+        return mock(HttpServletResponse.class);
+    }
 }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java Fri Jan 30 17:22:31 2015
@@ -16,27 +16,10 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterConfig;
-import javax.servlet.Servlet;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.osgi.service.http.NamespaceException;
 
 public class HandlerRegistryTest
 {
+    /*
     @Test
     public void testAddRemoveServlet() throws Exception
     {
@@ -44,18 +27,18 @@ public class HandlerRegistryTest
 
         Servlet servlet = Mockito.mock(Servlet.class);
         final ServletInfo info = new ServletInfo("foo", "/foo", 0, null, servlet, null);
-        ServletHandler handler = new ServletHandler(null, info, info.getServlet(), info.getPatterns()[0]);
+        ServletHandler handler = new ServletHandler(null, null, info, info.getServlet());
         assertEquals("Precondition", 0, hr.getServlets().length);
-        hr.addServlet(handler);
+        hr.addServlet(null, handler);
         Mockito.verify(servlet, Mockito.times(1)).init(Mockito.any(ServletConfig.class));
         assertEquals(1, hr.getServlets().length);
         assertSame(handler, hr.getServlets()[0]);
 
         final ServletInfo info2 = new ServletInfo("bar", "/bar", 0, null, servlet, null);
-        ServletHandler handler2 = new ServletHandler(null, info2, info2.getServlet(), info2.getPatterns()[0]);
+        ServletHandler handler2 = new ServletHandler(null, null, info2, info2.getServlet());
         try
         {
-            hr.addServlet(handler2);
+            hr.addServlet(null, handler2);
             // TODO
 //            fail("Should not have allowed to add the same servlet twice");
         }
@@ -66,11 +49,11 @@ public class HandlerRegistryTest
         assertArrayEquals(new ServletHandler[] {handler2, handler}, hr.getServlets());
 
         final ServletInfo info3 = new ServletInfo("zar", "/foo", 0, null, Mockito.mock(Servlet.class), null);
-        ServletHandler handler3 = new ServletHandler(null,info3, info3.getServlet(), info3.getPatterns()[0]);
+        ServletHandler handler3 = new ServletHandler(null, null,info3, info3.getServlet());
 
         try
         {
-            hr.addServlet(handler3);
+            hr.addServlet(null, handler3);
             fail("Should not have allowed to add the same alias twice");
         }
         catch (NamespaceException ne) {
@@ -93,7 +76,7 @@ public class HandlerRegistryTest
 
         Servlet servlet = Mockito.mock(Servlet.class);
         final ServletInfo info = new ServletInfo("bar", "/bar", 0, null, servlet, null);
-        final ServletHandler otherHandler = new ServletHandler(null, info, info.getServlet(), info.getPatterns()[0]);
+        final ServletHandler otherHandler = new ServletHandler(null, null, info, info.getServlet());
 
         Mockito.doAnswer(new Answer<Void>()
         {
@@ -106,17 +89,17 @@ public class HandlerRegistryTest
                     registered = true;
                     // sneakily register another handler with this servlet before this
                     // one has finished calling init()
-                    hr.addServlet(otherHandler);
+                    hr.addServlet(null, otherHandler);
                 }
                 return null;
             }
         }).when(servlet).init(Mockito.any(ServletConfig.class));
 
         final ServletInfo info2 = new ServletInfo("foo", "/foo", 0, null, servlet, null);
-        ServletHandler handler = new ServletHandler(null, info2, info2.getServlet(), info2.getPatterns()[0]);
+        ServletHandler handler = new ServletHandler(null, null, info2, info2.getServlet());
         try
         {
-            hr.addServlet(handler);
+            hr.addServlet(null, handler);
 
             // TODO
 //            fail("Should not have allowed the servlet to be added as it was already "
@@ -137,7 +120,7 @@ public class HandlerRegistryTest
 
         Servlet otherServlet = Mockito.mock(Servlet.class);
         final ServletInfo info = new ServletInfo("bar", "/foo", 0, null, otherServlet, null);
-        final ServletHandler otherHandler = new ServletHandler(null, info, info.getServlet(), info.getPatterns()[0]);
+        final ServletHandler otherHandler = new ServletHandler(null, null, info, info.getServlet());
 
         Servlet servlet = Mockito.mock(Servlet.class);
         Mockito.doAnswer(new Answer<Void>()
@@ -146,17 +129,17 @@ public class HandlerRegistryTest
             public Void answer(InvocationOnMock invocation) throws Throwable
             {
                 // sneakily register another servlet before this one has finished calling init()
-                hr.addServlet(otherHandler);
+                hr.addServlet(null, otherHandler);
                 return null;
             }
         }).when(servlet).init(Mockito.any(ServletConfig.class));
 
         final ServletInfo info2 = new ServletInfo("foo", "/foo", 0, null, servlet, null);
-        ServletHandler handler = new ServletHandler(null, info2, info2.getServlet(), info2.getPatterns()[0]);
+        ServletHandler handler = new ServletHandler(null, null, info2, info2.getServlet());
 
         try
         {
-            hr.addServlet(handler);
+            hr.addServlet(null, handler);
             fail("Should not have allowed the servlet to be added as another one got in there with the same alias");
         }
         catch (NamespaceException ne)
@@ -175,10 +158,7 @@ public class HandlerRegistryTest
         HandlerRegistry hr = new HandlerRegistry();
 
         Filter filter = Mockito.mock(Filter.class);
-        final FilterInfo info = new FilterInfo();
-        info.name = "oho";
-        info.patterns = new String[] {"/aha"};
-        info.ranking = 1;
+        final FilterInfo info = new FilterInfo("oho", "/aha", 1, null, filter, null);
 
         FilterHandler handler = new FilterHandler(null, filter, info);
         assertEquals("Precondition", 0, hr.getFilters().length);
@@ -187,10 +167,7 @@ public class HandlerRegistryTest
         assertEquals(1, hr.getFilters().length);
         assertSame(handler, hr.getFilters()[0]);
 
-        final FilterInfo info2 = new FilterInfo();
-        info2.name = "haha";
-        info2.patterns = new String[] {"/hihi"};
-        info2.ranking = 2;
+        final FilterInfo info2 = new FilterInfo("haha", "/hihi", 2, null, filter, null);
         FilterHandler handler2 = new FilterHandler(null, filter, info2);
         try
         {
@@ -215,10 +192,7 @@ public class HandlerRegistryTest
         final HandlerRegistry hr = new HandlerRegistry();
 
         Filter filter = Mockito.mock(Filter.class);
-        final FilterInfo info = new FilterInfo();
-        info.name = "two";
-        info.patterns = new String[] {"/two"};
-        info.ranking = 99;
+        final FilterInfo info = new FilterInfo("two", "/two", 99, null, filter, null);
         final FilterHandler otherHandler = new FilterHandler(null, filter, info);
 
         Mockito.doAnswer(new Answer<Void>()
@@ -238,10 +212,7 @@ public class HandlerRegistryTest
             }
         }).when(filter).init(Mockito.any(FilterConfig.class));
 
-        final FilterInfo info2 = new FilterInfo();
-        info2.name = "one";
-        info2.patterns = new String[] {"/one"};
-        info2.ranking = 1;
+        final FilterInfo info2 = new FilterInfo("one", "/one", 1, null, filter, null);
         FilterHandler handler = new FilterHandler(null, filter, info2);
 
         try
@@ -264,17 +235,14 @@ public class HandlerRegistryTest
 
         Servlet servlet = Mockito.mock(Servlet.class);
         final ServletInfo info = new ServletInfo("f", "/f", 0, null, servlet, null);
-        ServletHandler servletHandler = new ServletHandler(null, info, info.getServlet(), info.getPatterns()[0]);
-        hr.addServlet(servletHandler);
+        ServletHandler servletHandler = new ServletHandler(null, null, info, info.getServlet());
+        hr.addServlet(null, servletHandler);
         Servlet servlet2 = Mockito.mock(Servlet.class);
         final ServletInfo info2 = new ServletInfo("ff", "/ff", 0, null, servlet2, null);
-        ServletHandler servletHandler2 = new ServletHandler(null, info2, info2.getServlet(), info2.getPatterns()[0]);
-        hr.addServlet(servletHandler2);
+        ServletHandler servletHandler2 = new ServletHandler(null, null, info2, info2.getServlet());
+        hr.addServlet(null, servletHandler2);
         Filter filter = Mockito.mock(Filter.class);
-        final FilterInfo fi = new FilterInfo();
-        fi.name = "f";
-        fi.patterns = new String[] {"/f"};
-        fi.ranking = 0;
+        final FilterInfo fi = new FilterInfo("f", "/f", 0, null, filter, null);
         FilterHandler filterHandler = new FilterHandler(null, filter, fi);
         hr.addFilter(filterHandler);
 
@@ -296,4 +264,5 @@ public class HandlerRegistryTest
         assertEquals(0, hr.getServlets().length);
         assertEquals(0, hr.getFilters().length);
     }
+    */
 }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerTest.java?rev=1656064&r1=1656063&r2=1656064&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerTest.java Fri Jan 30 17:22:31 2015
@@ -19,7 +19,6 @@ package org.apache.felix.http.base.inter
 import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static javax.servlet.http.HttpServletResponse.SC_PAYMENT_REQUIRED;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
@@ -28,6 +27,8 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.Map;
+
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
@@ -50,16 +51,6 @@ public class ServletHandlerTest extends
     }
 
     @Test
-    public void testCompare()
-    {
-        ServletHandler h1 = createHandler("/a");
-        ServletHandler h2 = createHandler("/a/b");
-
-        assertEquals(2, h1.compareTo(h2));
-        assertEquals(-2, h2.compareTo(h1));
-    }
-
-    @Test
     public void testDestroy()
     {
         ServletHandler h1 = createHandler("/a");
@@ -117,7 +108,7 @@ public class ServletHandlerTest extends
         when(req.getPathInfo()).thenReturn("/a/b");
         boolean result = h1.handle(req, res);
 
-        assertTrue(result);
+        assertFalse(result);
         verify(this.servlet, never()).service(req, res);
         verify(res).sendError(SC_FORBIDDEN);
     }
@@ -142,7 +133,7 @@ public class ServletHandlerTest extends
         when(req.getPathInfo()).thenReturn("/a/b");
         boolean result = h1.handle(req, res);
 
-        assertTrue(result);
+        assertFalse(result);
         verify(this.servlet, never()).service(req, res);
         verify(res, never()).sendError(SC_FORBIDDEN);
     }
@@ -167,7 +158,7 @@ public class ServletHandlerTest extends
         when(req.getPathInfo()).thenReturn("/a/b");
         boolean result = h1.handle(req, res);
 
-        assertTrue(result);
+        assertFalse(result);
         verify(this.servlet, never()).service(req, res);
         verify(res, never()).sendError(SC_FORBIDDEN);
     }
@@ -194,11 +185,11 @@ public class ServletHandlerTest extends
         HttpServletResponse res = mock(HttpServletResponse.class);
         when(this.context.handleSecurity(req, res)).thenReturn(true);
 
-        when(req.getPathInfo()).thenReturn(null);
+        when(req.getRequestURI()).thenReturn(null);
         boolean result = h1.handle(req, res);
 
-        assertFalse(result);
-        verify(this.servlet, never()).service(req, res);
+        assertTrue(result);
+        verify(this.servlet).service(req, res);
     }
 
     @Test
@@ -209,28 +200,26 @@ public class ServletHandlerTest extends
         verify(this.servlet).init(any(ServletConfig.class));
     }
 
-    @Test
-    public void testMatches()
+    @Override
+    protected AbstractHandler createHandler()
     {
-        ServletHandler h1 = createHandler("/a/b");
-
-        assertFalse(h1.matches(null));
-        assertFalse(h1.matches("/"));
-        assertFalse(h1.matches("/a/"));
-        assertTrue(h1.matches("/a/b"));
-        assertTrue(h1.matches("/a/b/"));
-        assertTrue(h1.matches("/a/b/c"));
+        return createHandler("/dummy", null);
     }
 
     @Override
-    protected AbstractHandler createHandler()
+    protected AbstractHandler createHandler(Map<String, String> map)
     {
-        return createHandler("/dummy");
+        return createHandler("/dummy", map);
     }
 
     private ServletHandler createHandler(String alias)
     {
-        final ServletInfo info = new ServletInfo(null, alias, 0, null, this.servlet, null);
-        return new ServletHandler(this.context, info, info.getServlet(), info.getPatterns()[0]);
+        return createHandler(alias, null);
+    }
+
+    private ServletHandler createHandler(String alias, Map<String, String> map)
+    {
+        final ServletInfo info = new ServletInfo(null, alias, 0, map, this.servlet, null);
+        return new ServletHandler(null, this.context, info, info.getServlet());
     }
 }

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=1656064&r1=1656063&r2=1656064&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 Jan 30 17:22:31 2015
@@ -31,6 +31,37 @@ import org.junit.Test;
 public class UriUtilsTest
 {
     @Test
+    public void testCompactPath()
+    {
+        assertEquals(null, compactPath(null));
+        assertEquals("", compactPath(""));
+        assertEquals("/", compactPath("/"));
+        assertEquals("/", compactPath("//"));
+        assertEquals("/foo/", compactPath("/foo//"));
+        assertEquals("/foo/", compactPath("//foo/"));
+        assertEquals("/foo/bar", compactPath("/foo/bar"));
+        assertEquals("/foo/bar", compactPath("//foo//bar"));
+        assertEquals("/foo/bar", compactPath("/foo///bar"));
+        assertEquals("/foo/bar?qux=quu//baz", compactPath("/foo/bar?qux=quu//baz"));
+    }
+
+    @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("/foo", relativePath("/", "/foo"));
+        assertEquals("/foo/", relativePath("/", "/foo/"));
+        assertEquals("/foo/", relativePath(null, "/foo/"));
+        assertEquals("/bar", relativePath("/foo", "/foo/bar"));
+        assertEquals("/bar/foo", relativePath("/foo", "/bar/foo"));
+        assertEquals("/bar", relativePath("/foo/", "/foo/bar"));
+        assertEquals("/foobar", relativePath("/foo", "/foobar"));
+    }
+
+    @Test
     public void testConcatOk()
     {
         assertEquals(null, concat(null, null));



Mime
View raw message