incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r964317 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl: SlingMainServlet.java helper/RequestListenerManager.java
Date Thu, 15 Jul 2010 06:50:49 GMT
Author: cziegeler
Date: Thu Jul 15 06:50:49 2010
New Revision: 964317

URL: http://svn.apache.org/viewvc?rev=964317&view=rev
Log:
Correct usage of servlet context and create event object only if listeners are available

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/RequestListenerManager.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=964317&r1=964316&r2=964317&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
Thu Jul 15 06:50:49 2010
@@ -190,8 +190,7 @@ public class SlingMainServlet extends Ge
 
             HttpServletRequest request = (HttpServletRequest) req;
 
-        	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(),
-        			request, SlingRequestEvent.EventType.EVENT_INIT ) );
+        	requestListenerManager.sendEvent( request, SlingRequestEvent.EventType.EVENT_INIT
);
 
             // set the thread name according to the request
             String threadName = setThreadName(request);
@@ -245,8 +244,7 @@ public class SlingMainServlet extends Ge
 
             } finally {
 
-            	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(),
-            			request, SlingRequestEvent.EventType.EVENT_DESTROY ) );
+                requestListenerManager.sendEvent( request, SlingRequestEvent.EventType.EVENT_DESTROY
);
                 // reset the thread name
                 if (threadName != null) {
                     Thread.currentThread().setName(threadName);
@@ -632,7 +630,7 @@ public class SlingMainServlet extends Ge
         }
 
         // initialize requestListenerManager
-        requestListenerManager = new RequestListenerManager( bundleContext );
+        requestListenerManager = new RequestListenerManager( bundleContext, slingServletContext
);
 
         // try to setup configuration printer
         try {

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java?rev=964317&r1=964316&r2=964317&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
Thu Jul 15 06:50:49 2010
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.engine.impl.helper;
 
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.sling.api.request.SlingRequestEvent;
 import org.apache.sling.api.request.SlingRequestListener;
 import org.osgi.framework.BundleContext;
@@ -27,14 +30,19 @@ public class RequestListenerManager  {
 
     private final ServiceTracker serviceTracker;
 
-	public RequestListenerManager( final BundleContext context ) {
+    private final ServletContext servletContext;
+
+	public RequestListenerManager( final BundleContext context, final ServletContext servletContext
) {
 		serviceTracker = new ServiceTracker( context, SlingRequestListener.SERVICE_NAME, null );
 		serviceTracker.open();
+		this.servletContext = servletContext;
 	}
 
-	public void sendEvent ( final SlingRequestEvent event ) {
+	public void sendEvent ( final HttpServletRequest request,
+	        final SlingRequestEvent.EventType type) {
 		final Object[] services = serviceTracker.getServices();
-		if ( services != null ) {
+		if ( services != null && services.length > 0 ) {
+		    final SlingRequestEvent event = new SlingRequestEvent(this.servletContext, request,
type);
 			for ( final Object service : services ) {
 				( (SlingRequestListener) service ).onEvent( event );
 			}



Mime
View raw message