felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1682004 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: dispatch/ handler/ registry/ runtime/ service/ whiteboard/
Date Wed, 27 May 2015 12:50:15 GMT
Author: cziegeler
Date: Wed May 27 12:50:15 2015
New Revision: 1682004

URL: http://svn.apache.org/r1682004
Log:
FELIX-4904 : Provide a way to associate whiteboard services with the default context of the
http service

Removed:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ContextHandler.java
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/dispatch/RequestDispatcherProvider.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletContextWrapper.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/HttpServiceContextHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.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=1682004&r1=1682003&r2=1682004&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
Wed May 27 12:50:15 2015
@@ -34,6 +34,8 @@ import java.io.IOException;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 import javax.servlet.AsyncContext;
 import javax.servlet.DispatcherType;
 import javax.servlet.FilterChain;
@@ -56,6 +58,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.registry.PathResolution;
+import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
 import org.apache.felix.http.base.internal.registry.ServletResolution;
 import org.apache.felix.http.base.internal.util.UriUtils;
 import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
@@ -133,25 +136,19 @@ public final class Dispatcher implements
 
         private final AtomicInteger invocationCount = new AtomicInteger();
 
-        private final Long serviceId;
+        private final PerContextHandlerRegistry errorRegistry;
 
         private final String servletName;
 
-        public ServletResponseWrapper(final HttpServletRequest req, final HttpServletResponse
res,
-                final ServletHandler servletHandler)
+        public ServletResponseWrapper(@Nonnull final HttpServletRequest req,
+                @Nonnull final HttpServletResponse res,
+                @CheckForNull final String servletName,
+                @CheckForNull final PerContextHandlerRegistry errorRegistry)
         {
             super(res);
             this.request = req;
-            if ( servletHandler != null )
-            {
-                this.serviceId = servletHandler.getContextServiceId();
-                this.servletName = servletHandler.getName();
-            }
-            else
-            {
-                this.serviceId = null;
-                this.servletName = null;
-            }
+            this.servletName = servletName;
+            this.errorRegistry = errorRegistry;
         }
 
         @Override
@@ -178,7 +175,8 @@ public final class Dispatcher implements
                     code >= SC_OK)
                 {
                     final Throwable exception = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
-                    final ServletResolution errorResolution = handlerRegistry.getErrorHandler(request.getRequestURI(),
this.serviceId, code, exception);
+                    final ServletHandler errorResolution = (errorRegistry == null ? null
:
+                            errorRegistry.getErrorHandler(code, exception));
 
                     if ( errorResolution != null )
                     {
@@ -201,10 +199,10 @@ public final class Dispatcher implements
 
                             final RequestInfo requestInfo = new RequestInfo(servletPath,
pathInfo, queryString);
 
-                            final FilterHandler[] filterHandlers = handlerRegistry.getFilters(errorResolution,
DispatcherType.ERROR, request.getRequestURI());
+                            final FilterHandler[] filterHandlers = errorRegistry.getFilterHandlers(errorResolution,
DispatcherType.ERROR, request.getRequestURI());
 
                             // TODO - is async = false correct?
-                            invokeChain(errorResolution.handler, filterHandlers, new ServletRequestWrapper(request,
errorResolution.handler.getContext(), requestInfo, this.serviceId, false), this);
+                            invokeChain(errorResolution, filterHandlers, new ServletRequestWrapper(request,
errorResolution.getContext(), requestInfo, errorResolution.getContextServiceId(), false),
this);
 
                             invokeSuper = false;
                         }
@@ -236,10 +234,10 @@ public final class Dispatcher implements
         private final DispatcherType type;
         private final RequestInfo requestInfo;
         private final ExtServletContext servletContext;
-        private final Long contextId;
+        private final long contextId;
         private final boolean asyncSupported;
 
-        public ServletRequestWrapper(HttpServletRequest req, ExtServletContext servletContext,
RequestInfo requestInfo, final Long contextId,
+        public ServletRequestWrapper(HttpServletRequest req, ExtServletContext servletContext,
RequestInfo requestInfo, final long contextId,
                 final boolean asyncSupported)
         {
             this(req, servletContext, requestInfo, null /* type */, contextId, asyncSupported);
@@ -370,10 +368,6 @@ public final class Dispatcher implements
         @Override
         public RequestDispatcher getRequestDispatcher(String path)
         {
-            if ( this.contextId == null )
-            {
-                return null;
-            }
             // See section 9.1 of Servlet 3.0 specification...
             if (path == null)
             {
@@ -592,8 +586,9 @@ public final class Dispatcher implements
         // Determine which servlet we should forward the request to...
         final PathResolution pr = this.handlerRegistry.resolveServlet(requestURI);
 
-        final HttpServletResponse wrappedResponse = new ServletResponseWrapper(req, res,
-                pr == null ? null : pr.handler);
+        final PerContextHandlerRegistry errorRegistry = (pr != null ? pr.handlerRegistry
: this.handlerRegistry.getBestMatchingRegistry(requestURI));
+        final String servletName = (pr != null ? pr.handler.getName() : null);
+        final HttpServletResponse wrappedResponse = new ServletResponseWrapper(req, res,
servletName, errorRegistry);
         if ( pr == null )
         {
             wrappedResponse.sendError(404);
@@ -634,14 +629,14 @@ public final class Dispatcher implements
     }
 
     @Override
-    public RequestDispatcher getNamedDispatcher(final Long contextId, final String name)
+    public RequestDispatcher getNamedDispatcher(final long contextId, final String name)
     {
         final ServletResolution resolution = this.handlerRegistry.resolveServletByName(contextId,
name);
         return resolution != null ? new RequestDispatcherImpl(resolution, null) : null;
     }
 
     @Override
-    public RequestDispatcher getRequestDispatcher(final Long contextId, String path)
+    public RequestDispatcher getRequestDispatcher(final long contextId, String path)
     {
         // See section 9.1 of Servlet 3.x specification...
         if (path == null || (!path.startsWith("/") && !"".equals(path)))

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherProvider.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherProvider.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherProvider.java
Wed May 27 12:50:15 2015
@@ -27,10 +27,10 @@ public interface RequestDispatcherProvid
     /**
      * @see ServletContext#getNamedDispatcher(String)
      */
-    RequestDispatcher getNamedDispatcher(Long contextId, String name);
+    RequestDispatcher getNamedDispatcher(long contextId, String name);
 
     /**
      * @see ServletContext#getRequestDispatcher(String)
      */
-    RequestDispatcher getRequestDispatcher(Long contextId, String path);
+    RequestDispatcher getRequestDispatcher(long contextId, String path);
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletContextWrapper.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletContextWrapper.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletContextWrapper.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletContextWrapper.java
Wed May 27 12:50:15 2015
@@ -28,12 +28,12 @@ class ServletContextWrapper extends ExtS
 {
     private final RequestDispatcherProvider provider;
 
-    private final Long contextId;
+    private final long contextId;
 
     /**
      * Creates a new {@link ServletContextWrapper} instance.
      */
-    public ServletContextWrapper(final Long contextId, final ExtServletContext delegate,
final RequestDispatcherProvider provider)
+    public ServletContextWrapper(final long contextId, final ExtServletContext delegate,
final RequestDispatcherProvider provider)
     {
         super(delegate);
 

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
Wed May 27 12:50:15 2015
@@ -35,7 +35,6 @@ import javax.servlet.http.HttpSessionCon
 import javax.servlet.http.HttpSessionEvent;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 
 /**
  * The session wrapper keeps track of the internal session, manages their attributes
@@ -87,9 +86,9 @@ public class HttpSessionWrapper implemen
      */
     private final boolean isNew;
 
-    public static boolean hasSession(final Long contextId, final HttpSession session)
+    public static boolean hasSession(final long contextId, final HttpSession session)
     {
-        final String sessionId = contextId == null ? String.valueOf(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID)
: String.valueOf(contextId);
+        final String sessionId = String.valueOf(contextId);
         return session.getAttribute(ATTR_CREATED + sessionId) != null;
     }
 
@@ -136,15 +135,15 @@ public class HttpSessionWrapper implemen
     /**
      * Creates a new {@link HttpSessionWrapper} instance.
      */
-    public HttpSessionWrapper(final Long contextId,
+    public HttpSessionWrapper(final long contextId,
             final HttpSession session,
             final ExtServletContext context,
             final boolean terminate)
     {
         this.delegate = session;
         this.context = context;
-        this.sessionId = contextId == null ? String.valueOf(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID)
: String.valueOf(contextId);
-        this.keyPrefix = contextId == null ? null : ATTR_PREFIX + this.sessionId + ".";
+        this.sessionId = String.valueOf(contextId);
+        this.keyPrefix = ATTR_PREFIX + this.sessionId + ".";
 
         if ( this.keyPrefix != null )
         {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
Wed May 27 12:50:15 2015
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.servlet.DispatcherType;
 
@@ -123,7 +124,10 @@ public final class HandlerRegistry
         return null;
     }
 
-    public ServletResolution getErrorHandler(String requestURI, Long serviceId, int code,
Throwable exception)
+    public @CheckForNull ServletResolution getErrorHandler(@Nonnull final String requestURI,
+            final Long serviceId,
+            final int code,
+            final Throwable exception)
     {
         final PerContextHandlerRegistry reg;
         if ( serviceId == null )
@@ -229,4 +233,21 @@ public final class HandlerRegistry
         }
         return false;
     }
+
+    public PerContextHandlerRegistry getBestMatchingRegistry(String requestURI)
+    {
+        // if the context is unknown, we use the first matching one!
+        PerContextHandlerRegistry found = null;
+        final List<PerContextHandlerRegistry> regs = this.registrations;
+        for(final PerContextHandlerRegistry r : regs)
+        {
+            final String path = r.isMatching(requestURI);
+            if ( path != null )
+            {
+                found = r;
+                break;
+            }
+        }
+        return found;
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
Wed May 27 12:50:15 2015
@@ -21,6 +21,7 @@ package org.apache.felix.http.base.inter
 import java.util.Collections;
 import java.util.Map;
 
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.apache.felix.http.base.internal.util.PatternUtil;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.context.ServletContextHelper;
@@ -88,6 +89,7 @@ public final class ServletContextHelperI
     {
         return super.isValid()
                 && PatternUtil.isValidSymbolicName(this.name)
+                && !HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME.equals(this.name)
                 && isValidPath();
     }
 

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/PerBundleHttpServiceImpl.java
Wed May 27 12:50:15 2015
@@ -286,7 +286,7 @@ public final class PerBundleHttpServiceI
         }
     }
 
-    private ExtServletContext getServletContext(HttpContext context)
+    public ExtServletContext getServletContext(HttpContext context)
     {
         if (context == null)
         {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/HttpServiceContextHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/HttpServiceContextHandler.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/HttpServiceContextHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/HttpServiceContextHandler.java
Wed May 27 12:50:15 2015
@@ -16,50 +16,103 @@
  */
 package org.apache.felix.http.base.internal.whiteboard;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import javax.servlet.ServletContext;
+
 import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.ContextHandler;
 import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
+import org.apache.felix.http.base.internal.service.PerBundleHttpServiceImpl;
 import org.osgi.framework.Bundle;
 
-public class HttpServiceContextHandler implements ContextHandler, Comparable<ContextHandler>
+public class HttpServiceContextHandler extends WhiteboardContextHandler
 {
-    /** The info object for the context. */
-    private final ServletContextHelperInfo info;
-
     private final PerContextHandlerRegistry registry;
 
-    private final ExtServletContext webContext;
+    private final HttpServiceFactory httpServiceFactory;
+
+    /** A map of all created servlet contexts. Each bundle gets it's own instance. */
+    private final Map<Long, ContextHolder> perBundleContextMap = new HashMap<Long,
ContextHolder>();
 
-    /** The http bundle. */
-    private final Bundle httpBundle;
+    private final ServletContext sharedContext;
 
     public HttpServiceContextHandler(final ServletContextHelperInfo info,
             final PerContextHandlerRegistry registry,
-            final ExtServletContext webContext,
+            final HttpServiceFactory httpServiceFactory,
+            final ServletContext webContext,
             final Bundle httpBundle)
     {
-        this.info = info;
+        super(info, webContext, httpBundle);
         this.registry = registry;
-        this.webContext = webContext;
-        this.httpBundle = httpBundle;
+        this.httpServiceFactory = httpServiceFactory;
+        this.sharedContext = webContext;
     }
 
     @Override
-    public ServletContextHelperInfo getContextInfo()
+    public PerContextHandlerRegistry getRegistry()
     {
-        return this.info;
+        return this.registry;
     }
 
     @Override
-    public int compareTo(final ContextHandler o)
+    public ServletContext getSharedContext()
     {
-        return this.info.compareTo(o.getContextInfo());
+        return this.sharedContext;
     }
 
     @Override
-    public PerContextHandlerRegistry getRegistry()
+    public @CheckForNull ExtServletContext getServletContext(@CheckForNull final Bundle bundle)
     {
-        return this.registry;
+        if ( bundle == null )
+        {
+            return null;
+        }
+        final Long key = bundle.getBundleId();
+        synchronized ( this.perBundleContextMap )
+        {
+            ContextHolder holder = this.perBundleContextMap.get(key);
+            if ( holder == null )
+            {
+                holder = new ContextHolder();
+                final PerBundleHttpServiceImpl service = (PerBundleHttpServiceImpl)this.httpServiceFactory.getService(bundle,
null);
+                holder.servletContext = service.getServletContext(service.createDefaultHttpContext());
+                holder.httpService = service;
+                this.perBundleContextMap.put(key, holder);
+            }
+            holder.counter++;
+
+            return holder.servletContext;
+        }
+    }
+
+    @Override
+    public void ungetServletContext(@Nonnull final Bundle bundle)
+    {
+        final Long key = bundle.getBundleId();
+        synchronized ( this.perBundleContextMap )
+        {
+            ContextHolder holder = this.perBundleContextMap.get(key);
+            if ( holder != null )
+            {
+                holder.counter--;
+                if ( holder.counter == 0 )
+                {
+                    this.perBundleContextMap.remove(key);
+                    holder.httpService.unregisterAll();
+                }
+            }
+        }
+    }
+
+    private static final class ContextHolder
+    {
+        public long counter;
+        public ExtServletContext servletContext;
+        public PerBundleHttpServiceImpl httpService;
     }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
Wed May 27 12:50:15 2015
@@ -24,28 +24,16 @@ import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.ContextHandler;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
-import org.apache.felix.http.base.internal.handler.ListenerHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler;
-import org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler;
-import org.apache.felix.http.base.internal.handler.WhiteboardServletHandler;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
-import org.apache.felix.http.base.internal.service.ResourceServlet;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceObjects;
 import org.osgi.service.http.context.ServletContextHelper;
 
-public final class WhiteboardContextHandler implements ContextHandler, Comparable<ContextHandler>
+public class WhiteboardContextHandler implements Comparable<WhiteboardContextHandler>
 {
     /** The info object for the context. */
     private final ServletContextHelperInfo info;
@@ -77,15 +65,26 @@ public final class WhiteboardContextHand
         return this.httpBundle.getBundleContext();
     }
 
-    @Override
     public ServletContextHelperInfo getContextInfo()
     {
         return this.info;
     }
 
     @Override
-    public int compareTo(final ContextHandler o)
+    public int compareTo(final WhiteboardContextHandler o)
     {
+        if ( this.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
+        {
+            if ( o.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
+            {
+                return 0;
+            }
+            return -1;
+        }
+        if ( o.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
+        {
+            return 1;
+        }
         return this.info.compareTo(o.getContextInfo());
     }
 
@@ -196,81 +195,9 @@ public final class WhiteboardContextHand
         }
     }
 
-    /**
-     * Create a servlet handler
-     * @param servletInfo The servlet info
-     * @return {@code null} if the servlet context could not be created, a handler otherwise
-     */
-    public ServletHandler getServletContextAndCreateServletHandler(@Nonnull final ServletInfo
servletInfo)
-    {
-        final ExtServletContext servletContext = this.getServletContext(servletInfo.getServiceReference().getBundle());
-        if ( servletContext == null )
-        {
-            return null;
-        }
-        final ServletHandler handler;
-        if ( servletInfo.isResource() )
-        {
-            handler = new HttpServiceServletHandler(
-                    this.info.getServiceId(),
-                    servletContext,
-                    servletInfo,
-                    new ResourceServlet(servletInfo.getPrefix()));
-        }
-        else
-        {
-            handler = new WhiteboardServletHandler(
-                this.info.getServiceId(),
-                servletContext,
-                servletInfo,
-                this.httpBundle.getBundleContext());
-        }
-        return handler;
-    }
-
-    /**
-     * Create a filter handler
-     * @param info The filter info
-     * @return {@code null} if the servlet context could not be created, a handler otherwise
-     */
-    public FilterHandler getServletContextAndCreateFilterHandler(@Nonnull final FilterInfo
info)
-    {
-        final ExtServletContext servletContext = this.getServletContext(info.getServiceReference().getBundle());
-        if ( servletContext == null )
-        {
-            return null;
-        }
-        final FilterHandler handler = new WhiteboardFilterHandler(
-                this.info.getServiceId(),
-                servletContext,
-                info,
-                this.httpBundle.getBundleContext());
-        return handler;
-    }
-
-    /**
-     * Create a listener handler
-     * @param info The listener info
-     * @return {@code null} if the servlet context could not be created, a handler otherwise
-     */
-    public ListenerHandler getServletContextAndCreateListenerHandler(@Nonnull final ListenerInfo
info)
-    {
-        final ExtServletContext servletContext = this.getServletContext(info.getServiceReference().getBundle());
-        if ( servletContext == null )
-        {
-            return null;
-        }
-        final ListenerHandler handler = new WhiteboardListenerHandler(
-                this.info.getServiceId(),
-                servletContext,
-                info,
-                this.httpBundle.getBundleContext());
-        return handler;
-    }
-
-    public void ungetServletContext(@Nonnull final WhiteboardServiceInfo<?> info)
+    public PerContextHandlerRegistry getRegistry()
     {
-        this.ungetServletContext(info.getServiceReference().getBundle());
+        return this.registry;
     }
 
     private static final class ContextHolder
@@ -279,10 +206,4 @@ public final class WhiteboardContextHand
         public ExtServletContext servletContext;
         public ServletContextHelper servletContextHelper;
     }
-
-    @Override
-    public PerContextHandlerRegistry getRegistry()
-    {
-        return this.registry;
-    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1682004&r1=1682003&r2=1682004&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
Wed May 27 12:50:15 2015
@@ -42,9 +42,13 @@ import javax.servlet.http.HttpSessionEve
 import org.apache.felix.http.base.internal.console.HttpServicePlugin;
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.handler.FilterHandler;
+import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
 import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
 import org.apache.felix.http.base.internal.handler.ListenerHandler;
 import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardServletHandler;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.runtime.AbstractInfo;
@@ -59,6 +63,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.runtime.dto.ServletContextDTOBuilder;
 import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.apache.felix.http.base.internal.service.HttpServiceRuntimeImpl;
+import org.apache.felix.http.base.internal.service.ResourceServlet;
 import org.apache.felix.http.base.internal.util.MimeTypes;
 import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
 import org.apache.felix.http.base.internal.whiteboard.tracker.ListenersTracker;
@@ -142,6 +147,15 @@ public final class WhiteboardManager
         props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/");
         props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
 
+        // add context for http service
+        final List<WhiteboardContextHandler> list = new ArrayList<WhiteboardContextHandler>();
+        final ServletContextHelperInfo info = new ServletContextHelperInfo(Integer.MAX_VALUE,
+                HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID,
+                HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME, "/", null);
+        list.add(new HttpServiceContextHandler(info, registry.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID),
+                httpServiceFactory, webContext, this.httpBundleContext.getBundle()));
+        this.contextMap.put(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME, list);
+
         this.defaultContextRegistration = httpBundleContext.registerService(
                 ServletContextHelper.class,
                 new ServiceFactory<ServletContextHelper>()
@@ -521,9 +535,25 @@ public final class WhiteboardManager
                     // we ignore this and treat it as an invisible service
                 }
             }
-            if ( visible && info.getContextSelectionFilter().match(h.getContextInfo().getServiceReference())
)
+            if ( visible )
             {
-                result.add(h);
+                if ( h.getContextInfo().getServiceReference() != null )
+                {
+                    if ( info.getContextSelectionFilter().match(h.getContextInfo().getServiceReference())
)
+                    {
+                        result.add(h);
+                    }
+                }
+                else
+                {
+                    final Map<String, String> props = new HashMap<String, String>();
+                    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, h.getContextInfo().getName());
+                    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, h.getContextInfo().getPath());
+                    if ( info.getContextSelectionFilter().matches(props) )
+                    {
+                        result.add(h);
+                    }
+                }
             }
         }
         return result;
@@ -635,52 +665,71 @@ public final class WhiteboardManager
             int failureCode = -1;
             if ( info instanceof ServletInfo )
             {
-                final ServletHandler servletHandler = handler.getServletContextAndCreateServletHandler((ServletInfo)info);
-                if ( servletHandler == null )
+                final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
+                if ( servletContext == null )
                 {
                     failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
                 }
                 else
                 {
+                    final ServletHandler servletHandler = new WhiteboardServletHandler(
+                        handler.getContextInfo().getServiceId(),
+                        servletContext,
+                        (ServletInfo)info,
+                        handler.getBundleContext());
                     handler.getRegistry().registerServlet(servletHandler);
                 }
             }
             else if ( info instanceof FilterInfo )
             {
-                final FilterHandler filterHandler = handler.getServletContextAndCreateFilterHandler((FilterInfo)info);
-                if ( filterHandler == null )
+                final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
+                if ( servletContext == null )
                 {
                     failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
                 }
                 else
                 {
+                    final FilterHandler filterHandler = new WhiteboardFilterHandler(
+                            handler.getContextInfo().getServiceId(),
+                            servletContext,
+                            (FilterInfo)info,
+                            handler.getBundleContext());
                     handler.getRegistry().registerFilter(filterHandler);
                 }
             }
             else if ( info instanceof ResourceInfo )
             {
                 final ServletInfo servletInfo = new ServletInfo((ResourceInfo)info);
-
-                final ServletHandler servleHandler = handler.getServletContextAndCreateServletHandler(servletInfo);
-                if ( servleHandler == null )
+                final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
+                if ( servletContext == null )
                 {
                     failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
                 }
                 else
                 {
+                    final ServletHandler servleHandler = new HttpServiceServletHandler(
+                            handler.getContextInfo().getServiceId(),
+                            servletContext,
+                            servletInfo,
+                            new ResourceServlet(servletInfo.getPrefix()));
                     handler.getRegistry().registerServlet(servleHandler);
                 }
             }
 
             else if ( info instanceof ListenerInfo )
             {
-                final ListenerHandler listenerHandler = handler.getServletContextAndCreateListenerHandler((ListenerInfo)info);
-                if ( listenerHandler == null )
+                final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
+                if ( servletContext == null )
                 {
                     failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
                 }
                 else
                 {
+                    final ListenerHandler listenerHandler = new WhiteboardListenerHandler(
+                            handler.getContextInfo().getServiceId(),
+                            servletContext,
+                            (ListenerInfo)info,
+                            handler.getBundleContext());
                     handler.getRegistry().registerListeners(listenerHandler);
                 }
             }
@@ -715,23 +764,23 @@ public final class WhiteboardManager
             if ( info instanceof ServletInfo )
             {
                 handler.getRegistry().unregisterServlet((ServletInfo)info, true);
-                handler.ungetServletContext(info);
+                handler.ungetServletContext(info.getServiceReference().getBundle());
             }
             else if ( info instanceof FilterInfo )
             {
                 handler.getRegistry().unregisterFilter((FilterInfo)info, true);
-                handler.ungetServletContext(info);
+                handler.ungetServletContext(info.getServiceReference().getBundle());
             }
             else if ( info instanceof ResourceInfo )
             {
                 handler.getRegistry().unregisterServlet(new ServletInfo((ResourceInfo)info),
true);
-                handler.ungetServletContext(info);
+                handler.ungetServletContext(info.getServiceReference().getBundle());
             }
 
             else if ( info instanceof ListenerInfo )
             {
                 handler.getRegistry().unregisterListeners((ListenerInfo) info);
-                handler.ungetServletContext(info);
+                handler.ungetServletContext(info.getServiceReference().getBundle());
             }
         }
         catch (final Exception e)
@@ -786,6 +835,7 @@ public final class WhiteboardManager
         final FailedDTOHolder failedDTOHolder = new FailedDTOHolder();
 
         final Collection<ServletContextDTO> contextDTOs = new ArrayList<ServletContextDTO>();
+/*
         // add the context for the http service
         final ServletContextHelperInfo info = new ServletContextHelperInfo(Integer.MAX_VALUE,
                 HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID,
@@ -795,7 +845,7 @@ public final class WhiteboardManager
         {
             contextDTOs.add(dto);
         }
-
+*/
         // get sort list of context handlers
         final List<WhiteboardContextHandler> contextHandlerList = new ArrayList<WhiteboardContextHandler>();
         synchronized ( this.contextMap )



Mime
View raw message