Author: kfujino Date: Fri Apr 9 07:38:32 2010 New Revision: 932276 URL: http://svn.apache.org/viewvc?rev=932276&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47774 Ensure web application class loader is used when calling session listeners.
Modified: tomcat/tc5.5.x/trunk/STATUS.txt tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/session/StandardSession.java tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml Modified: tomcat/tc5.5.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/STATUS.txt?rev=932276&r1=932275&r2=932276&view=diff ============================================================================== --- tomcat/tc5.5.x/trunk/STATUS.txt (original) +++ tomcat/tc5.5.x/trunk/STATUS.txt Fri Apr 9 07:38:32 2010 @@ -146,13 +146,6 @@ PATCHES PROPOSED TO BACKPORT: http://svn.apache.org/viewvc?rev=928732&view=rev -1: -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47774 - Ensure web application class loader is used when calling session listeners - http://svn.apache.org/viewvc?view=revision&revision=899138 - http://svn.apache.org/viewvc?view=revision&revision=900131 - +1: kfujino, kkolinko, markt - -1: - * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48843 Prevent possible deadlock for worker allocation in APR https://issues.apache.org/bugzilla/attachment.cgi?id=25226 Modified: tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java?rev=932276&r1=932275&r2=932276&view=diff ============================================================================== --- tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java (original) +++ tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java Fri Apr 9 07:38:32 2010 @@ -87,6 +87,8 @@ public final class SecurityClassLoad { loader.loadClass (basePackage + "session.StandardSession"); loader.loadClass + (basePackage + "session.StandardSession$PrivilegedSetTccl"); + loader.loadClass (basePackage + "session.StandardSession$1"); loader.loadClass Modified: tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/session/StandardSession.java URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/session/StandardSession.java?rev=932276&r1=932275&r2=932276&view=diff ============================================================================== --- tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/session/StandardSession.java (original) +++ tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/session/StandardSession.java Fri Apr 9 07:38:32 2010 @@ -686,34 +686,59 @@ public class StandardSession // 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)) { - HttpSessionEvent event = - new HttpSessionEvent(getSession()); - for (int i = 0; i < listeners.length; i++) { - int j = (listeners.length - 1) - i; - if (!(listeners[j] instanceof HttpSessionListener)) - continue; - HttpSessionListener listener = - (HttpSessionListener) listeners[j]; - try { - fireContainerEvent(context, - "beforeSessionDestroyed", - listener); - listener.sessionDestroyed(event); - fireContainerEvent(context, - "afterSessionDestroyed", - listener); - } catch (Throwable t) { + + // The call to expire() may not have been triggered by the webapp. + // Make sure the webapp's class loader is set when calling the + // listeners + ClassLoader oldTccl = null; + if (context.getLoader() != null && + context.getLoader().getClassLoader() != null) { + oldTccl = Thread.currentThread().getContextClassLoader(); + if (System.getSecurityManager() != null) { + PrivilegedAction<Void> pa = new PrivilegedSetTccl( + context.getLoader().getClassLoader()); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader( + context.getLoader().getClassLoader()); + } + } + try { + Object listeners[] = context.getApplicationLifecycleListeners(); + if (notify && (listeners != null)) { + HttpSessionEvent event = new HttpSessionEvent(getSession()); + for (int i = 0; i < listeners.length; i++) { + int j = (listeners.length - 1) - i; + if (!(listeners[j] instanceof HttpSessionListener)) + continue; + HttpSessionListener listener = + (HttpSessionListener) listeners[j]; try { fireContainerEvent(context, - "afterSessionDestroyed", - listener); - } catch (Exception e) { - ; + "beforeSessionDestroyed", listener); + listener.sessionDestroyed(event); + fireContainerEvent(context, + "afterSessionDestroyed", listener); + } catch (Throwable t) { + try { + fireContainerEvent(context, + "afterSessionDestroyed", listener); + } catch (Exception e) { + ; + } + manager.getContainer().getLogger().error + (sm.getString("standardSession.sessionEvent"), t); } - manager.getContainer().getLogger().error - (sm.getString("standardSession.sessionEvent"), t); + } + } + } finally { + if (oldTccl != null) { + if (System.getSecurityManager() != null) { + PrivilegedAction<Void> pa = new PrivilegedSetTccl( + oldTccl); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader(oldTccl); } } } @@ -1689,7 +1714,19 @@ public class StandardSession } + private static class PrivilegedSetTccl implements PrivilegedAction<Void> { + + private ClassLoader cl; + PrivilegedSetTccl(ClassLoader cl) { + this.cl = cl; + } + + public Void run() { + Thread.currentThread().setContextClassLoader(cl); + return null; + } + } } Modified: tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml?rev=932276&r1=932275&r2=932276&view=diff ============================================================================== --- tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml (original) +++ tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml Fri Apr 9 07:38:32 2010 @@ -41,6 +41,14 @@ tree. (mturk/kkolinko)</update> </changelog> </subsection> + <subsection name="Catalina"> + <changelog> + <fix> + <bug>47774</bug>: Ensure web application class loader is used when + calling session listeners. (kfujino) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 5.5.29 (fhanik)"> <subsection name="General"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org