Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50789
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 17 Feb 2011 10:32:07 +0000 (10:32 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 17 Feb 2011 10:32:07 +0000 (10:32 +0000)
Provide an option to enable ServletRequestListeners for forwards as required by some CDI frameworks.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1071565 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Context.java
java/org/apache/catalina/core/ApplicationDispatcher.java
java/org/apache/catalina/core/StandardContext.java
webapps/docs/changelog.xml
webapps/docs/config/context.xml

index 6743085..af26716 100644 (file)
@@ -1315,5 +1315,18 @@ public interface Context extends Container {
      * deployment. If not specified, defaults to the empty string.
      */
     public String getWebappVersion();
+    
+    /**
+     * Configure whether or not requests listeners will be fired on forwards for
+     * this Context.
+     */
+    public void setFireRequestListenersOnForwards(boolean enable);
+
+    /**
+     * Determine whether or not requests listeners will be fired on forwards for
+     * this Context.
+     */
+    public boolean getFireRequestListenersOnForwards();
+    
 }
 
index 73c1f9f..b26448d 100644 (file)
@@ -453,19 +453,31 @@ final class ApplicationDispatcher
                 
         DispatcherType disInt = (DispatcherType) request.getAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR);
         if (disInt != null) {
-            if (disInt != DispatcherType.ERROR) {
-                state.outerRequest.setAttribute
-                    (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
-                     getCombinedPath());
-                state.outerRequest.setAttribute
-                    (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                     DispatcherType.FORWARD);
-                invoke(state.outerRequest, response, state);
-            } else {
-                invoke(state.outerRequest, response, state);
+            boolean doInvoke = true;
+            
+            if (context.getFireRequestListenersOnForwards() &&
+                    !context.fireRequestInitEvent(request)) {
+                doInvoke = false;
             }
-        }
 
+            if (doInvoke) {
+                if (disInt != DispatcherType.ERROR) {
+                    state.outerRequest.setAttribute
+                        (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
+                         getCombinedPath());
+                    state.outerRequest.setAttribute
+                        (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
+                         DispatcherType.FORWARD);
+                    invoke(state.outerRequest, response, state);
+                } else {
+                    invoke(state.outerRequest, response, state);
+                }
+                
+                if (context.getFireRequestListenersOnForwards()) {
+                    context.fireRequestDestroyEvent(request);
+                }
+            }
+        }
     }
     
     
index c84889a..9502068 100644 (file)
@@ -833,10 +833,24 @@ public class StandardContext extends ContainerBase
     private String webappVersion = "";
 
     private boolean addWebinfClassesResources = false;
+    
+    private boolean fireRequestListenersOnForwards = false;
 
     // ----------------------------------------------------- Context Properties
 
 
+    @Override
+    public void setFireRequestListenersOnForwards(boolean enable) {
+        fireRequestListenersOnForwards = enable;
+    }
+
+
+    @Override
+    public boolean getFireRequestListenersOnForwards() {
+        return fireRequestListenersOnForwards;
+    }
+
+
     public void setAddWebinfClassesResources(
             boolean addWebinfClassesResources) {
         this.addWebinfClassesResources = addWebinfClassesResources;
index 8b06f4e..b652898 100644 (file)
         class. (markt)
       </fix>
       <fix>
+        <bug>50789</bug>: Provide an option to enable ServletRequestListeners
+        for forwards as required by some CDI frameworks. (markt)
+      </fix>
+      <fix>
         <bug>50793</bug>: When processing Servlet 3.0 async requests, ensure
         that the requestInitialized and requestDestroyed events are only fired
         once per request at the correct times. (markt)
index d4e32b3..3b185c0 100644 (file)
         sufficient.</p>
       </attribute>
 
+      <attribute name="fireRequestListenersOnForwards" required="false">
+        <p>Set to <code>true</code> to fire any configured
+        ServletRequestListeners  when Tomcat forwards a request. This is
+        primarily of use to users of CDI frameworks that use
+        ServletRequestListeners to configure the necessary environment for a
+        request. If not specified, the default value of <code>false</code> is
+        used.</p>
+      </attribute>
+
       <attribute name="logEffectiveWebXml" required="false">
         <p>Set to <code>true</code> if you want the effective web.xml used for a
         web application to be logged (at INFO level) when the application