felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1775388 - in /felix/trunk/http: base/src/main/java/org/apache/felix/http/base/internal/ base/src/main/java/org/apache/felix/http/base/internal/runtime/ base/src/main/java/org/apache/felix/http/base/internal/service/ base/src/main/java/org/...
Date Wed, 21 Dec 2016 10:54:24 GMT
Author: cziegeler
Date: Wed Dec 21 10:54:24 2016
New Revision: 1775388

URL: http://svn.apache.org/viewvc?rev=1775388&view=rev
Log:
FELIX-5446 : Http Service ignores Whiteboard Servlet API Listeners

Removed:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/HttpSessionAttributeListenerManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/HttpSessionListenerManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/ServletContextAttributeListenerManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/ServletRequestAttributeListenerManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/ServletRequestListenerManager.java
Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.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/service/ServletContextImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/AbstractListenerManager.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
    felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java Wed Dec 21 10:54:24 2016
@@ -18,8 +18,6 @@
  */
 package org.apache.felix.http.base.internal;
 
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
@@ -27,14 +25,14 @@ import javax.servlet.http.HttpSessionLis
 /**
  * The <code>EventDispatcher</code> dispatches events sent from the servlet
  * container (embedded Jetty or container in which the framework is running
- * in bridged mode) to any {@link HttpSessionAttributeListener} or
+ * in bridged mode) to any {@link HttpSessionListener} or
  * {@link HttpSessionListener} services.
  *
  * TODO - only HttpSessionIdListener and HttpSessionListener should be
  *        required; HttpSessionListener only for getting notified of
  *        terminated session.
  */
-public class EventDispatcher implements HttpSessionAttributeListener, HttpSessionListener, HttpSessionIdListener
+public class EventDispatcher implements HttpSessionListener, HttpSessionIdListener
 {
     private volatile boolean active = false;
 
@@ -68,33 +66,6 @@ public class EventDispatcher implements
         }
     }
 
-    @Override
-    public void attributeAdded(final HttpSessionBindingEvent se)
-    {
-        if ( this.active )
-        {
-            controller.getSessionAttributeListener().attributeAdded(se);
-        }
-    }
-
-    @Override
-    public void attributeRemoved(final HttpSessionBindingEvent se)
-    {
-        if ( this.active )
-        {
-            controller.getSessionAttributeListener().attributeRemoved(se);
-        }
-    }
-
-    @Override
-    public void attributeReplaced(final HttpSessionBindingEvent se)
-    {
-        if ( this.active )
-        {
-            controller.getSessionAttributeListener().attributeReplaced(se);
-        }
-    }
-
     @Override
     public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId) {
         if ( this.active )

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java Wed Dec 21 10:54:24 2016
@@ -21,7 +21,6 @@ import java.util.Hashtable;
 import javax.annotation.Nonnull;
 import javax.servlet.Servlet;
 import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSessionAttributeListener;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
@@ -84,28 +83,19 @@ public final class HttpServiceController
 
                 @Override
                 public void sessionDestroyed(final HttpSessionEvent se) {
-                    httpServiceFactory.getSessionListener().sessionDestroyed(se);
+                    registry.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID).getEventListenerRegistry().sessionDestroyed(se);
                     whiteboardManager.sessionDestroyed(se.getSession(), HttpSessionWrapper.getSessionContextIds(se.getSession()));
                 }
 
                 @Override
                 public void sessionCreated(final HttpSessionEvent se) {
-                    httpServiceFactory.getSessionListener().sessionCreated(se);
+                    registry.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID).getEventListenerRegistry().sessionCreated(se);
                 }
             };
         }
         return httpSessionListener;
     }
 
-    /**
-     * TODO : we should try to remove this, it's only needed for
-     *        the proprietary support of the Felix implementation
-     */
-    HttpSessionAttributeListener getSessionAttributeListener()
-    {
-        return httpServiceFactory.getSessionAttributeListener();
-    }
-
     HttpSessionIdListener getSessionIdListener()
     {
         return new HttpSessionIdListener() {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java Wed Dec 21 10:54:24 2016
@@ -52,14 +52,18 @@ public class ListenerInfo extends Whiteb
         ALLOWED_INTERFACES.add(ServletRequestListener.class.getName());
     }
 
-    private final String enabled;
+    private final boolean enabled;
 
     private final String[] types;
 
+    /**
+     * Constructor for http whiteboard
+     * @param ref The service reference
+     */
     public ListenerInfo(final ServiceReference<EventListener> ref)
     {
         super(ref);
-        this.enabled = this.getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER);
+        this.enabled = "true".equalsIgnoreCase(this.getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
         final String[] objectClass = (String[])ref.getProperty(Constants.OBJECTCLASS);
         final Set<String> names = new HashSet<String>();
         for(final String name : objectClass)
@@ -72,10 +76,34 @@ public class ListenerInfo extends Whiteb
         this.types = names.toArray(new String[names.size()]);
     }
 
+    /**
+     * Constructor for Apache Felix proprietary listener support
+     * @param ref The service reference
+     * @param marker Just a marker parameter to distinguish from other constructor
+     */
+    public ListenerInfo(final ServiceReference<EventListener> ref, final boolean marker)
+    {
+        super(ref);
+        this.enabled = true;
+        final String[] objectClass = (String[])ref.getProperty(Constants.OBJECTCLASS);
+        final Set<String> names = new HashSet<String>();
+        for(final String name : objectClass)
+        {
+            if ( ALLOWED_INTERFACES.contains(name) )
+            {
+                names.add(name);
+            }
+        }
+        // remove interfaces not supported by Felix whiteboard
+        names.remove(HttpSessionIdListener.class.getName());
+        names.remove(ServletContextListener.class.getName());
+        this.types = names.toArray(new String[names.size()]);
+    }
+
     @Override
     public boolean isValid()
     {
-        return super.isValid() && "true".equalsIgnoreCase(this.enabled);
+        return super.isValid() && this.enabled;
     }
 
     public String[] getListenerTypes()

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java Wed Dec 21 10:54:24 2016
@@ -20,16 +20,10 @@ import java.util.Hashtable;
 
 import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionListener;
 
 import org.apache.felix.http.api.ExtHttpService;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
-import org.apache.felix.http.base.internal.service.listener.HttpSessionAttributeListenerManager;
-import org.apache.felix.http.base.internal.service.listener.HttpSessionListenerManager;
-import org.apache.felix.http.base.internal.service.listener.ServletContextAttributeListenerManager;
-import org.apache.felix.http.base.internal.service.listener.ServletRequestAttributeListenerManager;
-import org.apache.felix.http.base.internal.service.listener.ServletRequestListenerManager;
+import org.apache.felix.http.base.internal.service.listener.AbstractListenerManager;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -73,18 +67,14 @@ public final class HttpServiceFactory
     private final BundleContext bundleContext;
     private final boolean sharedContextAttributes;
 
-    private final ServletContextAttributeListenerManager contextAttributeListenerManager;
-    private final ServletRequestListenerManager requestListenerManager;
-    private final ServletRequestAttributeListenerManager requestAttributeListenerManager;
-    private final HttpSessionListenerManager sessionListenerManager;
-    private final HttpSessionAttributeListenerManager sessionAttributeListenerManager;
-
     private final Hashtable<String, Object> httpServiceProps = new Hashtable<String, Object>();
     private volatile ServletContext context;
     private volatile ServiceRegistration<?> httpServiceReg;
 
     private final HandlerRegistry handlerRegistry;
     private volatile SharedHttpServiceImpl sharedHttpService;
+    private volatile AbstractListenerManager listenerManager;
+
 
     public HttpServiceFactory(final BundleContext bundleContext,
             final HandlerRegistry handlerRegistry)
@@ -93,11 +83,6 @@ public final class HttpServiceFactory
         this.handlerRegistry = handlerRegistry;
         this.sharedContextAttributes = getBoolean(FELIX_HTTP_SHARED_SERVLET_CONTEXT_ATTRIBUTES);
 
-        this.contextAttributeListenerManager = new ServletContextAttributeListenerManager(bundleContext);
-        this.requestListenerManager = new ServletRequestListenerManager(bundleContext);
-        this.requestAttributeListenerManager = new ServletRequestAttributeListenerManager(bundleContext);
-        this.sessionListenerManager = new HttpSessionListenerManager(bundleContext);
-        this.sessionAttributeListenerManager = new HttpSessionAttributeListenerManager(bundleContext);
     }
 
     public void start(final ServletContext context,
@@ -113,11 +98,10 @@ public final class HttpServiceFactory
         }
 
         this.context = context;
-        this.contextAttributeListenerManager.open();
-        this.requestListenerManager.open();
-        this.requestAttributeListenerManager.open();
-        this.sessionListenerManager.open();
-        this.sessionAttributeListenerManager.open();
+        this.listenerManager = new AbstractListenerManager(bundleContext,
+                handlerRegistry
+                    .getRegistry(HTTP_SERVICE_CONTEXT_SERVICE_ID).getEventListenerRegistry());
+        this.listenerManager.open();
 
         this.sharedHttpService = new SharedHttpServiceImpl(handlerRegistry);
 
@@ -139,11 +123,11 @@ public final class HttpServiceFactory
         this.context = null;
         this.sharedHttpService = null;
 
-        this.contextAttributeListenerManager.close();
-        this.requestListenerManager.close();
-        this.requestAttributeListenerManager.close();
-        this.sessionListenerManager.close();
-        this.sessionAttributeListenerManager.close();
+        if ( this.listenerManager != null )
+        {
+            this.listenerManager.close();
+            this.listenerManager = null;
+        }
 
         this.httpServiceProps.clear();
     }
@@ -155,22 +139,17 @@ public final class HttpServiceFactory
         if (active) {
             // Store everything that we want to pass to the PerBundleHttpServiceImpl in local vars to avoid
             // a race condition where the service might be stopped while this method is executing.
-            SharedHttpServiceImpl sharedHttpSvc = this.sharedHttpService;
-            ServletContext servletCtx = this.context;
-            ServletContextAttributeListenerManager servletCtxAttrListenerMgr = this.contextAttributeListenerManager;
-            boolean sharedCtxAttrs = this.sharedContextAttributes;
-            ServletRequestListenerManager reqListenerMgr = this.requestListenerManager;
-            ServletRequestAttributeListenerManager reqAttrListenerMgr = this.requestAttributeListenerManager;
+            final SharedHttpServiceImpl sharedHttpSvc = this.sharedHttpService;
+            final ServletContext servletCtx = this.context;
+
+            final boolean sharedCtxAttrs = this.sharedContextAttributes;
 
             if ( active ) {
                 // Only return the service if we're still active
                 return new PerBundleHttpServiceImpl(bundle,
                         sharedHttpSvc,
                         servletCtx,
-                        servletCtxAttrListenerMgr,
-                        sharedCtxAttrs,
-                        reqListenerMgr,
-                        reqAttrListenerMgr);
+                        sharedCtxAttrs);
             }
         }
         return null;
@@ -186,21 +165,6 @@ public final class HttpServiceFactory
         }
     }
 
-    public ServletContextAttributeListenerManager getContextAttributeListener()
-    {
-        return contextAttributeListenerManager;
-    }
-
-    public HttpSessionListener getSessionListener()
-    {
-        return sessionListenerManager;
-    }
-
-    public HttpSessionAttributeListener getSessionAttributeListener()
-    {
-        return sessionAttributeListenerManager;
-    }
-
     public long getHttpServiceServiceId()
     {
         return (Long) this.httpServiceReg.getReference().getProperty(Constants.SERVICE_ID);

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=1775388&r1=1775387&r2=1775388&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 Dec 21 10:54:24 2016
@@ -27,10 +27,7 @@ import java.util.Set;
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletContextAttributeListener;
 import javax.servlet.ServletException;
-import javax.servlet.ServletRequestAttributeListener;
-import javax.servlet.ServletRequestListener;
 
 import org.apache.felix.http.api.ExtHttpService;
 import org.apache.felix.http.base.internal.context.ExtServletContext;
@@ -60,10 +57,7 @@ public final class PerBundleHttpServiceI
     public PerBundleHttpServiceImpl(final Bundle bundle,
             final SharedHttpServiceImpl sharedHttpService,
             final ServletContext context,
-            final ServletContextAttributeListener servletAttributeListener,
-            final boolean sharedContextAttributes,
-            final ServletRequestListener reqListener,
-            final ServletRequestAttributeListener reqAttrListener)
+            final boolean sharedContextAttributes)
     {
         if (bundle == null)
         {
@@ -75,12 +69,9 @@ public final class PerBundleHttpServiceI
         }
 
         this.bundle = bundle;
-        this.contextManager = new ServletContextManager(this.bundle, 
-        		context, 
-        		servletAttributeListener, 
-        		sharedContextAttributes, 
-        		reqListener, 
-        		reqAttrListener,
+        this.contextManager = new ServletContextManager(this.bundle,
+        		context,
+        		sharedContextAttributes,
         		sharedHttpService.getHandlerRegistry().getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID));
         this.sharedHttpService = sharedHttpService;
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextImpl.java Wed Dec 21 10:54:24 2016
@@ -36,7 +36,6 @@ import javax.servlet.RequestDispatcher;
 import javax.servlet.Servlet;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextAttributeEvent;
-import javax.servlet.ServletContextAttributeListener;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRegistration;
 import javax.servlet.ServletRequestAttributeListener;
@@ -69,33 +68,18 @@ public class ServletContextImpl implemen
     private final ServletContext context;
     private final HttpContext httpContext;
     private final Map<String, Object> attributes;
-    private final ServletContextAttributeListener attributeListener;
-    private final HttpSessionAttributeListener httpSessionAttributeListener;
-    private final HttpSessionListener httpSessionListener;
-    private final ServletRequestListener servletRequestListener;
-    private final ServletRequestAttributeListener servletRequestAttributeListener;
     private final PerContextHandlerRegistry handlerRegistry;
 
     public ServletContextImpl(final Bundle bundle,
             final ServletContext context,
             final HttpContext httpContext,
-            final ServletContextAttributeListener attributeListener,
             final boolean sharedAttributes,
-            final HttpSessionAttributeListener httpSessionAttributeListener,
-            final HttpSessionListener httpSessionListener,
-            final ServletRequestListener servletRequestListener,
-            final ServletRequestAttributeListener servletRequestAttributeListener,
             final PerContextHandlerRegistry registry)
     {
         this.bundle = bundle;
         this.context = context;
         this.httpContext = httpContext;
-        this.attributeListener = attributeListener;
         this.attributes = sharedAttributes ? null : new ConcurrentHashMap<String, Object>();
-        this.httpSessionAttributeListener = httpSessionAttributeListener;
-        this.httpSessionListener = httpSessionListener;
-        this.servletRequestAttributeListener = servletRequestAttributeListener;
-        this.servletRequestListener = servletRequestListener;
         this.handlerRegistry = registry;
     }
 
@@ -394,25 +378,25 @@ public class ServletContextImpl implemen
     @Override
     public HttpSessionListener getHttpSessionListener()
     {
-        return this.httpSessionListener;
+        return this.handlerRegistry.getEventListenerRegistry();
     }
 
     @Override
     public HttpSessionAttributeListener getHttpSessionAttributeListener()
     {
-        return this.httpSessionAttributeListener;
+        return this.handlerRegistry.getEventListenerRegistry();
     }
 
     @Override
     public ServletRequestListener getServletRequestListener()
     {
-        return this.servletRequestListener;
+        return this.handlerRegistry.getEventListenerRegistry();
     }
 
     @Override
     public ServletRequestAttributeListener getServletRequestAttributeListener()
     {
-        return this.servletRequestAttributeListener;
+        return this.handlerRegistry.getEventListenerRegistry();
     }
 
     @Override
@@ -455,7 +439,7 @@ public class ServletContextImpl implemen
 
         if (oldValue != null)
         {
-            this.attributeListener.attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
+            this.handlerRegistry.getEventListenerRegistry().attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
         }
     }
 
@@ -481,11 +465,11 @@ public class ServletContextImpl implemen
 
             if (oldValue == null)
             {
-                this.attributeListener.attributeAdded(new ServletContextAttributeEvent(this, name, value));
+                this.handlerRegistry.getEventListenerRegistry().attributeAdded(new ServletContextAttributeEvent(this, name, value));
             }
             else
             {
-                this.attributeListener.attributeReplaced(new ServletContextAttributeEvent(this, name, oldValue));
+                this.handlerRegistry.getEventListenerRegistry().attributeReplaced(new ServletContextAttributeEvent(this, name, oldValue));
             }
         }
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextManager.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ServletContextManager.java Wed Dec 21 10:54:24 2016
@@ -20,9 +20,6 @@ import java.util.Map;
 import java.util.WeakHashMap;
 
 import javax.servlet.ServletContext;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletRequestAttributeListener;
-import javax.servlet.ServletRequestListener;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
@@ -33,27 +30,18 @@ public final class ServletContextManager
 {
     private final Bundle bundle;
     private final ServletContext context;
-    private final ServletContextAttributeListener attributeListener;
     private final Map<HttpContext, ExtServletContext> contextMap;
     private final boolean sharedAttributes;
-    private final ServletRequestListener servletRequestListener;
-    private final ServletRequestAttributeListener servletRequestAttributeListener;
     private final PerContextHandlerRegistry handlerRegistry;
 
     public ServletContextManager(
             final Bundle bundle,
             final ServletContext context,
-            final ServletContextAttributeListener attributeListener,
             final boolean sharedAttributes,
-            final ServletRequestListener servletRequestListener,
-            final ServletRequestAttributeListener servletRequestAttributeListener,
             final PerContextHandlerRegistry registry)
     {
         this.bundle = bundle;
         this.context = context;
-        this.attributeListener = attributeListener;
-        this.servletRequestAttributeListener = servletRequestAttributeListener;
-        this.servletRequestListener = servletRequestListener;
         // FELIX-4424 : avoid classloader leakage through HttpContext, for now this is sufficient,
         // the real fix should be to remove ExtServletContext's when the usage count of HttpContext
         // drops to zero.
@@ -81,12 +69,7 @@ public final class ServletContextManager
         ExtServletContext context = new ServletContextImpl(this.bundle,
                 this.context,
                 httpContext,
-                this.attributeListener,
                 this.sharedAttributes,
-                null,
-                null,
-                servletRequestListener,
-                servletRequestAttributeListener,
                 handlerRegistry);
         this.contextMap.put(httpContext, context);
         return context;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/AbstractListenerManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/AbstractListenerManager.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/AbstractListenerManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/listener/AbstractListenerManager.java Wed Dec 21 10:54:24 2016
@@ -18,99 +18,116 @@
  */
 package org.apache.felix.http.base.internal.service.listener;
 
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.EventListener;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletRequestAttributeListener;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionListener;
 
+import org.apache.felix.http.base.internal.handler.ListenerHandler;
+import org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.registry.EventListenerRegistry;
+import org.apache.felix.http.base.internal.runtime.ListenerInfo;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
+ * Implementation of the Apache Felix proprietary whiteboard for listeners
+ *
  * @deprecated
  */
 @Deprecated
-public class AbstractListenerManager<ListenerType> extends ServiceTracker<ListenerType, ListenerType>
+public class AbstractListenerManager extends ServiceTracker<EventListener, ServiceReference<EventListener>>
 {
 
-    private ArrayList<ListenerType> allContextListeners;
+    /** Map containing all info objects reported from the trackers. */
+    private final Map<Long, ListenerInfo> allInfos = new ConcurrentHashMap<Long, ListenerInfo>();
 
     private final Object lock = new Object();
 
-    protected AbstractListenerManager(final BundleContext context, final Filter filter)
-    {
-        super(context, filter, null);
-    }
+    private final EventListenerRegistry registry;
 
-    @SuppressWarnings("unchecked")
-    protected final Iterator<ListenerType> getContextListeners()
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
     {
-        ArrayList<ListenerType> result = allContextListeners;
-        if (result == null)
+        try
         {
-            synchronized (lock)
-            {
-                if (allContextListeners == null)
-                {
-                    Object[] services = getServices();
-                    if (services != null && services.length > 0)
-                    {
-                        result = new ArrayList<ListenerType>(services.length);
-                        for (Object service : services)
-                        {
-                            result.add((ListenerType) service);
-                        }
-                    }
-                    else
-                    {
-                        result = new ArrayList<ListenerType>(0);
-                    }
-                    this.allContextListeners = result;
-                }
-                else
-                {
-                    result = this.allContextListeners;
-                }
-            }
+            return btx.createFilter(String.format("(&" +
+                                                   "(!(%s=*))" +
+                                                   "(|(objectClass=%s)(objectClass=%s)(objectClass=%s)(objectClass=%s)(objectClass=%s))" +
+                                                   ")",
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER,
+                    HttpSessionAttributeListener.class.getName(),
+                    HttpSessionListener.class.getName(),
+                    ServletContextAttributeListener.class.getName(),
+                    ServletRequestAttributeListener.class.getName(),
+                    ServletRequestListener.class.getName()));
         }
-        return result.iterator();
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if, we get an NPE which is fine
+    }
+
+    public AbstractListenerManager(final BundleContext context,
+            final EventListenerRegistry registry)
+    {
+        super(context, createFilter(context), null);
+        this.registry = registry;
     }
 
     @Override
-    public ListenerType addingService(ServiceReference<ListenerType> reference)
+    public ServiceReference<EventListener> addingService(final ServiceReference<EventListener> reference)
     {
-        final ListenerType result = super.addingService(reference);
-        if ( result != null ) {
-            SystemLogger.warning("Deprecation warning: " +
-                "Listener registered through Apache Felix whiteboard service: " + reference +
-                ". Please change your code to the OSGi Http Whiteboard Service.", null);
-        }
+        SystemLogger.warning("Deprecation warning: " +
+            "Listener registered through Apache Felix whiteboard service: " + reference +
+            ". Please change your code to the OSGi Http Whiteboard Service.", null);
+
+        final ListenerInfo info = new ListenerInfo(reference, true);
+        this.allInfos.put((Long)reference.getProperty(Constants.SERVICE_ID), info);
+
+        final ListenerHandler listenerHandler = new WhiteboardListenerHandler(
+                HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID,
+                null, // context is only relevant for ServletContextListener which is not supported here
+                info,
+                this.context);
         synchronized (lock)
         {
-            allContextListeners = null;
+            registry.addListeners(listenerHandler);
         }
 
-        return result;
+        return reference;
     }
 
     @Override
-    public void modifiedService(ServiceReference<ListenerType> reference, ListenerType service)
+    public void modifiedService(final ServiceReference<EventListener> reference, final ServiceReference<EventListener> service)
     {
-        super.modifiedService(reference, service);
-        synchronized (lock)
+        synchronized ( lock )
         {
-            allContextListeners = null;
+            this.removedService(reference, service);
+            this.addingService(reference);
         }
     }
 
     @Override
-    public void removedService(ServiceReference<ListenerType> reference, ListenerType service)
+    public void removedService(final ServiceReference<EventListener> reference, final ServiceReference<EventListener> service)
     {
-        super.removedService(reference, service);
-        synchronized (lock)
-        {
-            allContextListeners = null;
+        final ListenerInfo info = this.allInfos.remove(reference.getProperty(Constants.SERVICE_ID));
+        if ( info != null ) {
+            synchronized (lock)
+            {
+                registry.removeListeners(info);
+            }
         }
     }
 }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java Wed Dec 21 10:54:24 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.felix.http.base.internal.context;
 
+import static org.mockito.Mockito.when;
+
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Arrays;
@@ -43,6 +45,12 @@ import javax.servlet.descriptor.JspConfi
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.felix.http.base.internal.handler.ListenerHandler;
+import org.apache.felix.http.base.internal.registry.EventListenerRegistry;
+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.ListenerInfo;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 import org.apache.felix.http.base.internal.service.ServletContextImpl;
 import org.junit.Assert;
 import org.junit.Before;
@@ -126,7 +134,7 @@ public class ServletContextImplTest
     private class MockServletContext implements ServletContext
     {
 
-        private Dictionary attributes = new Hashtable();
+        private Dictionary<String, Object> attributes = new Hashtable<String, Object>();
 
         @Override
         public FilterRegistration.Dynamic addFilter(String name, Class<? extends Filter> type)
@@ -214,7 +222,7 @@ public class ServletContextImplTest
         }
 
         @Override
-        public Enumeration getAttributeNames()
+        public Enumeration<String> getAttributeNames()
         {
             return attributes.keys();
         }
@@ -340,7 +348,7 @@ public class ServletContextImplTest
         }
 
         @Override
-        public Set getResourcePaths(String path)
+        public Set<String> getResourcePaths(String path)
         {
             return null;
         }
@@ -351,6 +359,7 @@ public class ServletContextImplTest
             return null;
         }
 
+        @Deprecated
         @Override
         public Servlet getServlet(String name)
         {
@@ -363,6 +372,8 @@ public class ServletContextImplTest
             return null;
         }
 
+        @SuppressWarnings("deprecation")
+        @Deprecated
         @Override
         public Enumeration getServletNames()
         {
@@ -381,6 +392,8 @@ public class ServletContextImplTest
             return null;
         }
 
+        @SuppressWarnings("deprecation")
+        @Deprecated
         @Override
         public Enumeration getServlets()
         {
@@ -393,6 +406,8 @@ public class ServletContextImplTest
             return null;
         }
 
+        @SuppressWarnings("deprecation")
+        @Deprecated
         @Override
         public void log(Exception exception, String msg)
         {
@@ -443,6 +458,7 @@ public class ServletContextImplTest
     private HttpContext httpContext;
     private AttributeListener listener;
     private ServletContextImpl context;
+    private PerContextHandlerRegistry contextRegistry;
 
     @Before
     public void setUp()
@@ -451,8 +467,20 @@ public class ServletContextImplTest
         ServletContext globalContext = new MockServletContext();
         this.httpContext = Mockito.mock(HttpContext.class);
         this.listener = new AttributeListener();
-        this.context = new ServletContextImpl(this.bundle, globalContext, this.httpContext, this.listener, false,
-                null, null, null, null, null);
+        final HandlerRegistry reg = new HandlerRegistry();
+        reg.init();
+        contextRegistry = reg.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID);
+        final EventListenerRegistry eventReg = contextRegistry.getEventListenerRegistry();
+        final ListenerInfo info = Mockito.mock(ListenerInfo.class);
+        when(info.getListenerTypes()).thenReturn(new String[] {ServletContextAttributeListener.class.getName()});
+        when(info.isListenerType(ServletContextAttributeListener.class.getName())).thenReturn(true);
+        final ListenerHandler handler = Mockito.mock(ListenerHandler.class);
+        when(handler.getListenerInfo()).thenReturn(info);
+        when(handler.getContextServiceId()).thenReturn(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID);
+        when(handler.getListener()).thenReturn(listener);
+        when(handler.init()).thenReturn(-1);
+        eventReg.addListeners(handler);
+        this.context = new ServletContextImpl(this.bundle, globalContext, this.httpContext, false, contextRegistry);
     }
 
     @Test
@@ -484,7 +512,7 @@ public class ServletContextImplTest
     @Test
     public void testGetAttributeNames()
     {
-        Enumeration e = this.context.getAttributeNames();
+        Enumeration<String> e = this.context.getAttributeNames();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
 
@@ -506,7 +534,7 @@ public class ServletContextImplTest
     @Test
     public void testGetInitParameterNames()
     {
-        Enumeration e = this.context.getInitParameterNames();
+        Enumeration<String> e = this.context.getInitParameterNames();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
     }
@@ -553,7 +581,7 @@ public class ServletContextImplTest
         HashSet<String> paths = new HashSet<String>(Arrays.asList("/some/path/1", "/some/path/2"));
         Mockito.when(this.bundle.getEntryPaths("some/path")).thenReturn(Collections.enumeration(paths));
 
-        Set set = this.context.getResourcePaths("/some/path");
+        Set<String> set = this.context.getResourcePaths("/some/path");
         Assert.assertNotNull(set);
         Assert.assertEquals(2, set.size());
         Assert.assertTrue(set.contains("/some/path/1"));
@@ -569,7 +597,7 @@ public class ServletContextImplTest
     @Test
     public void testGetServletNames()
     {
-        Enumeration e = this.context.getServletNames();
+        Enumeration<String> e = this.context.getServletNames();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
     }
@@ -577,7 +605,7 @@ public class ServletContextImplTest
     @Test
     public void testGetServlets()
     {
-        Enumeration e = this.context.getServlets();
+        Enumeration<Servlet> e = this.context.getServlets();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
     }
@@ -586,10 +614,10 @@ public class ServletContextImplTest
     public void testGetSharedAttribute()
     {
         ServletContext globalContext = new MockServletContext();
-        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, listener, true,
-                null, null, null, null, null);
-        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, listener, true,
-                null, null, null, null, null);
+        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, true,
+                contextRegistry);
+        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, true,
+                contextRegistry);
 
         Assert.assertNull(ctx1.getAttribute("key1"));
         Assert.assertNull(ctx2.getAttribute("key1"));
@@ -697,12 +725,12 @@ public class ServletContextImplTest
     public void testGetSharedAttributeNames()
     {
         ServletContext globalContext = new MockServletContext();
-        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, listener, true,
-                null, null, null, null, null);
-        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, listener, true,
-                null, null, null, null, null);
+        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, true,
+                contextRegistry);
+        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, true,
+                contextRegistry);
 
-        Enumeration e = ctx1.getAttributeNames();
+        Enumeration<String> e = ctx1.getAttributeNames();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
         e = ctx2.getAttributeNames();
@@ -735,10 +763,10 @@ public class ServletContextImplTest
     public void testGetUnsharedAttribute()
     {
         ServletContext globalContext = new MockServletContext();
-        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, listener, false,
-                null, null, null, null, null);
-        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, listener, false,
-                null, null, null, null, null);
+        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, false,
+                contextRegistry);
+        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, false,
+                contextRegistry);
 
         Assert.assertNull(ctx1.getAttribute("key1"));
         Assert.assertNull(ctx2.getAttribute("key1"));
@@ -783,12 +811,12 @@ public class ServletContextImplTest
     public void testGetUnsharedAttributeNames()
     {
         ServletContext globalContext = new MockServletContext();
-        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, listener, false,
-                null, null, null, null, null);
-        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, listener, false,
-                null, null, null, null, null);
+        ServletContext ctx1 = new ServletContextImpl(bundle, globalContext, httpContext, false,
+                contextRegistry);
+        ServletContext ctx2 = new ServletContextImpl(bundle, globalContext, httpContext, false,
+                contextRegistry);
 
-        Enumeration e = ctx1.getAttributeNames();
+        Enumeration<String> e = ctx1.getAttributeNames();
         Assert.assertNotNull(e);
         Assert.assertFalse(e.hasMoreElements());
         e = ctx2.getAttributeNames();

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java Wed Dec 21 10:54:24 2016
@@ -35,8 +35,7 @@ public class ServletContextManagerTest
     {
         Bundle bundle = Mockito.mock(Bundle.class);
         ServletContext globalContext = Mockito.mock(ServletContext.class);
-        this.manager = new ServletContextManager(bundle, globalContext, null, false,
-                null, null, null);
+        this.manager = new ServletContextManager(bundle, globalContext, false, null);
     }
 
     @Test

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java Wed Dec 21 10:54:24 2016
@@ -44,7 +44,9 @@ public class HttpServiceFactoryTest {
                 return FrameworkUtil.createFilter((String) invocation.getArguments()[0]);
             }
         });
-        HttpServiceFactory hsf = new HttpServiceFactory(bc, new HandlerRegistry());
+        final HandlerRegistry reg = new HandlerRegistry();
+        reg.init();
+        HttpServiceFactory hsf = new HttpServiceFactory(bc, reg);
 
         Assert.assertNull("Not yet active",
                 hsf.getService(Mockito.mock(Bundle.class), null));

Modified: felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java?rev=1775388&r1=1775387&r2=1775388&view=diff
==============================================================================
--- felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java (original)
+++ felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java Wed Dec 21 10:54:24 2016
@@ -423,7 +423,9 @@ public class EventListenerTest extends B
         };
 
         // register with default context
-        final ServiceRegistration<ServletRequestListener> reg = m_context.registerService(ServletRequestListener.class, listener, getListenerProps());
+        final ServiceRegistration<ServletRequestListener> reg1 = m_context.registerService(ServletRequestListener.class, listener, getListenerProps());
+        // register proprietary listener
+        final ServiceRegistration<ServletRequestListener> reg2 = m_context.registerService(ServletRequestListener.class, listener, null);
 
         // register test servlet with default context
         ServiceRegistration<Servlet> regS = m_context.registerService(Servlet.class,
@@ -447,7 +449,8 @@ public class EventListenerTest extends B
         }
         finally
         {
-            reg.unregister();
+            reg1.unregister();
+            reg2.unregister();
             regS.unregister();
         }
     }
@@ -480,7 +483,9 @@ public class EventListenerTest extends B
         final Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true");
         props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
-        final ServiceRegistration<ServletRequestListener> reg = m_context.registerService(ServletRequestListener.class, listener, getListenerProps());
+        final ServiceRegistration<ServletRequestListener> reg = m_context.registerService(ServletRequestListener.class, listener, props);
+        // register proprietary listener
+        final ServiceRegistration<ServletRequestListener> reg2 = m_context.registerService(ServletRequestListener.class, listener, null);
 
         // register test servlet with http service
         getHttpService().registerServlet("/test", new TestServlet()
@@ -497,13 +502,16 @@ public class EventListenerTest extends B
         {
             assertEquals(0, list.size());
             assertContent(SC_OK, null, createURL("/test"));
-// TODO            assertEquals(2, list.size());
-// TODO            assertEquals("INIT", list.get(0));
-// TODO            assertEquals("DESTROY", list.get(1));
+            assertEquals(4, list.size());
+            assertEquals("INIT", list.get(0));
+            assertEquals("INIT", list.get(1));
+            assertEquals("DESTROY", list.get(2));
+            assertEquals("DESTROY", list.get(3));
         }
         finally
         {
             reg.unregister();
+            reg2.unregister();
             getHttpService().unregister("/test");
         }
     }



Mime
View raw message