incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r634201 - /incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java
Date Thu, 06 Mar 2008 09:24:35 GMT
Author: bdelacretaz
Date: Thu Mar  6 01:24:34 2008
New Revision: 634201

URL: http://svn.apache.org/viewvc?rev=634201&view=rev
Log:
SLING-310 - make SlingMainServlet the HttpContext, and detect if used after being deactivated

Modified:
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java?rev=634201&r1=634200&r2=634201&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/SlingMainServlet.java
Thu Mar  6 01:24:34 2008
@@ -88,7 +88,7 @@
  * @scr.reference name="Filter" interface="javax.servlet.Filter"
  *                cardinality="0..n" policy="dynamic"
  */
-public class SlingMainServlet extends GenericServlet implements ErrorHandler {
+public class SlingMainServlet extends GenericServlet implements ErrorHandler, HttpContext
{
 
     /** default log */
     private static final Logger log = LoggerFactory.getLogger(SlingMainServlet.class);
@@ -110,6 +110,8 @@
     private ComponentContext osgiComponentContext;
 
     private List<ServiceReference> delayedComponentFilters;
+    
+    private boolean activated;
 
     /**
      * The server information to report in the {@link #getServerInfo()} method.
@@ -575,32 +577,10 @@
 
         // register the servlet and resources
         try {
-            HttpContext httpContext = new HttpContext() {
-                public String getMimeType(String name) {
-                    return mimeTypeService.getMimeType(name);
-                }
-
-                public URL getResource(String name) {
-                    return null;
-                }
-
-                public boolean handleSecurity(HttpServletRequest request,
-                        HttpServletResponse response) {
-                    try {
-                        return slingAuthenticator.authenticate(request,
-                            response);
-                    } catch (MissingRepositoryException mre) {
-                        log.error(
-                            "handleSecurity: Cannot authenticate request", mre);
-                        return false;
-                    }
-                }
-            };
-
             Dictionary<String, String> servletConfig = toStringConfig(configuration);
 
             this.httpService.registerServlet(this.slingRoot, this,
-                servletConfig, httpContext);
+                servletConfig, this);
 
             log.info("{} ready to serve requests", this.getServerInfo());
 
@@ -630,6 +610,8 @@
                 initFilter(componentContext, serviceReference);
             }
         }
+        
+        activated = true;
     }
 
     protected void deactivate(ComponentContext componentContext) {
@@ -648,6 +630,7 @@
         this.slingServletContext = null;
         this.osgiComponentContext = null;
 
+        activated = false;
         log.info(this.getServerInfo() + " shut down");
     }
 
@@ -752,4 +735,33 @@
         return stringConfig;
     }
 
+    /** {@inheritDoc} */
+    public String getMimeType(String name) {
+        ensureActivated();
+        return mimeTypeService.getMimeType(name);
+    }
+
+    /** {@inheritDoc} */
+    public URL getResource(String name) {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response)
{
+        ensureActivated();
+        try {
+            return slingAuthenticator.authenticate(request,
+                response);
+        } catch (MissingRepositoryException mre) {
+            log.error(
+                "handleSecurity: Cannot authenticate request", mre);
+            return false;
+        }
+    }
+    
+    protected void ensureActivated() {
+        if(!activated) {
+            throw new IllegalStateException("SlingMainServlet is inactive");
+        }
+    }
 }



Mime
View raw message