You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/06/30 08:42:31 UTC
svn commit: r789581 - in
/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl:
SlingMainServlet.java helper/SlingServletContext.java
Author: fmeschbe
Date: Tue Jun 30 06:42:31 2009
New Revision: 789581
URL: http://svn.apache.org/viewvc?rev=789581&view=rev
Log:
SLING-1026 Only setup SlingServletContext after SlingMainServlet
initialization and exactly reverse the activation setup order
in the deactivate method
Modified:
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/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=789581&r1=789580&r2=789581&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 Jun 30 06:42:31 2009
@@ -87,7 +87,7 @@
/**
* The <code>SlingMainServlet</code> TODO
- *
+ *
* @scr.component immediate="true" label="%sling.name"
* description="%sling.description"
* @scr.property name="service.vendor" value="The Apache Software Foundation"
@@ -100,14 +100,14 @@
HttpContext {
/** @scr.property valueRef="RequestData.DEFAULT_MAX_CALL_COUNTER" */
- public static final String PROP_MAX_CALL_COUNTER = "sling.max.calls";
+ public static final String PROP_MAX_CALL_COUNTER = "sling.max.calls";
/** @scr.property valueRef="RequestData.DEFAULT_MAX_INCLUSION_COUNTER" */
- public static final String PROP_MAX_INCLUSION_COUNTER = "sling.max.inclusions";
-
+ public static final String PROP_MAX_INCLUSION_COUNTER = "sling.max.inclusions";
+
/** default log */
private static final Logger log = LoggerFactory.getLogger(SlingMainServlet.class);
-
+
/**
* The registration path for the SlingMainServlet is hard wired to always
* be the root, aka "<code>/</code>" (value is "/").
@@ -160,10 +160,10 @@
/** @scr.reference cardinality="0..1" policy="dynamic" */
private RequestLogger requestLogger;
-
+
/** @scr.reference cardinality="0..1" policy="dynamic" */
private AdapterManager adapterManager;
-
+
/** @scr.reference cardinality="0..1" policy="dynamic" */
private SystemStatus systemStatus;
@@ -284,7 +284,7 @@
errorMessage = e.toString();
}
}
-
+
if (errorMessage != null) {
final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
log.error("{} , sending status {}", errorMessage, status);
@@ -297,7 +297,7 @@
systemStatus.doGet(request, response);
return;
}
-
+
// initialize the request data - resolve resource and servlet
ResourceResolver resolver = getResourceResolverFactory().getResourceResolver(
session);
@@ -544,7 +544,7 @@
ErrorHandler eh = errorHandler;
return (eh != null) ? eh : this;
}
-
+
/**
* Returns the {@link AdapterManager} bound to this instance or
* <code>null</code> if no adapter manager is bound to this instance.
@@ -593,9 +593,8 @@
RequestData.setMaxCallCounter(OsgiUtil.toInteger(
componentConfig.get(PROP_MAX_CALL_COUNTER),
RequestData.DEFAULT_MAX_CALL_COUNTER));
-
+
// setup servlet request processing helpers
- SlingServletContext tmpServletContext = new SlingServletContext(this);
slingAuthenticator = new SlingAuthenticator(bundleContext);
// register the servlet and resources
@@ -611,6 +610,10 @@
log.error("Cannot register " + this.getServerInfo(), e);
}
+ // now that the sling main servlet is registered with the HttpService
+ // and initialized we can register the servlet context
+ SlingServletContext tmpServletContext = new SlingServletContext(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)
@@ -637,22 +640,28 @@
protected void deactivate(ComponentContext componentContext) {
- // first of all, we have to unregister
- httpService.unregister(SLING_ROOT);
+ // this reverses the activation setup
+ // first destroy the filters
destroyFilters(innerFilterChain);
destroyFilters(requestFilterChain);
- if (slingAuthenticator != null) {
- slingAuthenticator.dispose();
- slingAuthenticator = null;
- }
-
+ // second unregister the servlet context *before* unregistering
+ // and destroying the the sling main servlet
if (slingServletContext != null) {
slingServletContext.dispose();
slingServletContext = null;
}
+ // third unregister and destroy the sling main servlet
+ httpService.unregister(SLING_ROOT);
+
+ // fourth dispose off the authenticator
+ if (slingAuthenticator != null) {
+ slingAuthenticator.dispose();
+ slingAuthenticator = null;
+ }
+
this.osgiComponentContext = null;
log.info(this.getServerInfo() + " shut down");
@@ -845,7 +854,7 @@
* Sets the name of the current thread to the IP address of the remote
* client with the current system time and the first request line consisting
* of the method, path and protocol.
- *
+ *
* @param request The request to extract the remote IP address, method,
* request URL and protocol from.
* @return The name of the current thread before setting the new name.
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=789581&r1=789580&r2=789581&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 Jun 30 06:42:31 2009
@@ -73,14 +73,22 @@
/** The {@link SlingMainServlet} to which some calls are delegated */
private final SlingMainServlet slingMainServlet;
- /** The service registration of this service as a ManagedService */
+ /**
+ * The service registration of this service as ServletContext
+ * @see #SlingServletContext(SlingMainServlet)ling
+ * @see #dispose()
+ */
private final ServiceRegistration registration;
/**
* Creates an instance of this class delegating some methods to the given
* {@link SlingMainServlet}. In addition the new instance is registered as
- * a <code>ManagedService</code> and <code>ServletContext</code> to
- * receive configuration information.
+ * a<code>ServletContext</code>.
+ * <p>
+ * This method must only be called <b>after</b> the sling main servlet
+ * has been fully initialized. Otherwise the {@link #getServletContext()}
+ * method may cause a {@link NullPointerException} !
+ * @see #dispose()
*/
public SlingServletContext(SlingMainServlet slingMainServlet) {
this.slingMainServlet = slingMainServlet;
@@ -94,7 +102,12 @@
}
/**
- * Disposes of this servlet context by just unregistering as a service.
+ * Unregisters this servlet context as a service (if registered at all)
+ * <p>
+ * This method must be called <b>before</b> the sling main servlet
+ * is destroyed. Otherwise the {@link #getServletContext()} method may
+ * cause a {@link NullPointerException} !
+ * @see #SlingServletContext(SlingMainServlet)
*/
public void dispose() {
if (registration != null) {