From: markt Date: Thu, 17 Feb 2011 10:32:07 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50789 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=167dba20a60dce0895123c6cdc54fb3adf700041;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50789 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 --- diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 6743085fb..af26716e7 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -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(); + } diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index 73c1f9fec..b26448dd1 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -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); + } + } + } } diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index c84889a09..9502068e5 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -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; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8b06f4e4b..b652898f1 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -89,6 +89,10 @@ class. (markt) + 50789: Provide an option to enable ServletRequestListeners + for forwards as required by some CDI frameworks. (markt) + + 50793: 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) diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index d4e32b377..3b185c032 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -240,6 +240,15 @@ sufficient.

+ +

Set to true 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 false is + used.

+
+

Set to true if you want the effective web.xml used for a web application to be logged (at INFO level) when the application