felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1760610 - in /felix/sandbox/http-base-r7/src: main/java/org/apache/felix/http/base/internal/ main/java/org/apache/felix/http/base/internal/dispatch/ main/java/org/apache/felix/http/base/internal/service/ main/java/org/apache/felix/http/bas...
Date Wed, 14 Sep 2016 01:18:55 GMT
Author: cziegeler
Date: Wed Sep 14 01:18:55 2016
New Revision: 1760610

URL: http://svn.apache.org/viewvc?rev=1760610&view=rev
Log:
Merge in changes from FELIX-5344

Modified:
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
    felix/sandbox/http-base-r7/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
Wed Sep 14 01:18:55 2016
@@ -19,13 +19,13 @@ package org.apache.felix.http.base.inter
 public abstract class AbstractHttpActivator
     extends AbstractActivator
 {
-    private DispatcherServlet dispatcher;
+    private DispatcherServlet dispatcherServlet;
     private EventDispatcher eventDispatcher;
     private HttpServiceController controller;
 
     protected final DispatcherServlet getDispatcherServlet()
     {
-        return this.dispatcher;
+        return this.dispatcherServlet;
     }
 
     protected final EventDispatcher getEventDispatcher()
@@ -38,18 +38,20 @@ public abstract class AbstractHttpActiva
         return this.controller;
     }
 
+    @Override
     protected void doStart()
         throws Exception
     {
         this.controller = new HttpServiceController(getBundleContext());
-        this.dispatcher = new DispatcherServlet(this.controller);
+        this.dispatcherServlet = new DispatcherServlet(this.controller.getDispatcher());
         this.eventDispatcher = new EventDispatcher(this.controller);
     }
 
+    @Override
     protected void doStop()
         throws Exception
     {
         this.controller.unregister();
-        this.dispatcher.destroy();
+        this.dispatcherServlet.destroy();
     }
 }

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
Wed Sep 14 01:18:55 2016
@@ -18,46 +18,30 @@ package org.apache.felix.http.base.inter
 
 import java.io.IOException;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.felix.http.base.internal.dispatch.Dispatcher;
+
 /**
  * The dispatcher servlet is registered in the container.
  *
- * When {@link #init(ServletConfig)} is called, the Http services are registered
- * and started, when {@link #destroy()} is called the services are stopped
- * and unregistered.
  */
-public final class DispatcherServlet extends HttpServlet
+public class DispatcherServlet extends HttpServlet
 {
-    private final HttpServiceController controller;
+    private final Dispatcher controller;
 
-    public DispatcherServlet(final HttpServiceController controller)
+    public DispatcherServlet(final Dispatcher controller)
     {
         this.controller = controller;
     }
 
     @Override
-    public void init(final ServletConfig config) throws ServletException
-    {
-        super.init(config);
-        this.controller.register(getServletContext());
-    }
-
-    @Override
-    public void destroy()
-    {
-        this.controller.unregister();
-        super.destroy();
-    }
-
-    @Override
     protected void service(final HttpServletRequest req, final HttpServletResponse res)
             throws ServletException, IOException
     {
-        this.controller.getDispatcher().dispatch(req, res);
+        this.controller.dispatch(req, res);
     }
 }

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
Wed Sep 14 01:18:55 2016
@@ -51,7 +51,7 @@ public final class HttpServiceController
         this.whiteboardManager = new WhiteboardManager(bundleContext, this.httpServiceFactory,
this.registry);
     }
 
-    Dispatcher getDispatcher()
+    public Dispatcher getDispatcher()
     {
         return this.dispatcher;
     }
@@ -99,22 +99,16 @@ public final class HttpServiceController
         };
     }
 
-    public void setProperties(final Hashtable<String, Object> props)
-    {
-        this.httpServiceFactory.setProperties(props);
-        this.whiteboardManager.setProperties(props);
-    }
-
     /**
      * Start the http and http whiteboard service in the provided context.
      * @param containerContext The container context.
      */
-    public void register(@Nonnull final ServletContext containerContext)
+    public void register(@Nonnull final ServletContext containerContext, @Nonnull final Hashtable<String,
Object> props)
     {
         this.registry.init();
 
-        this.httpServiceFactory.start(containerContext);
-        this.whiteboardManager.start(containerContext);
+        this.httpServiceFactory.start(containerContext, props);
+        this.whiteboardManager.start(containerContext, props);
 
         this.dispatcher.setWhiteboardManager(this.whiteboardManager);
     }

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
Wed Sep 14 01:18:55 2016
@@ -69,21 +69,24 @@ public final class Dispatcher
      */
     public void dispatch(final HttpServletRequest req, final HttpServletResponse res) throws
ServletException, IOException
     {
+        final WhiteboardManager mgr = this.whiteboardManager;
+        if ( mgr == null )
+        {
+            // not active, always return 404
+            res.sendError(404);
+            return;
+        }
+
         // check for invalidating session(s) first
         final HttpSession session = req.getSession(false);
         if ( session != null )
         {
             final Set<Long> ids = HttpSessionWrapper.getExpiredSessionContextIds(session);
-            final WhiteboardManager mgr = this.whiteboardManager;
-            if ( mgr != null )
-            {
-                mgr.sessionDestroyed(session, ids);
-            }
+	        mgr.sessionDestroyed(session, ids);
         }
 
         // invoke preprocessors
-        final WhiteboardManager mgr = this.whiteboardManager;
-        if ( mgr != null && !mgr.invokePreprocessors(req, res) )
+        if ( !mgr.invokePreprocessors(req, res) )
         {
             return;
         }

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
Wed Sep 14 01:18:55 2016
@@ -18,6 +18,7 @@ package org.apache.felix.http.base.inter
 
 import java.util.Hashtable;
 
+import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSessionAttributeListener;
 import javax.servlet.http.HttpSessionListener;
@@ -99,8 +100,18 @@ public final class HttpServiceFactory
         this.sessionAttributeListenerManager = new HttpSessionAttributeListenerManager(bundleContext);
     }
 
-    public void start(final ServletContext context)
+    public void start(final ServletContext context,
+            @Nonnull final Hashtable<String, Object> props)
     {
+        this.httpServiceProps.clear();
+        this.httpServiceProps.putAll(props);
+
+        if ( this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT)
!= null )
+        {
+            this.httpServiceProps.put(OBSOLETE_REG_PROPERTY_ENDPOINTS,
+                    this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT));
+        }
+
         this.context = context;
         this.contextAttributeListenerManager.open();
         this.requestListenerManager.open();
@@ -133,6 +144,8 @@ public final class HttpServiceFactory
         this.requestAttributeListenerManager.close();
         this.sessionListenerManager.close();
         this.sessionAttributeListenerManager.close();
+
+        this.httpServiceProps.clear();
     }
 
     @Override
@@ -193,23 +206,6 @@ public final class HttpServiceFactory
         return (Long) this.httpServiceReg.getReference().getProperty(Constants.SERVICE_ID);
     }
 
-    public void setProperties(final Hashtable<String, Object> props)
-    {
-        this.httpServiceProps.clear();
-        this.httpServiceProps.putAll(props);
-
-        if ( this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT)
!= null )
-        {
-            this.httpServiceProps.put(OBSOLETE_REG_PROPERTY_ENDPOINTS,
-                    this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT));
-        }
-
-        if (this.httpServiceReg != null)
-        {
-            this.httpServiceReg.setProperties(this.httpServiceProps);
-        }
-    }
-
     private boolean getBoolean(final String property)
     {
         String prop = this.bundleContext.getProperty(property);

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
Wed Sep 14 01:18:55 2016
@@ -152,8 +152,11 @@ public final class WhiteboardManager
      * Start the whiteboard manager
      * @param containerContext The servlet context
      */
-    public void start(final ServletContext containerContext)
+    public void start(final ServletContext containerContext, @Nonnull final Dictionary<String,
Object> httpServiceProps)
     {
+        // runtime service gets the same props for now
+        this.serviceRuntime.setAllAttributes(httpServiceProps);
+
         this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID,
                 Collections.singletonList(this.httpServiceFactory.getHttpServiceServiceId()));
         this.runtimeServiceReg = this.httpBundleContext.registerService(HttpServiceRuntime.class,
@@ -256,19 +259,6 @@ public final class WhiteboardManager
         this.webContext = null;
     }
 
-    public void setProperties(final Hashtable<String, Object> props)
-    {
-        // runtime service gets the same props for now
-        this.serviceRuntime.setAllAttributes(props);
-
-        if (this.runtimeServiceReg != null)
-        {
-            this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID,
-                    Collections.singletonList(this.httpServiceFactory.getHttpServiceServiceId()));
-            this.runtimeServiceReg.setProperties(this.serviceRuntime.getAttributes());
-        }
-    }
-
     public void sessionDestroyed(@Nonnull final HttpSession session, final Set<Long>
contextIds)
     {
         for(final Long contextId : contextIds)

Modified: felix/sandbox/http-base-r7/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java?rev=1760610&r1=1760609&r2=1760610&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
(original)
+++ felix/sandbox/http-base-r7/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
Wed Sep 14 01:18:55 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.http.base.internal.service;
 
+import java.util.Hashtable;
+
 import javax.servlet.ServletContext;
 
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
@@ -48,7 +50,7 @@ public class HttpServiceFactoryTest {
                 hsf.getService(Mockito.mock(Bundle.class), null));
 
         ServletContext sctx = Mockito.mock(ServletContext.class);
-        hsf.start(sctx);
+        hsf.start(sctx, new Hashtable<String, Object>());
         HttpService svc = hsf.getService(Mockito.mock(Bundle.class), null);
         Assert.assertNotNull(svc);
 



Mime
View raw message