Author: cziegeler
Date: Mon Sep 19 06:48:29 2016
New Revision: 1761389

URL: http://svn.apache.org/viewvc?rev=1761389&view=rev
Log:
Merge changes from trunk

Modified:
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
    
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/WebAppBundleContext.java
    
felix/sandbox/http-jetty-r7/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConfigMetaTypeProvider.java
 Mon Sep 19 06:48:29 2016
@@ -315,6 +315,12 @@ class ConfigMetaTypeProvider implements
                 -1,
                 
bundle.getBundleContext().getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_MAX_AGE)));
 
+        adList.add(new 
AttributeDefinitionImpl(JettyConfig.FELIX_HTTP_SERVICE_NAME,
+                "HTTP Service Name",
+                "HTTP Service Name used in service filter to target specific 
HTTP instance. Default is null.",
+                null,
+                
bundle.getBundleContext().getProperty(JettyConfig.FELIX_HTTP_SERVICE_NAME)));
+
         return new ObjectClassDefinition()
         {
 

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/ConnectorFactoryTracker.java
 Mon Sep 19 06:48:29 2016
@@ -26,13 +26,13 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class ConnectorFactoryTracker extends ServiceTracker
+public class ConnectorFactoryTracker extends ServiceTracker<ConnectorFactory, 
Connector>
 {
     private final Server server;
 
     public ConnectorFactoryTracker(final BundleContext context, final Server 
server)
     {
-        super(context, ConnectorFactory.class.getName(), null);
+        super(context, ConnectorFactory.class, null);
         this.server = server;
     }
 
@@ -48,7 +48,7 @@ public class ConnectorFactoryTracker ext
     }
 
     @Override
-    public Object addingService(ServiceReference reference)
+    public Connector addingService(ServiceReference<ConnectorFactory> 
reference)
     {
         ConnectorFactory factory = (ConnectorFactory) 
super.addingService(reference);
         Connector connector = factory.createConnector(server);
@@ -68,9 +68,9 @@ public class ConnectorFactoryTracker ext
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service)
+    public void removedService(ServiceReference<ConnectorFactory> reference, 
Connector service)
     {
-        Connector connector = (Connector) service;
+        Connector connector = service;
         if (connector.isStarted())
         {
             try

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
 Mon Sep 19 06:48:29 2016
@@ -25,6 +25,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedServiceFactory;
 
 public final class JettyActivator extends AbstractHttpActivator
 {
@@ -32,6 +33,7 @@ public final class JettyActivator extend
 
     private ServiceRegistration<?> metatypeReg;
     private ServiceRegistration<LoadBalancerCustomizerFactory> 
loadBalancerCustomizerFactoryReg;
+    private JettyManagedServiceFactory jettyServiceFactory;
 
     @Override
     protected void doStart() throws Exception
@@ -58,7 +60,7 @@ public final class JettyActivator extend
                         // nothing to do
                     }
                 }, properties);
-        this.jetty = new JettyService(getBundleContext(), 
getDispatcherServlet(), getEventDispatcher(), getHttpServiceController());
+        this.jetty = new JettyService(getBundleContext(), 
getHttpServiceController());
         this.jetty.start();
 
         final Dictionary<String, Object> propertiesCustomizer = new 
Hashtable<String, Object>();
@@ -83,6 +85,8 @@ public final class JettyActivator extend
                         // nothing to do
                     }
                 }, propertiesCustomizer);
+
+        this.jettyServiceFactory = new 
JettyManagedServiceFactory(this.getBundleContext());
     }
 
     @Override
@@ -99,6 +103,11 @@ public final class JettyActivator extend
             loadBalancerCustomizerFactoryReg.unregister();
             loadBalancerCustomizerFactoryReg = null;
         }
+        if ( jettyServiceFactory != null )
+        {
+            jettyServiceFactory.stop();
+            jettyServiceFactory = null;
+        }
 
         super.doStop();
     }

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
 Mon Sep 19 06:48:29 2016
@@ -25,7 +25,6 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Properties;
 
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.osgi.framework.BundleContext;
@@ -137,13 +136,13 @@ public final class JettyConfig
 
     /** Felix specific property to control whether to enable Proxy/Load 
Balancer Connection */
     public static final String FELIX_PROXY_LOAD_BALANCER_CONNECTION_ENABLE = 
"org.apache.felix.proxy.load.balancer.connection.enable";
-    
+
     /** Felix specific property to configure the session cookie httpOnly flag 
*/
     public static final String FELIX_JETTY_SESSION_COOKIE_HTTP_ONLY = 
"org.apache.felix.https.jetty.session.cookie.httpOnly";
-    
+
     /** Felix specific property to configure the session cookie secure flag */
     public static final String FELIX_JETTY_SESSION_COOKIE_SECURE = 
"org.apache.felix.https.jetty.session.cookie.secure";
-    
+
     /** Felix specific property to configure session id path parameter*/
     public static final String 
FELIX_JETTY_SERVLET_SESSION_ID_PATH_PARAMETER_NAME = 
"org.eclipse.jetty.servlet.SessionIdPathParameterName";
 
@@ -162,6 +161,10 @@ public final class JettyConfig
     /**  Felix specific property to configure session max age */
     public static final String FELIX_JETTY_SERVLET_SESSION_MAX_AGE = 
"org.eclipse.jetty.servlet.MaxAge";
 
+    /** Felix specific property to set HTTP instance name. */
+    public static final String FELIX_HTTP_SERVICE_NAME = 
"org.apache.felix.http.name";
+
+
     private static String validateContextPath(String ctxPath)
     {
         // undefined, empty, or root context path
@@ -193,9 +196,9 @@ public final class JettyConfig
      * This map is indexed by String objects (the property names) and
      * the values are just objects as provided by the configuration.
      */
-    private volatile Dictionary config;
+    private volatile Dictionary<String, ?> config;
 
-    public JettyConfig(BundleContext context)
+    public JettyConfig(final BundleContext context)
     {
         this.context = context;
         reset();
@@ -414,6 +417,11 @@ public final class JettyConfig
         return getBooleanProperty(FELIX_JETTY_RENEGOTIATION_ALLOWED, false);
     }
 
+    public String getHttpServiceName()
+    {
+       return (String) getProperty(FELIX_HTTP_SERVICE_NAME);
+    }
+
     public void reset()
     {
         update(null);
@@ -425,6 +433,10 @@ public final class JettyConfig
         props.put(HTTPS_PORT, Integer.toString(getHttpsPort()));
         props.put(FELIX_HTTP_ENABLE, Boolean.toString(isUseHttp()));
         props.put(FELIX_HTTPS_ENABLE, Boolean.toString(isUseHttps()));
+        if (getHttpServiceName() != null)
+        {
+                       props.put(FELIX_HTTP_SERVICE_NAME, 
getHttpServiceName());
+        }
     }
 
     /**
@@ -433,15 +445,15 @@ public final class JettyConfig
      * @param props the dictionary with the new configuration values, can be 
<code>null</code> to reset this configuration to its defaults.
      * @return <code>true</code> if the configuration was updated due to a 
changed value, or <code>false</code> if no change was found.
      */
-    public boolean update(Dictionary props)
+    public boolean update(Dictionary<String, ?> props)
     {
         if (props == null)
         {
-            props = new Properties();
+            props = new Hashtable<>();
         }
 
         // FELIX-4312 Check whether there's something changed in our 
configuration...
-        Dictionary currentConfig = this.config;
+        Dictionary<String, ?> currentConfig = this.config;
         if (currentConfig == null || !props.equals(currentConfig))
         {
             this.config = props;
@@ -566,9 +578,9 @@ public final class JettyConfig
         return port;
     }
 
-    private Object getProperty(String name)
+    private Object getProperty(final String name)
     {
-        Dictionary conf = this.config;
+        Dictionary<String, ?> conf = this.config;
         Object value = (conf != null) ? conf.get(name) : null;
         if (value == null)
         {

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedService.java
 Mon Sep 19 06:48:29 2016
@@ -36,12 +36,12 @@ public class JettyManagedService impleme
     }
 
     @Override
-    public ManagedService getService(Bundle bundle, ServiceRegistration 
registration)
+    public ManagedService getService(Bundle bundle, 
ServiceRegistration<ManagedService> registration)
     {
         return new ManagedService()
         {
             @Override
-            public void updated(Dictionary properties)
+            public void updated(Dictionary<String, ?> properties)
             {
                 jettyService.updated(properties);
             }
@@ -49,7 +49,7 @@ public class JettyManagedService impleme
     }
 
     @Override
-    public void ungetService(Bundle bundle, ServiceRegistration registration, 
ManagedService service)
+    public void ungetService(Bundle bundle, 
ServiceRegistration<ManagedService> registration, ManagedService service)
     {
         // just have the reference dropped, nothing to cleanup
     }

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
 Mon Sep 19 06:48:29 2016
@@ -39,8 +39,6 @@ import javax.servlet.ServletContext;
 import javax.servlet.SessionCookieConfig;
 import javax.servlet.SessionTrackingMode;
 
-import org.apache.felix.http.base.internal.DispatcherServlet;
-import org.apache.felix.http.base.internal.EventDispatcher;
 import org.apache.felix.http.base.internal.HttpServiceController;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.eclipse.jetty.http.HttpVersion;
@@ -77,7 +75,7 @@ import org.osgi.util.tracker.BundleTrack
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
-public final class JettyService extends 
AbstractLifeCycle.AbstractLifeCycleListener implements BundleTrackerCustomizer, 
ServiceTrackerCustomizer
+public final class JettyService extends 
AbstractLifeCycle.AbstractLifeCycleListener
 {
     /** PID for configuration of the HTTP service. */
     public static final String PID = "org.apache.felix.http";
@@ -91,32 +89,27 @@ public final class JettyService extends
 
     private final JettyConfig config;
     private final BundleContext context;
-    private final DispatcherServlet dispatcher;
     private final HttpServiceController controller;
     private final Map<String, Deployment> deployments;
     private final ExecutorService executor;
 
-    private ServiceRegistration<?> configServiceReg;
-    private Server server;
-    private ContextHandlerCollection parent;
-    private EventDispatcher eventDispatcher;
-    private MBeanServerTracker mbeanServerTracker;
-    private BundleTracker bundleTracker;
-    private ServiceTracker eventAdmintTracker;
-    private ServiceTracker connectorTracker;
-    private ServiceTracker loadBalancerCustomizerTracker;
-    private CustomizerWrapper customizerWrapper;
-    private EventAdmin eventAdmin;
+    private volatile ServiceRegistration<?> configServiceReg;
+    private volatile Server server;
+    private volatile ContextHandlerCollection parent;
+    private volatile MBeanServerTracker mbeanServerTracker;
+    private volatile BundleTracker<Deployment> bundleTracker;
+    private volatile ServiceTracker<EventAdmin, EventAdmin> eventAdmintTracker;
+    private volatile ConnectorFactoryTracker connectorTracker;
+    private volatile LoadBalancerCustomizerFactoryTracker 
loadBalancerCustomizerTracker;
+    private volatile CustomizerWrapper customizerWrapper;
+    private volatile EventAdmin eventAdmin;
+    private boolean registerManagedService = true;
 
     public JettyService(final BundleContext context,
-            final DispatcherServlet dispatcher,
-            final EventDispatcher eventDispatcher,
             final HttpServiceController controller)
     {
         this.context = context;
         this.config = new JettyConfig(this.context);
-        this.dispatcher = dispatcher;
-        this.eventDispatcher = eventDispatcher;
         this.controller = controller;
         this.deployments = new LinkedHashMap<String, Deployment>();
         this.executor = Executors.newSingleThreadExecutor(new ThreadFactory()
@@ -131,19 +124,101 @@ public final class JettyService extends
         });
     }
 
+    public JettyService(final BundleContext context,
+            final HttpServiceController controller,
+            final Dictionary<String,?> props)
+    {
+       this(context, controller);
+       this.config.update(props);
+       this.registerManagedService = false;
+    }
+
     public void start() throws Exception
     {
         // FELIX-4422: start Jetty synchronously...
         startJetty();
 
-        Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(Constants.SERVICE_PID, PID);
-        this.configServiceReg = 
this.context.registerService("org.osgi.service.cm.ManagedService", new 
JettyManagedService(this), props);
+        if (this.registerManagedService) {
+                       final Dictionary<String, Object> props = new 
Hashtable<String, Object>();
+                       props.put(Constants.SERVICE_PID, PID);
+                       this.configServiceReg = 
this.context.registerService("org.osgi.service.cm.ManagedService",
+                               new JettyManagedService(this), props);
+        }
 
-        this.eventAdmintTracker = new ServiceTracker(this.context, 
EventAdmin.class.getName(), this);
+        this.eventAdmintTracker = new ServiceTracker<EventAdmin, 
EventAdmin>(this.context, EventAdmin.class,
+                new ServiceTrackerCustomizer<EventAdmin, EventAdmin>()
+        {
+            @Override
+            public EventAdmin addingService(final ServiceReference<EventAdmin> 
reference)
+            {
+                EventAdmin service = context.getService(reference);
+                modifiedService(reference, service);
+                return service;
+            }
+
+            @Override
+            public void modifiedService(final ServiceReference<EventAdmin> 
reference, final EventAdmin service)
+            {
+                eventAdmin = service;
+            }
+
+            @Override
+            public void removedService(final ServiceReference<EventAdmin> 
reference, final EventAdmin service)
+            {
+                context.ungetService(reference);
+                eventAdmin = null;
+            }
+        });
         this.eventAdmintTracker.open();
 
-        this.bundleTracker = new BundleTracker(this.context, Bundle.ACTIVE | 
Bundle.STARTING, this);
+        this.bundleTracker = new BundleTracker<Deployment>(this.context, 
Bundle.ACTIVE | Bundle.STARTING,
+                new BundleTrackerCustomizer<Deployment>() {
+
+            @Override
+            public Deployment addingBundle(Bundle bundle, BundleEvent event)
+            {
+                return detectWebAppBundle(bundle);
+            }
+
+            @Override
+            public void modifiedBundle(Bundle bundle, BundleEvent event, 
Deployment object)
+            {
+                detectWebAppBundle(bundle);
+            }
+
+            private Deployment detectWebAppBundle(Bundle bundle)
+            {
+                if (bundle.getState() == Bundle.ACTIVE || (bundle.getState() 
== Bundle.STARTING && 
"Lazy".equals(bundle.getHeaders().get(HEADER_ACTIVATION_POLICY))))
+                {
+
+                    String contextPath = 
bundle.getHeaders().get(HEADER_WEB_CONTEXT_PATH);
+                    if (contextPath != null)
+                    {
+                        return startWebAppBundle(bundle, contextPath);
+                    }
+                }
+                return null;
+            }
+
+            @Override
+            public void removedBundle(Bundle bundle, BundleEvent event, 
Deployment object)
+            {
+                String contextPath = 
bundle.getHeaders().get(HEADER_WEB_CONTEXT_PATH);
+                if (contextPath == null)
+                {
+                    return;
+                }
+
+                Deployment deployment = deployments.remove(contextPath);
+                if (deployment != null && deployment.getContext() != null)
+                {
+                    // remove registration, since bundle is already stopping
+                    deployment.setRegistration(null);
+                    undeploy(deployment, deployment.getContext());
+                }
+            }
+
+                });
         this.bundleTracker.open();
     }
 
@@ -187,7 +262,7 @@ public final class JettyService extends
         return props;
     }
 
-    public void updated(Dictionary props)
+    public void updated(final Dictionary<String, ?> props)
     {
         if (this.config.update(props))
         {
@@ -213,7 +288,7 @@ public final class JettyService extends
     {
         if (this.server != null)
         {
-            this.eventDispatcher.setActive(false);
+            this.controller.getEventDispatcher().setActive(false);
             if (this.connectorTracker != null)
             {
                 this.connectorTracker.close();
@@ -266,10 +341,10 @@ public final class JettyService extends
             ServletContextHandler context = new 
ServletContextHandler(this.parent, this.config.getContextPath(), 
ServletContextHandler.SESSIONS);
 
             configureSessionManager(context);
-            this.eventDispatcher.setActive(true);
-            context.addEventListener(eventDispatcher);
-            context.getSessionHandler().addEventListener(eventDispatcher);
-            final ServletHolder holder = new ServletHolder(this.dispatcher);
+            this.controller.getEventDispatcher().setActive(true);
+            context.addEventListener(controller.getEventDispatcher());
+            
context.getSessionHandler().addEventListener(controller.getEventDispatcher());
+            final ServletHolder holder = new 
ServletHolder(this.controller.getDispatcherServlet());
             holder.setAsyncSupported(true);
             context.addServlet(holder, "/*");
             context.setMaxFormContentSize(this.config.getMaxFormSize());
@@ -318,6 +393,7 @@ public final class JettyService extends
                 }
                 Connector connector = this.server.getConnectors()[0];
                 if (connector instanceof ServerConnector) {
+                    @SuppressWarnings("resource")
                     ServerConnector serverConnector = (ServerConnector) 
connector;
                     
message.append("acceptors=").append(serverConnector.getAcceptors()).append(",");
                     
message.append("selectors=").append(serverConnector.getSelectorManager().getSelectorCount());
@@ -343,8 +419,8 @@ public final class JettyService extends
     private String fixJettyVersion()
     {
         // FELIX-4311: report the real version of Jetty...
-        Dictionary headers = this.context.getBundle().getHeaders();
-        String version = (String) headers.get("X-Jetty-Version");
+        Dictionary<String, String> headers = 
this.context.getBundle().getHeaders();
+        String version = headers.get("X-Jetty-Version");
         if (version != null)
         {
             System.setProperty("jetty.version", version);
@@ -744,7 +820,7 @@ public final class JettyService extends
                     props.put(WEB_SYMBOLIC_NAME, 
webAppBundle.getSymbolicName());
                     props.put(WEB_VERSION, webAppBundle.getVersion());
                     props.put(WEB_CONTEXT_PATH, deployment.getContextPath());
-                    
deployment.setRegistration(webAppBundle.getBundleContext().registerService(ServletContext.class.getName(),
 context.getServletContext(), props));
+                    
deployment.setRegistration(webAppBundle.getBundleContext().registerService(ServletContext.class,
 context.getServletContext(), props));
 
                     postEvent(WebEvent.DEPLOYED(webAppBundle, extenderBundle));
                 }
@@ -781,7 +857,7 @@ public final class JettyService extends
 
                     
context.getServletContext().removeAttribute(OSGI_BUNDLE_CONTEXT);
 
-                    ServiceRegistration registration = 
deployment.getRegistration();
+                    ServiceRegistration<ServletContext> registration = 
deployment.getRegistration();
                     if (registration != null)
                     {
                         registration.unregister();
@@ -802,71 +878,6 @@ public final class JettyService extends
         });
     }
 
-    @Override
-    public Object addingBundle(Bundle bundle, BundleEvent event)
-    {
-        return detectWebAppBundle(bundle);
-    }
-
-    @Override
-    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
-    {
-        detectWebAppBundle(bundle);
-    }
-
-    private Object detectWebAppBundle(Bundle bundle)
-    {
-        if (bundle.getState() == Bundle.ACTIVE || (bundle.getState() == 
Bundle.STARTING && 
"Lazy".equals(bundle.getHeaders().get(HEADER_ACTIVATION_POLICY))))
-        {
-
-            String contextPath = 
bundle.getHeaders().get(HEADER_WEB_CONTEXT_PATH);
-            if (contextPath != null)
-            {
-                return startWebAppBundle(bundle, contextPath);
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public void removedBundle(Bundle bundle, BundleEvent event, Object object)
-    {
-        String contextPath = bundle.getHeaders().get(HEADER_WEB_CONTEXT_PATH);
-        if (contextPath == null)
-        {
-            return;
-        }
-
-        Deployment deployment = this.deployments.remove(contextPath);
-        if (deployment != null && deployment.getContext() != null)
-        {
-            // remove registration, since bundle is already stopping
-            deployment.setRegistration(null);
-            undeploy(deployment, deployment.getContext());
-        }
-    }
-
-    @Override
-    public Object addingService(ServiceReference reference)
-    {
-        Object service = this.context.getService(reference);
-        modifiedService(reference, service);
-        return service;
-    }
-
-    @Override
-    public void modifiedService(ServiceReference reference, Object service)
-    {
-        this.eventAdmin = (EventAdmin) service;
-    }
-
-    @Override
-    public void removedService(ServiceReference reference, Object service)
-    {
-        this.context.ungetService(reference);
-        this.eventAdmin = null;
-    }
-
     private void postEvent(Event event)
     {
         if (this.eventAdmin != null)
@@ -909,7 +920,7 @@ public final class JettyService extends
         private String contextPath;
         private Bundle bundle;
         private WebAppBundleContext context;
-        private ServiceRegistration registration;
+        private ServiceRegistration<ServletContext> registration;
 
         public Deployment(String contextPath, Bundle bundle)
         {
@@ -937,12 +948,12 @@ public final class JettyService extends
             this.context = context;
         }
 
-        public ServiceRegistration getRegistration()
+        public ServiceRegistration<ServletContext> getRegistration()
         {
             return this.registration;
         }
 
-        public void setRegistration(ServiceRegistration registration)
+        public void setRegistration(ServiceRegistration<ServletContext> 
registration)
         {
             this.registration = registration;
         }

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
 Mon Sep 19 06:48:29 2016
@@ -26,31 +26,41 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class MBeanServerTracker extends ServiceTracker
+public class MBeanServerTracker extends ServiceTracker<MBeanServer, 
MBeanContainer>
 {
 
     private final Server server;
 
     public MBeanServerTracker(final BundleContext context, final Server server)
     {
-        super(context, MBeanServer.class.getName(), null);
+        super(context, MBeanServer.class, null);
         this.server = server;
     }
 
     @Override
-    public Object addingService(ServiceReference reference)
+    public MBeanContainer addingService(ServiceReference<MBeanServer> 
reference)
     {
         MBeanServer server = (MBeanServer) super.addingService(reference);
-        MBeanContainer mBeanContainer = new MBeanContainer(server);
-        this.server.addEventListener(mBeanContainer);
-        return mBeanContainer;
+        if ( server != null )
+        {
+            MBeanContainer mBeanContainer = new MBeanContainer(server);
+            this.server.addEventListener(mBeanContainer);
+            return mBeanContainer;
+        }
+        else
+        {
+            super.removedService(reference, null);
+        }
+        return null;
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service)
+    public void removedService(ServiceReference<MBeanServer> reference, 
MBeanContainer service)
     {
-        MBeanContainer mBeanContainer = (MBeanContainer) service;
-        this.server.removeEventListener(mBeanContainer);
-        super.removedService(reference, mBeanContainer.getMBeanServer());
+        if ( service != null )
+        {
+            this.server.removeEventListener(service);
+            super.removedService(reference, service);
+        }
     }
 }

Modified: 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/WebAppBundleContext.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/WebAppBundleContext.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/WebAppBundleContext.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/main/java/org/apache/felix/http/jetty/internal/WebAppBundleContext.java
 Mon Sep 19 06:48:29 2016
@@ -16,18 +16,18 @@
  */
 package org.apache.felix.http.jetty.internal;
 
-import org.eclipse.jetty.util.URIUtil;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.util.resource.URLResource;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.osgi.framework.Bundle;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Enumeration;
 
+import org.eclipse.jetty.util.URIUtil;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.util.resource.URLResource;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.osgi.framework.Bundle;
+
 class WebAppBundleContext extends WebAppContext
 {
     public WebAppBundleContext(String contextPath, final Bundle bundle, final 
ClassLoader parent)
@@ -70,13 +70,12 @@ class WebAppBundleContext extends WebApp
             }
 
             @Override
-            @SuppressWarnings({ "unchecked" })
             protected Enumeration<URL> findResources(String name) throws 
IOException
             {
                 // Don't try to load resources from the bundle when it is not 
active
                 if (bundle.getState() == Bundle.ACTIVE)
                 {
-                    Enumeration<URL> urls = (Enumeration<URL>) 
bundle.getResources(name);
+                    Enumeration<URL> urls = bundle.getResources(name);
                     if (urls != null)
                     {
                         return urls;

Modified: 
felix/sandbox/http-jetty-r7/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/http-jetty-r7/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java?rev=1761389&r1=1761388&r2=1761389&view=diff
==============================================================================
--- 
felix/sandbox/http-jetty-r7/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
 (original)
+++ 
felix/sandbox/http-jetty-r7/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
 Mon Sep 19 06:48:29 2016
@@ -42,8 +42,6 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
-import org.apache.felix.http.base.internal.DispatcherServlet;
-import org.apache.felix.http.base.internal.EventDispatcher;
 import org.apache.felix.http.base.internal.HttpServiceController;
 import org.apache.felix.http.jetty.internal.JettyService.Deployment;
 import org.eclipse.jetty.servlet.FilterHolder;
@@ -71,10 +69,6 @@ public class JettyServiceTest
 
     private BundleContext mockBundleContext;
 
-    private DispatcherServlet dispatcherServlet;
-
-    private EventDispatcher mockEventDispatcher;
-
     private HttpServiceController httpServiceController;
 
     private Bundle mockBundle;
@@ -84,7 +78,6 @@ public class JettyServiceTest
     {
         //Setup Mocks
         mockBundleContext = mock(BundleContext.class);
-        mockEventDispatcher = mock(EventDispatcher.class);
         mockBundle = mock(Bundle.class);
 
         //Setup Behaviors
@@ -110,8 +103,7 @@ public class JettyServiceTest
                 Matchers.any(Dictionary.class))).thenReturn(reg);
 
         httpServiceController = new HttpServiceController(mockBundleContext);
-        dispatcherServlet = new 
DispatcherServlet(httpServiceController.getDispatcher());
-        jettyService = new JettyService(mockBundleContext, dispatcherServlet, 
mockEventDispatcher, httpServiceController);
+        jettyService = new JettyService(mockBundleContext, 
httpServiceController);
 
         jettyService.start();
     }


Reply via email to