jon 00/06/15 12:35:06 Modified: src/share/org/apache/tomcat/core BaseInterceptor.java ContextInterceptor.java ContextManager.java ServletWrapper.java src/share/org/apache/tomcat/session SessionSerializer.java StandardManager.java StandardSessionInterceptor.java Log: here is some of the email discussion that should explain these fixes...note that catalina will also probably need to be fixed. craig, i will leave that one up to you. :-) FAT kudo's to Sean for tracking this one down...it wasn't easy. -jon On Wed, Jun 14, 2000 at 07:12:26PM +0000, Sean Legassick wrote: > The sessions aren't being nullified - they are still there. At least > part of the problem is that SessionSerializer.doSerialization doesn't do > anything with sessions when it has been serialized & deserialized, so > the old hashtable remains in place. > > This works for anything loaded from the system classpath, but anything > loaded by the ACL gets a ClassCastException when it is retrieved from > the session, as the class of the object retrieved belongs to the old > classloader. This happens in RunData.getUserFromSession for us, so we > just start with a new user object. > > I'm not sure this is the whole problem Hi Jon, I thought I'd carry on .... It's not the whole problem, although it's most of it. Even when I patched SessionSerializer to replace the old sessions hashtable in sessionM with the new one, I was getting a ClassCastException in RunData.populate. The reason is that when the session is serialized/deserialized the Request object has already been setup with the current session (with objects loaded by the old classloader). What's needed is to have the reload handler also replace the session in the current request. I've done a quick'n'dirty patch that does this, and it now works for me! Basically my patch extends ContextInterceptor.reload to have 'Request req' as a paramter as well, and then I keep on passing the Request down until it hits SessionSerializer, which can then replace the old session with the regenerated one there and then. I'm not sure a Request is the right thing to pass around here, but if you'd like my patch I can send it to you. -- Sean Legassick sean@somacity.com Revision Changes Path 1.10 +1 -1 jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java Index: BaseInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BaseInterceptor.java 2000/06/13 00:32:36 1.9 +++ BaseInterceptor.java 2000/06/15 19:34:26 1.10 @@ -172,7 +172,7 @@ public void removeContext( ContextManager cm, Context ctx ) throws TomcatException { } - public void reload( Context ctx) + public void reload( Request req, Context ctx) throws TomcatException { } 1.11 +4 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java Index: ContextInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ContextInterceptor.java 2000/06/10 21:55:28 1.10 +++ ContextInterceptor.java 2000/06/15 19:34:27 1.11 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.10 2000/06/10 21:55:28 costin Exp $ - * $Revision: 1.10 $ - * $Date: 2000/06/10 21:55:28 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.11 2000/06/15 19:34:27 jon Exp $ + * $Revision: 1.11 $ + * $Date: 2000/06/15 19:34:27 $ * * ==================================================================== * @@ -111,7 +111,7 @@ This can be used to serialize sessions, log the event, remove any resource that was class-loader dependent. */ - public void reload( Context ctx) throws TomcatException; + public void reload( Request req, Context ctx) throws TomcatException; /** Called when a context is stoped, before removeContext. You must free all resources. 1.90 +2 -2 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java Index: ContextManager.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v retrieving revision 1.89 retrieving revision 1.90 diff -u -r1.89 -r1.90 --- ContextManager.java 2000/06/15 00:26:46 1.89 +++ ContextManager.java 2000/06/15 19:34:27 1.90 @@ -503,14 +503,14 @@ contextsV.removeElement(context); } - void doReload( Context context ) throws TomcatException { + void doReload( Request req, Context context ) throws TomcatException { if( context==null ) return; if( debug>0 ) log( "Reloading context " + context.toString()); ContextInterceptor cI[]=getContextInterceptors(); for( int i=0; i< cI.length; i++ ) { - cI[i].reload( context ); + cI[i].reload( req, context ); } } 1.52 +6 -6 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java Index: ServletWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- ServletWrapper.java 2000/06/13 00:32:36 1.51 +++ ServletWrapper.java 2000/06/15 19:34:28 1.52 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.51 2000/06/13 00:32:36 costin Exp $ - * $Revision: 1.51 $ - * $Date: 2000/06/13 00:32:36 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.52 2000/06/15 19:34:28 jon Exp $ + * $Revision: 1.52 $ + * $Date: 2000/06/15 19:34:28 $ * * ==================================================================== * @@ -392,7 +392,7 @@ // XXX ugly - should find a better way to deal with invoker // The problem is that we are just clearing up invoker, not // the class loaded by invoker. - void handleReload() throws TomcatException { + void handleReload(Request req) throws TomcatException { // That will be reolved after we reset the context - and many // other conflicts. if( isReloadable && ! "invoker".equals( getServletName())) { @@ -406,7 +406,7 @@ loader.reload(); ContextManager cm=context.getContextManager(); - cm.doReload( context ); + cm.doReload( req, context ); servlet=null; servletClass=null; @@ -488,7 +488,7 @@ public void handleRequest(Request req, Response res) { try { - handleReload(); + handleReload(req); } catch( TomcatException ex ) { ex.printStackTrace();// what to do ? } 1.3 +11 -1 jakarta-tomcat/src/share/org/apache/tomcat/session/SessionSerializer.java Index: SessionSerializer.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/SessionSerializer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SessionSerializer.java 2000/06/10 21:55:31 1.2 +++ SessionSerializer.java 2000/06/15 19:34:59 1.3 @@ -62,6 +62,7 @@ import java.io.*; import java.util.*; import javax.servlet.http.*; +import org.apache.tomcat.core.Request; /** This class manages the serialization of HttpSession object across @@ -82,7 +83,7 @@ /** This is the method that does the serialization. */ - public static final void doSerialization(ClassLoader cl, StandardManager sessionM) { + public static final void doSerialization(Request req, ClassLoader cl, StandardManager sessionM) { // get the hashtable of sessions Hashtable sessions = sessionM.getSessions(); @@ -102,6 +103,15 @@ // unserialize the sessions sessions = (Hashtable) oOut.readObject(); + + // put the new sessions into the manager + sessionM.setSessions(sessions); + + // and replace the current session in the current + // request + HttpSession newSession = + (HttpSession)sessions.get(req.getRequestedSessionId()); + req.setSession(newSession); } catch (Exception e) { // log the error. there shouldn't be one here though. 1.10 +15 -6 jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java Index: StandardManager.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- StandardManager.java 2000/06/10 21:55:31 1.9 +++ StandardManager.java 2000/06/15 19:34:59 1.10 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.9 2000/06/10 21:55:31 costin Exp $ - * $Revision: 1.9 $ - * $Date: 2000/06/10 21:55:31 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.10 2000/06/15 19:34:59 jon Exp $ + * $Revision: 1.10 $ + * $Date: 2000/06/15 19:34:59 $ * * ==================================================================== * @@ -71,6 +71,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; import org.apache.tomcat.util.*; +import org.apache.tomcat.core.Request; /** * Standard implementation of the Manager interface that provides @@ -101,7 +102,7 @@ * @author Craig R. McClanahan * @author costin@eng.sun.com * @author Jon S. Stevens - * @version $Revision: 1.9 $ $Date: 2000/06/10 21:55:31 $ + * @version $Revision: 1.10 $ $Date: 2000/06/15 19:34:59 $ */ public final class StandardManager implements Runnable { // ----------------------------------------------------- Instance Variables @@ -321,6 +322,14 @@ public Hashtable getSessions() { return this.sessions; } + + /** + This method will replace the sessions Hashtable with + that given. + */ + public void setSessions(Hashtable sessions) { + this.sessions = sessions; + } /** * Construct and return a new session object, based on the default @@ -361,8 +370,8 @@ return (session); } - public void handleReload(ClassLoader newLoader) { - SessionSerializer.doSerialization(newLoader, this); + public void handleReload(Request req, ClassLoader newLoader) { + SessionSerializer.doSerialization(req, newLoader, this); } /** 1.3 +2 -2 jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java Index: StandardSessionInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardSessionInterceptor.java 2000/06/11 23:13:13 1.2 +++ StandardSessionInterceptor.java 2000/06/15 19:34:59 1.3 @@ -143,10 +143,10 @@ return 0; } - public void reload( Context ctx ) { + public void reload( Request req, Context ctx ) { ClassLoader newLoader = ctx.getServletLoader().getClassLoader(); StandardManager sM = getManager( ctx ); - sM.handleReload(newLoader); + sM.handleReload(req, newLoader); } public int newSessionRequest( Request request, Response response) {