Author: markt Date: Fri Jun 14 10:00:57 2013 New Revision: 1493015 URL: http://svn.apache.org/r1493015 Log: As per review from voiletagg, restrictions from in Servlet 3.0, section 4.0 apply to listeners added through the pluggability API as well as via TLDs.
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1493011,1493013-1493014 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1493015&r1=1493014&r2=1493015&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java Fri Jun 14 10:00:57 2013 @@ -1329,6 +1329,8 @@ public class ApplicationContext if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { + // Add listener directly to the list of instances rather than to + // the list of class names. context.addApplicationLifecycleListener(t); match = true; } Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1493015&r1=1493014&r2=1493015&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Fri Jun 14 10:00:57 2013 @@ -242,8 +242,9 @@ public class StandardContext extends Con /** - * The set of application listeners configured for this application, in the - * order they were encountered in the web.xml file. + * The set of application listener class names configured for this + * application, in the order they were encountered in the resulting merged + * web.xml file. */ private ApplicationListener applicationListeners[] = new ApplicationListener[0]; @@ -252,14 +253,18 @@ public class StandardContext extends Con /** - * The set of instantiated application event listener objects</code>. + * The set of instantiated application event listener objects. Note that + * SCIs and other code may use the pluggability APIs to add listener + * instances directly to this list before the application starts. */ private Object applicationEventListenersObjects[] = new Object[0]; /** - * The set of instantiated application lifecycle listener objects</code>. + * The set of instantiated application lifecycle listener objects. Note that + * SCIs and other code may use the pluggability APIs to add listener + * instances directly to this list before the application starts. */ private Object applicationLifecycleListenersObjects[] = new Object[0]; @@ -4839,7 +4844,7 @@ public class StandardContext extends Con ApplicationListener listeners[] = applicationListeners; Object results[] = new Object[listeners.length]; boolean ok = true; - Set<Object> tldListeners = new HashSet<Object>(); + Set<Object> noPluggabilityListeners = new HashSet<Object>(); for (int i = 0; i < results.length; i++) { if (getLogger().isDebugEnabled()) getLogger().debug(" Configuring event listener class '" + @@ -4849,7 +4854,7 @@ public class StandardContext extends Con results[i] = instanceManager.newInstance( listener.getClassName()); if (listener.isPluggabilityBlocked()) { - tldListeners.add(results[i]); + noPluggabilityListeners.add(results[i]); } } catch (Throwable t) { t = ExceptionUtils.unwrapInvocationTargetException(t); @@ -4881,13 +4886,20 @@ public class StandardContext extends Con } } - //Listeners may have been added by ServletContextInitializers. Put them after the ones we know about. + // Listener instances may have been added directly to this Context by + // ServletContextInitializers and other code via the pluggability APIs. + // Put them these listeners after the ones defined in web.xml and/or + // annotations then overwrite the list of instances with the new, full + // list. for (Object eventListener: getApplicationEventListeners()) { eventListeners.add(eventListener); } setApplicationEventListeners(eventListeners.toArray()); for (Object lifecycleListener: getApplicationLifecycleListeners()) { lifecycleListeners.add(lifecycleListener); + if (lifecycleListener instanceof ServletContextListener) { + noPluggabilityListeners.add(lifecycleListener); + } } setApplicationLifecycleListeners(lifecycleListeners.toArray()); @@ -4908,7 +4920,7 @@ public class StandardContext extends Con ServletContextEvent event = new ServletContextEvent(getServletContext()); ServletContextEvent tldEvent = null; - if (tldListeners.size() > 0) { + if (noPluggabilityListeners.size() > 0) { tldEvent = new ServletContextEvent(new NoPluggabilityServletContext( getServletContext())); } @@ -4921,7 +4933,7 @@ public class StandardContext extends Con (ServletContextListener) instances[i]; try { fireContainerEvent("beforeContextInitialized", listener); - if (tldListeners.contains(listener)) { + if (noPluggabilityListeners.contains(listener)) { listener.contextInitialized(tldEvent); } else { listener.contextInitialized(event); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org