Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 2635 invoked by uid 500); 11 Nov 2000 02:07:03 -0000 Delivered-To: apmail-jakarta-tomcat-cvs@apache.org Received: (qmail 2632 invoked by uid 1059); 11 Nov 2000 02:07:03 -0000 Date: 11 Nov 2000 02:07:03 -0000 Message-ID: <20001111020703.2631.qmail@locus.apache.org> From: craigmcc@locus.apache.org To: jakarta-tomcat-cvs@apache.org Subject: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/session StandardSessionInterceptor.java craigmcc 00/11/10 18:07:02 Modified: src/share/org/apache/tomcat/request Tag: tomcat_32 SessionInterceptor.java src/share/org/apache/tomcat/session Tag: tomcat_32 StandardSessionInterceptor.java Log: Migrate the handling of session id cookies from SessionInterceptor to StandardSessionInterceptor. When there are multiple session ID cookies, take the *first* one as the one that belongs to us, because of the rule in RFC 2109 that clients must specify such cookies with the most specific "path" attribute first. This corresponds to the servlet spec rule that we take the longest prefix match when selecting which context will handle a particular request. (This is slightly different than the original proposed behavior, and matches behavior just added in Tomcat 4.0 as well.) Submitted by: Paul Frieden Revision Changes Path No revision No revision 1.24.2.2 +9 -40 jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java Index: SessionInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v retrieving revision 1.24.2.1 retrieving revision 1.24.2.2 diff -u -r1.24.2.1 -r1.24.2.2 --- SessionInterceptor.java 2000/11/07 22:15:35 1.24.2.1 +++ SessionInterceptor.java 2000/11/11 02:07:02 1.24.2.2 @@ -82,7 +82,7 @@ // GS, separates the session id from the jvm route static final char SESSIONID_ROUTE_SEP = '.'; ContextManager cm; - + public SessionInterceptor() { } @@ -109,51 +109,23 @@ int foundAt=-1; String uri=request.getRequestURI(); String sessionId; - + if ((foundAt=uri.indexOf(sig))!=-1){ sessionId=uri.substring(foundAt+sig.length()); // I hope the optimizer does it's job:-) sessionId = fixSessionId( request, sessionId ); - + // rewrite URL, do I need to do anything more? request.setRequestURI(uri.substring(0, foundAt)); // No validate now - we just note that this is what the user - // requested. + // requested. request.setSessionIdSource( Request.SESSIONID_FROM_URL); request.setRequestedSessionId( sessionId ); } return 0; } - /** This happens after context map, so we know the context. - * We can probably do it later too. - */ - public int requestMap(Request request ) { - String sessionId = null; - - int count=request.getCookieCount(); - - // Give priority to cookies. I don't know if that's part - // of the spec - XXX - for( int i=0; i 0) log("Found session id cookie " + sessionId); + request.setRequestedSessionId( sessionId ); + request.setSessionIdSource( Request.SESSIONID_FROM_COOKIE ); + sess = sM.findSession(sessionId); + if (sess != null) + request.setSession(sess); + break; + } + } - // log( "No session "); + return 0; } - + public void reload( Request req, Context ctx ) { ClassLoader newLoader = ctx.getServletLoader().getClassLoader(); - StandardManager sM = getManager( ctx ); + StandardManager sM = getManager( ctx ); sM.handleReload(req, newLoader); } - + public int newSessionRequest( Request request, Response response) { Context ctx=request.getContext(); if( ctx==null ) return 0; - - StandardManager sM = getManager( ctx ); + StandardManager sM = getManager( ctx ); + if( request.getSession( false ) != null ) return 0; // somebody already set the session HttpSession newS=sM.getNewSession(); @@ -169,26 +172,26 @@ */ public int postService( Request rrequest, Response response ) { Context ctx=rrequest.getContext(); - if( ctx==null ) return 0; + if( ctx==null ) return 0; StandardManager sm= getManager( ctx ); HttpSession sess=rrequest.getSession(false); if( sess == null ) return 0; - + sm.release( sess ); return 0; } + - //-------------------- Tomcat context events -------------------- - - /** Init session management stuff for this context. + + /** Init session management stuff for this context. */ public void contextInit(Context ctx) throws TomcatException { // Defaults !! StandardManager sm= getManager( ctx ); - + if( sm == null ) { sm=new StandardManager(); setManager(ctx, sm); @@ -204,10 +207,10 @@ throw new TomcatException( ex ); } } - + /** Notification of context shutdown. * We should clean up any resources that are used by our - * session management code. + * session management code. */ public void contextShutdown( Context ctx ) throws TomcatException @@ -221,4 +224,19 @@ throw new TomcatException( ex ); } } + + private String fixSessionId(Request request, String sessionId){ + // GS, We piggyback the JVM id on top of the session cookie + // Separate them ... + + if( debug>0 ) cm.log(" Orig sessionId " + sessionId ); + if (null != sessionId) { + int idex = sessionId.lastIndexOf(SESSIONID_ROUTE_SEP); + if(idex > 0) { + sessionId = sessionId.substring(0, idex); + } + } + return sessionId; + } + }