You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/01/29 14:58:04 UTC

svn commit: r1655665 - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/ main/java/org/apache/felix/http/base/internal/handler/ main/java/org/apache/felix/http/base/internal/service/ test/java/org/apache/felix/http/base/inte...

Author: cziegeler
Date: Thu Jan 29 13:58:04 2015
New Revision: 1655665

URL: http://svn.apache.org/r1655665
Log:
FELIX-4060 : Implement HTTP Service Update (RFC-189)

Modified:
    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/handler/AbstractHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java

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=1655665&r1=1655664&r2=1655665&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 Thu Jan 29 13:58:04 2015
@@ -30,9 +30,12 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.listener.ServletRequestAttributeListenerManager;
 import org.apache.felix.http.base.internal.listener.ServletRequestListenerManager;
 import org.apache.felix.http.base.internal.service.HttpServiceFactory;
+import org.apache.felix.http.base.internal.service.HttpServiceRuntimeImpl;
+import org.apache.felix.http.base.internal.whiteboard.ExtenderManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.http.HttpService;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
 
 public final class HttpServiceController
 {
@@ -67,7 +70,9 @@ public final class HttpServiceController
     private final HttpSessionAttributeListenerManager sessionAttributeListener;
     private final boolean sharedContextAttributes;
     private final HttpServicePlugin plugin;
-    private ServiceRegistration serviceReg;
+    private volatile ExtenderManager manager;
+    private volatile ServiceRegistration serviceReg;
+    private volatile ServiceRegistration<HttpServiceRuntime> runtimeReg;
 
     public HttpServiceController(BundleContext bundleContext)
     {
@@ -138,13 +143,23 @@ public final class HttpServiceController
         HttpServiceFactory factory = new HttpServiceFactory(servletContext, this.registry, this.contextAttributeListener, this.sharedContextAttributes);
 
         this.serviceReg = this.bundleContext.registerService(ifaces, factory, this.serviceProps);
+        this.manager = new ExtenderManager((HttpService)factory.getService(this.bundleContext.getBundle(), this.serviceReg), this.bundleContext);
+
+        this.runtimeReg = this.bundleContext.registerService(HttpServiceRuntime.class, new HttpServiceRuntimeImpl(), null);
     }
 
     public void unregister()
     {
-        if (this.serviceReg == null)
+        if ( this.manager != null )
+        {
+            this.manager.close();
+            this.manager = null;
+        }
+
+        if ( this.runtimeReg != null )
         {
-            return;
+            this.runtimeReg.unregister();
+            this.runtimeReg = null;
         }
 
         this.sessionAttributeListener.close();
@@ -152,16 +167,20 @@ public final class HttpServiceController
         this.contextAttributeListener.close();
         this.requestListener.close();
         this.requestAttributeListener.close();
+
         this.plugin.unregister();
 
-        try
-        {
-            this.serviceReg.unregister();
-            this.registry.removeAll();
-        }
-        finally
+        if ( this.serviceReg != null )
         {
-            this.serviceReg = null;
+            try
+            {
+                this.serviceReg.unregister();
+                this.registry.removeAll();
+            }
+            finally
+            {
+                this.serviceReg = null;
+            }
         }
     }
 

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java?rev=1655665&r1=1655664&r2=1655665&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java Thu Jan 29 13:58:04 2015
@@ -16,15 +16,18 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 
-import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
-
 public abstract class AbstractHandler
 {
     private final static AtomicInteger ID = new AtomicInteger();
@@ -61,6 +64,10 @@ public abstract class AbstractHandler
 
     public abstract void init() throws ServletException;
 
+    /**
+     * TODO - We can remove this, once we switched to {@link #setInitParams(Map)}
+     * @param map
+     */
     public final void setInitParams(Dictionary map)
     {
         this.initParams.clear();
@@ -82,6 +89,17 @@ public abstract class AbstractHandler
         }
     }
 
+    public final void setInitParams(Map<String, String> map)
+    {
+        this.initParams.clear();
+        if (map == null)
+        {
+            return;
+        }
+
+        this.initParams.putAll(map);
+    }
+
     protected final ExtServletContext getContext()
     {
         return this.context;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java?rev=1655665&r1=1655664&r2=1655665&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java Thu Jan 29 13:58:04 2015
@@ -109,31 +109,10 @@ public final class HttpServiceImpl imple
             filterInfo.name = filter.getClass().getName();
         }
 
-        ExtServletContext servletContext = getServletContext(filterInfo.context);
-
-        try
-        {
-            FilterHandler handler = new FilterHandler(servletContext, filter, filterInfo);
-
-            synchronized (this)
-            {
-                if (this.localFilters.add(filter))
-                {
-                    this.handlerRegistry.addFilter(handler);
-                }
-            }
-        }
-        catch (Exception e)
-        {
-            if (e instanceof ServletException)
-            {
-                throw (ServletException) e;
-            }
-            else
-            {
-                throw new ServletException("Failed to register filter " + filterInfo.name, e);
-            }
-        }
+        FilterHandler handler = new FilterHandler(getServletContext(filterInfo.context), filter, filterInfo);
+        handler.setInitParams(filterInfo.initParams);
+        this.handlerRegistry.addFilter(handler);
+        this.localFilters.add(filter);
     }
 
     @Override
@@ -188,44 +167,13 @@ public final class HttpServiceImpl imple
             servletInfo.name = servlet.getClass().getName();
         }
 
-        ExtServletContext servletContext = getServletContext(servletInfo.context);
-
-        try
-        {
-            ServletHandler handler = new ServletHandler(servletContext, servlet, servletInfo);
-
-            synchronized (this)
-            {
-                if (this.localServlets.add(servlet))
-                {
-                    this.handlerRegistry.addServlet(handler);
-                    if (servletInfo.errorPage != null && servletInfo.errorPage.length != 0)
-                    {
-                        for (String errorPage : servletInfo.errorPage)
-                        {
-                            this.handlerRegistry.addErrorServlet(errorPage, handler);
-                        }
-                    }
-                }
-            }
-        }
-        catch (Exception e)
-        {
-            if (e instanceof ServletException)
-            {
-                throw (ServletException) e;
-            }
-            else if (e instanceof NamespaceException)
-            {
-                throw (NamespaceException) e;
-            }
-            else
-            {
-                throw new ServletException("Failed to register servlet " + servletInfo.name, e);
-            }
-        }
+        ServletHandler handler = new ServletHandler(getServletContext(servletInfo.context), servlet, servletInfo);
+        handler.setInitParams(servletInfo.initParams);
+        this.handlerRegistry.addServlet(handler);
+        this.localServlets.add(servlet);
     }
 
+    @Override
     public void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext context) throws ServletException, NamespaceException
     {
         if (servlet == null)
@@ -243,6 +191,7 @@ public final class HttpServiceImpl imple
         this.localServlets.add(servlet);
     }
 
+    @Override
     public void unregister(String alias)
     {
         final Servlet servlet = this.handlerRegistry.getServletByAlias(alias);
@@ -330,7 +279,7 @@ public final class HttpServiceImpl imple
             this.localServlets.remove(servlet);
         }
     }
-    
+
     private boolean isAliasValid(String alias)
     {
         if (alias == null)

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java?rev=1655665&r1=1655664&r2=1655665&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java Thu Jan 29 13:58:04 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
+import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
@@ -51,7 +52,7 @@ public abstract class AbstractHandlerTes
         AbstractHandler handler = createHandler();
         Assert.assertEquals(0, handler.getInitParams().size());
 
-        Hashtable<String, String> map = new Hashtable<String, String>();
+        Dictionary<String, String> map = new Hashtable<String, String>();
         map.put("key1", "value1");
 
         handler.setInitParams(map);