Author: remy.maucherat(a)jboss.com
Date: 2011-07-22 10:17:26 -0400 (Fri, 22 Jul 2011)
New Revision: 1789
Modified:
branches/3.0.x/java/org/apache/catalina/core/StandardContextValve.java
branches/3.0.x/java/org/apache/catalina/core/StandardHostValve.java
branches/3.0.x/webapps/docs/changelog.xml
Log:
- Port listener timing patch.
Modified: branches/3.0.x/java/org/apache/catalina/core/StandardContextValve.java
===================================================================
--- branches/3.0.x/java/org/apache/catalina/core/StandardContextValve.java 2011-07-22
09:26:27 UTC (rev 1788)
+++ branches/3.0.x/java/org/apache/catalina/core/StandardContextValve.java 2011-07-22
14:17:26 UTC (rev 1789)
@@ -158,59 +158,8 @@
}
}
- // Normal request processing
- Object instances[] = context.getApplicationEventListeners();
-
- ServletRequestEvent event = null;
-
- if ((instances != null)
- && (instances.length > 0)) {
- event = new ServletRequestEvent
- (((StandardContext) container).getServletContext(),
- request.getRequest());
- // create pre-service event
- for (int i = 0; i < instances.length; i++) {
- if (instances[i] == null)
- continue;
- if (!(instances[i] instanceof ServletRequestListener))
- continue;
- ServletRequestListener listener =
- (ServletRequestListener) instances[i];
- try {
- listener.requestInitialized(event);
- } catch (Throwable t) {
-
container.getLogger().error(sm.getString("standardContext.requestListener.requestInit",
- instances[i].getClass().getName()), t);
- ServletRequest sreq = request.getRequest();
- sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
- return;
- }
- }
- }
-
wrapper.getPipeline().getFirst().invoke(request, response);
- if ((instances !=null ) &&
- (instances.length > 0)) {
- // create post-service event
- for (int i = instances.length - 1; i >= 0; i--) {
- if (instances[i] == null)
- continue;
- if (!(instances[i] instanceof ServletRequestListener))
- continue;
- ServletRequestListener listener =
- (ServletRequestListener) instances[i];
- try {
- listener.requestDestroyed(event);
- } catch (Throwable t) {
-
container.getLogger().error(sm.getString("standardContext.requestListener.requestDestroy",
- instances[i].getClass().getName()), t);
- ServletRequest sreq = request.getRequest();
- sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
- }
- }
- }
-
}
@@ -229,56 +178,10 @@
public final void event(Request request, Response response, HttpEvent httpEvent)
throws IOException, ServletException {
- Object instances[] = context.getApplicationEventListeners();
- ServletRequestEvent event = null;
- if (instances != null && (instances.length > 0)) {
- event = new ServletRequestEvent
- (((StandardContext) container).getServletContext(),
- request.getRequest());
- // create pre-service event
- for (int i = 0; i < instances.length; i++) {
- if (instances[i] == null)
- continue;
- if (!(instances[i] instanceof ServletRequestListener))
- continue;
- ServletRequestListener listener =
- (ServletRequestListener) instances[i];
- try {
- listener.requestInitialized(event);
- } catch (Throwable t) {
-
container.getLogger().error(sm.getString("requestListenerValve.requestInit",
- instances[i].getClass().getName()), t);
- ServletRequest sreq = request.getRequest();
- sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
- return;
- }
- }
- }
-
// Select the Wrapper to be used for this Request
Wrapper wrapper = request.getWrapper();
wrapper.getPipeline().getFirst().event(request, response, httpEvent);
- if (instances != null && (instances.length > 0)) {
- // create post-service event
- for (int i = instances.length - 1; i >= 0; i--) {
- if (instances[i] == null)
- continue;
- if (!(instances[i] instanceof ServletRequestListener))
- continue;
- ServletRequestListener listener =
- (ServletRequestListener) instances[i];
- try {
- listener.requestDestroyed(event);
- } catch (Throwable t) {
-
container.getLogger().error(sm.getString("requestListenerValve.requestDestroy",
- instances[i].getClass().getName()), t);
- ServletRequest sreq = request.getRequest();
- sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
- }
- }
- }
-
}
Modified: branches/3.0.x/java/org/apache/catalina/core/StandardHostValve.java
===================================================================
--- branches/3.0.x/java/org/apache/catalina/core/StandardHostValve.java 2011-07-22
09:26:27 UTC (rev 1788)
+++ branches/3.0.x/java/org/apache/catalina/core/StandardHostValve.java 2011-07-22
14:17:26 UTC (rev 1789)
@@ -24,6 +24,9 @@
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.Context;
@@ -123,9 +126,59 @@
(context.getLoader().getClassLoader());
}
+ // Normal request processing
+ Object instances[] = context.getApplicationEventListeners();
+
+ ServletRequestEvent event = null;
+
+ if ((instances != null)
+ && (instances.length > 0)) {
+ event = new ServletRequestEvent(context.getServletContext(),
+ request.getRequest());
+ // create pre-service event
+ for (int i = 0; i < instances.length; i++) {
+ if (instances[i] == null)
+ continue;
+ if (!(instances[i] instanceof ServletRequestListener))
+ continue;
+ ServletRequestListener listener =
+ (ServletRequestListener) instances[i];
+ try {
+ listener.requestInitialized(event);
+ } catch (Throwable t) {
+
container.getLogger().error(sm.getString("standardContext.requestListener.requestInit",
+ instances[i].getClass().getName()), t);
+ ServletRequest sreq = request.getRequest();
+ sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
+ return;
+ }
+ }
+ }
+
// Ask this Context to process this request
context.getPipeline().getFirst().invoke(request, response);
+ if ((instances !=null ) &&
+ (instances.length > 0)) {
+ // create post-service event
+ for (int i = instances.length - 1; i >= 0; i--) {
+ if (instances[i] == null)
+ continue;
+ if (!(instances[i] instanceof ServletRequestListener))
+ continue;
+ ServletRequestListener listener =
+ (ServletRequestListener) instances[i];
+ try {
+ listener.requestDestroyed(event);
+ } catch (Throwable t) {
+
container.getLogger().error(sm.getString("standardContext.requestListener.requestDestroy",
+ instances[i].getClass().getName()), t);
+ ServletRequest sreq = request.getRequest();
+ sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
+ }
+ }
+ }
+
// Access a session (if present) to update last accessed time, based on a
// strict interpretation of the specification
if (Globals.STRICT_SERVLET_COMPLIANCE) {
@@ -174,9 +227,54 @@
(context.getLoader().getClassLoader());
}
+ Object instances[] = context.getApplicationEventListeners();
+ ServletRequestEvent event2 = null;
+ if (instances != null && (instances.length > 0)) {
+ event2 = new ServletRequestEvent(context.getServletContext(),
+ request.getRequest());
+ // create pre-service event
+ for (int i = 0; i < instances.length; i++) {
+ if (instances[i] == null)
+ continue;
+ if (!(instances[i] instanceof ServletRequestListener))
+ continue;
+ ServletRequestListener listener =
+ (ServletRequestListener) instances[i];
+ try {
+ listener.requestInitialized(event2);
+ } catch (Throwable t) {
+
container.getLogger().error(sm.getString("requestListenerValve.requestInit",
+ instances[i].getClass().getName()), t);
+ ServletRequest sreq = request.getRequest();
+ sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
+ return;
+ }
+ }
+ }
+
// Ask this Context to process this request
context.getPipeline().getFirst().event(request, response, event);
+ if (instances != null && (instances.length > 0)) {
+ // create post-service event
+ for (int i = instances.length - 1; i >= 0; i--) {
+ if (instances[i] == null)
+ continue;
+ if (!(instances[i] instanceof ServletRequestListener))
+ continue;
+ ServletRequestListener listener =
+ (ServletRequestListener) instances[i];
+ try {
+ listener.requestDestroyed(event2);
+ } catch (Throwable t) {
+
container.getLogger().error(sm.getString("requestListenerValve.requestDestroy",
+ instances[i].getClass().getName()), t);
+ ServletRequest sreq = request.getRequest();
+ sreq.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
+ }
+ }
+ }
+
// Access a session (if present) to update last accessed time, based on a
// strict interpretation of the specification
if (Globals.STRICT_SERVLET_COMPLIANCE) {
Modified: branches/3.0.x/webapps/docs/changelog.xml
===================================================================
--- branches/3.0.x/webapps/docs/changelog.xml 2011-07-22 09:26:27 UTC (rev 1788)
+++ branches/3.0.x/webapps/docs/changelog.xml 2011-07-22 14:17:26 UTC (rev 1789)
@@ -22,6 +22,11 @@
<fix>
<jira>187</jira>: Fix NPE calling multipart parsing when a Servlet
has no multipart config. (remm)
</fix>
+ <fix>
+ <jboss-jira>JBAS-8297</jboss-jira>: Fix calling Request listeners
when entering and exiting
+ the application scope in the main host valve, not simply just before
+ calling the filter chain. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">