incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r993307 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine: SlingRequestProcessor.java impl/SlingMainServlet.java impl/helper/SlingServletContext.java
Date Tue, 07 Sep 2010 09:58:50 GMT
Author: fmeschbe
Date: Tue Sep  7 09:58:50 2010
New Revision: 993307

URL: http://svn.apache.org/viewvc?rev=993307&view=rev
Log:
SLING-1603 SlingRequestProcessor must be registered as a service
(also cleanup activation and deactivation methods with respect to using the Component Context)

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingRequestProcessor.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingRequestProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingRequestProcessor.java?rev=993307&r1=993306&r2=993307&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingRequestProcessor.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/SlingRequestProcessor.java
Tue Sep  7 09:58:50 2010
@@ -36,6 +36,11 @@ import org.apache.sling.api.resource.Res
 public interface SlingRequestProcessor {
 
     /**
+     * The name of the <code>SlingRequestProcessor</code> service.
+     */
+    static final String NAME = SlingRequestProcessor.class.getName();
+
+    /**
      * Process an HTTP request through the Sling request processing engine.
      * <p>
      * This method does <b>not</b> close the provided resource resolver !

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=993307&r1=993306&r2=993307&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Tue Sep  7 09:58:50 2010
@@ -23,6 +23,8 @@ import java.net.SocketException;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Map;
+
 import javax.servlet.GenericServlet;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
@@ -30,7 +32,9 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
@@ -44,6 +48,7 @@ import org.apache.sling.api.servlets.Ser
 import org.apache.sling.auth.core.AuthenticationSupport;
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.engine.SlingRequestProcessor;
 import org.apache.sling.engine.impl.filter.ServletFilterManager;
 import org.apache.sling.engine.impl.helper.RequestListenerManager;
 import org.apache.sling.engine.impl.helper.SlingServletContext;
@@ -52,8 +57,8 @@ import org.apache.sling.engine.impl.requ
 import org.apache.sling.engine.servlets.ErrorHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
-import org.osgi.service.component.ComponentContext;
 import org.osgi.service.http.HttpService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -110,8 +115,6 @@ public class SlingMainServlet extends Ge
 
     private SlingServletContext slingServletContext;
 
-    private ComponentContext osgiComponentContext;
-
     /**
      * The server information to report in the {@link #getServerInfo()} method.
      * By default this is just the {@link #PRODUCT_NAME}. The
@@ -135,6 +138,8 @@ public class SlingMainServlet extends Ge
 
     private final SlingRequestProcessorImpl requestProcessor = new SlingRequestProcessorImpl();
 
+    private ServiceRegistration requestProcessorRegistration;
+
     // ---------- Servlet API -------------------------------------------------
 
     public void service(ServletRequest req, ServletResponse res)
@@ -234,18 +239,13 @@ public class SlingMainServlet extends Ge
         return serverInfo;
     }
 
-    public BundleContext getBundleContext() {
-        return osgiComponentContext.getBundleContext();
-    }
-
     // ---------- Property Setter for SCR --------------------------------------
 
-    protected void activate(ComponentContext componentContext) {
-
-        osgiComponentContext = componentContext;
+    @Activate
+    protected void activate(final BundleContext bundleContext,
+            final Map<String, Object> componentConfig) {
 
         // setup server info
-        final BundleContext bundleContext = componentContext.getBundleContext();
         final Dictionary<?, ?> props = bundleContext.getBundle().getHeaders();
         final Version bundleVersion = Version.parseVersion((String) props.get(Constants.BUNDLE_VERSION));
         final String productVersion = bundleVersion.getMajor() + "."
@@ -259,12 +259,8 @@ public class SlingMainServlet extends Ge
         this.requestProcessor.setServerInfo(serverInfo);
 
         // prepare the servlet configuration from the component config
-        final Hashtable<String, Object> configuration = new Hashtable<String, Object>();
-        final Dictionary<?, ?> componentConfig = componentContext.getProperties();
-        for (Enumeration<?> cce = componentConfig.keys(); cce.hasMoreElements();) {
-            Object key = cce.nextElement();
-            configuration.put(String.valueOf(key), componentConfig.get(key));
-        }
+        final Hashtable<String, Object> configuration = new Hashtable<String, Object>(
+            componentConfig);
 
         // ensure the servlet name
         if (!(configuration.get("servlet-name") instanceof String)) {
@@ -300,13 +296,13 @@ public class SlingMainServlet extends Ge
 
         // now that the sling main servlet is registered with the HttpService
         // and initialized we can register the servlet context
-        slingServletContext = new SlingServletContext(this);
+        slingServletContext = new SlingServletContext(bundleContext, this);
 
         // register render filters already registered after registration with
         // the HttpService as filter initialization may cause the servlet
         // context to be required (see SLING-42)
-        filterManager = new ServletFilterManager(
-            componentContext.getBundleContext(), slingServletContext);
+        filterManager = new ServletFilterManager(bundleContext,
+            slingServletContext);
         filterManager.open();
         requestProcessor.setFilterManager(filterManager);
 
@@ -319,9 +315,23 @@ public class SlingMainServlet extends Ge
         } catch (Throwable t) {
             log.debug("Unable to register web console configuration printer.", t);
         }
+
+        // provide the SlingRequestProcessor service
+        Hashtable<String, String> srpProps = new Hashtable<String, String>();
+        srpProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        srpProps.put(Constants.SERVICE_DESCRIPTION, "Sling Request Processor");
+        requestProcessorRegistration = bundleContext.registerService(
+            SlingRequestProcessor.NAME, requestProcessor, srpProps);
     }
 
-    protected void deactivate(ComponentContext componentContext) {
+    @Deactivate
+    protected void deactivate() {
+        // unregister the sling request processor
+        if (requestProcessorRegistration != null) {
+            requestProcessorRegistration.unregister();
+            requestProcessorRegistration = null;
+        }
+
         // this reverses the activation setup
         if ( this.printerRegistration != null ) {
             WebConsoleConfigPrinter.unregister(this.printerRegistration);
@@ -354,8 +364,6 @@ public class SlingMainServlet extends Ge
         // reset the sling main servlet reference (help GC and be nice)
         RequestData.setSlingMainServlet(null);
 
-        this.osgiComponentContext = null;
-
         log.info(this.getServerInfo() + " shut down");
     }
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java?rev=993307&r1=993306&r2=993307&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
Tue Sep  7 09:58:50 2010
@@ -33,6 +33,7 @@ import javax.servlet.ServletContext;
 
 import org.apache.sling.engine.impl.SlingMainServlet;
 import org.apache.sling.engine.impl.request.SlingRequestDispatcher;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
@@ -90,14 +91,15 @@ public class SlingServletContext impleme
      * method may cause a {@link NullPointerException} !
      * @see #dispose()
      */
-    public SlingServletContext(SlingMainServlet slingMainServlet) {
+    public SlingServletContext(final BundleContext bundleContext,
+            final SlingMainServlet slingMainServlet) {
         this.slingMainServlet = slingMainServlet;
 
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(Constants.SERVICE_PID, getClass().getName());
         props.put(Constants.SERVICE_DESCRIPTION, "Sling ServletContext");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-        registration = slingMainServlet.getBundleContext().registerService(
+        registration = bundleContext.registerService(
             ServletContext.class.getName(), this, props);
     }
 



Mime
View raw message