Author: remy.maucherat(a)jboss.com
Date: 2009-10-16 19:21:50 -0400 (Fri, 16 Oct 2009)
New Revision: 1203
Modified:
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/catalina/core/StandardContextValve.java
trunk/java/org/apache/catalina/session/StandardSession.java
Log:
- Listener order fix.
- Also add the request listener for event. Don't know if it really needs to be done,
though.
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-10-16 17:30:49 UTC (rev
1202)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-10-16 23:21:50 UTC (rev
1203)
@@ -3918,16 +3918,15 @@
boolean ok = true;
Object listeners[] = getApplicationLifecycleListeners();
- if (listeners != null) {
+ if (listeners != null && (listeners.length > 0)) {
ServletContextEvent event =
new ServletContextEvent(getServletContext());
- for (int i = 0; i < listeners.length; i++) {
- int j = (listeners.length - 1) - i;
- if (listeners[j] == null)
+ for (int i = listeners.length - 1; i >= 0; i--) {
+ if (listeners[i] == null)
continue;
- if (listeners[j] instanceof ServletContextListener) {
+ if (listeners[i] instanceof ServletContextListener) {
ServletContextListener listener =
- (ServletContextListener) listeners[j];
+ (ServletContextListener) listeners[i];
try {
fireContainerEvent("beforeContextDestroyed",
listener);
listener.contextDestroyed(event);
@@ -3936,16 +3935,16 @@
fireContainerEvent("afterContextDestroyed", listener);
getLogger().error
(sm.getString("standardContext.listenerStop",
- listeners[j].getClass().getName()), t);
+ listeners[i].getClass().getName()), t);
ok = false;
}
}
try {
- getInstanceManager().destroyInstance(listeners[j]);
+ getInstanceManager().destroyInstance(listeners[i]);
} catch (Throwable t) {
getLogger().error
(sm.getString("standardContext.listenerStop",
- listeners[j].getClass().getName()), t);
+ listeners[i].getClass().getName()), t);
ok = false;
}
}
@@ -3953,17 +3952,16 @@
// Annotation processing
listeners = getApplicationEventListeners();
- if (listeners != null) {
- for (int i = 0; i < listeners.length; i++) {
- int j = (listeners.length - 1) - i;
- if (listeners[j] == null)
+ if (listeners != null && (listeners.length > 0)) {
+ for (int i = listeners.length - 1; i >= 0; i--) {
+ if (listeners[i] == null)
continue;
try {
- getInstanceManager().destroyInstance(listeners[j]);
+ getInstanceManager().destroyInstance(listeners[i]);
} catch (Throwable t) {
getLogger().error
(sm.getString("standardContext.listenerStop",
- listeners[j].getClass().getName()), t);
+ listeners[i].getClass().getName()), t);
ok = false;
}
}
Modified: trunk/java/org/apache/catalina/core/StandardContextValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContextValve.java 2009-10-16 17:30:49 UTC
(rev 1202)
+++ trunk/java/org/apache/catalina/core/StandardContextValve.java 2009-10-16 23:21:50 UTC
(rev 1203)
@@ -193,7 +193,7 @@
if ((instances !=null ) &&
(instances.length > 0)) {
// create post-service event
- for (int i = 0; i < instances.length; i++) {
+ for (int i = instances.length - 1; i >= 0; i--) {
if (instances[i] == null)
continue;
if (!(instances[i] instanceof ServletRequestListener))
@@ -226,21 +226,12 @@
* @exception IOException if an input/output error occurred
* @exception ServletException if a servlet error occurred
*/
- public final void event(Request request, Response response, HttpEvent event)
+ public final void event(Request request, Response response, HttpEvent httpEvent)
throws IOException, ServletException {
- // Select the Wrapper to be used for this Request
- Wrapper wrapper = request.getWrapper();
-
- // Normal request processing
- // FIXME: This could be an addition to the core API too
- /*
Object instances[] = context.getApplicationEventListeners();
-
ServletRequestEvent event = null;
-
- if ((instances != null)
- && (instances.length > 0)) {
+ if (instances != null && (instances.length > 0)) {
event = new ServletRequestEvent
(((StandardContext) container).getServletContext(),
request.getRequest());
@@ -263,15 +254,14 @@
}
}
}
- */
- wrapper.getPipeline().getFirst().event(request, response, event);
+ // 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)) {
+ if (instances != null && (instances.length > 0)) {
// create post-service event
- for (int i = 0; i < instances.length; i++) {
+ for (int i = instances.length - 1; i >= 0; i--) {
if (instances[i] == null)
continue;
if (!(instances[i] instanceof ServletRequestListener))
@@ -288,7 +278,6 @@
}
}
}
- */
}
Modified: trunk/java/org/apache/catalina/session/StandardSession.java
===================================================================
--- trunk/java/org/apache/catalina/session/StandardSession.java 2009-10-16 17:30:49 UTC
(rev 1202)
+++ trunk/java/org/apache/catalina/session/StandardSession.java 2009-10-16 23:21:50 UTC
(rev 1203)
@@ -670,18 +670,15 @@
expiring = true;
// Notify interested application event listeners
- // FIXME - Assumes we call listeners in reverse order
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
- if (notify && (listeners != null)) {
+ if (notify && listeners != null && (listeners.length > 0))
{
HttpSessionEvent event =
new HttpSessionEvent(getSession());
- for (int i = 0; i < listeners.length; i++) {
- int j = (listeners.length - 1) - i;
- if (!(listeners[j] instanceof HttpSessionListener))
+ for (int i = listeners.length - 1; i >= 0; i--) {
+ if (!(listeners[i] instanceof HttpSessionListener))
continue;
- HttpSessionListener listener =
- (HttpSessionListener) listeners[j];
+ HttpSessionListener listener = (HttpSessionListener) listeners[i];
try {
context.fireContainerEvent("beforeSessionDestroyed",
listener);
listener.sessionDestroyed(event);
@@ -1606,9 +1603,9 @@
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationEventListeners();
- if (listeners == null)
+ if (listeners == null || (listeners.length < 1))
return;
- for (int i = 0; i < listeners.length; i++) {
+ for (int i = listeners.length - 1; i >= 0; i--) {
if (!(listeners[i] instanceof HttpSessionAttributeListener))
continue;
HttpSessionAttributeListener listener =
Show replies by date