It is working with the latest from Branch_3_2 in CVS. I'm looking into if it works with RC1 or RC2.
You're using Apache/mod_jk/AJP. I think the jvmRoute attribute is added to the sessionID and that this is screwing up the RC1 and RC2 code. Thomas tests HTTPClustering with a hardware loadbalancer. User: tpeuss Date: 03/02/25 12:00:00 Modified: tomcat41/src/main/org/jboss/web/catalina/session Tag: Branch_3_2 ClusterManager.java Log: Bugfix for sticky session with jvmRoute() - thanks to integ! Revision Changes Path No revision No revision 1.1.4.1 +102 -51 contrib/tomcat41/src/main/org/jboss/web/catalina/session/ClusterManager.java Index: ClusterManager.java =================================================================== RCS file: /cvsroot/jboss/contrib/tomcat41/src/main/org/jboss/web/catalina/session/Clus terManager.java,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -u -r1.1 -r1.1.4.1 --- ClusterManager.java 27 Sep 2002 13:47:09 -0000 1.1 +++ ClusterManager.java 25 Feb 2003 19:59:58 -0000 1.1.4.1 @@ -29,7 +29,7 @@ @see org.jboss.ha.httpsession.server.ClusteredHTTPSessionService @author Thomas Peuss <[EMAIL PROTECTED]> - @version $Revision: 1.1 $ + @version $Revision: 1.1.4.1 $ */ public class ClusterManager extends StandardManager implements ClusterManagerMBean { @@ -71,6 +71,11 @@ * The objectname this Manager is associated with */ protected ObjectName objectName; + + /** + * The context for this Manager + */ + protected Context context; /** * Is the reaper-thread started? @@ -85,6 +90,7 @@ setDistributable(true); this.log=log; contextPath=context.getPath(); + this.context=context; // Find ClusteredHttpSessionService try { @@ -121,6 +127,16 @@ return new Integer(sessions.size()); } + public ClusteredSession[] getSessions() + { + ClusteredSession[] sess=new ClusteredSession[0]; + + synchronized(sessions) { + sess=(ClusteredSession[])sessions.values().toArray(sess); + } + return sess; + } + // Manager-methods ------------------------------------- @@ -145,6 +161,45 @@ return session; } + + /** + * Generate new sessionid for a new jvmRoute - during failover + * @param id The session id + */ + public String getJvmRouteId(String id) + { + String sessid = null; + if(id != null) { + if(this.getJvmRoute() != null) { + if(!this.getJvmRoute().equals(id.substring(id.lastIndexOf('.') + 1, id.length()))) { + sessid = id.substring(0,id.lastIndexOf('.')+1)+this.getJvmRoute(); + log.debug("JvmRoute id is :" + sessid); + } else { + return id; + } + } + } + return sessid; + } + + /** + * Sets a new cookie for the given session id and response + * @param response The HttpServletResponse to which cookie is to be added + * @param sessionId The session id + */ + public void setSessionCookie(HttpServletResponse response, String sessionId) + { + if(response != null) { + if (context.getCookies()) { + // set a new session cookie + Cookie newCookie=new Cookie(Globals.SESSION_COOKIE_NAME,sessionId); + log.debug("Setting cookie with session id:" + sessionId + " & name:" + Globals.SESSION_COOKIE_NAME); + newCookie.setMaxAge(-1); + newCookie.setPath(contextPath); + response.addCookie(newCookie); + } + } + } /** * Find the session for the given id @@ -153,70 +208,66 @@ */ public Session findSession(String id) throws IOException { - ClusteredSession session=null; + ClusteredSession session=null; if (id == null) { - return null; + return null; } log.debug("Looking for session with id="+id); synchronized(sessions) { - // first in local store - session=(ClusteredSession)sessions.get(id); + HttpServletResponse response=(HttpServletResponse)ClusteredSessionValve.responseThreadLocal.get( ); - // not found --> distributed store - if(session==null) { - session=loadSession(id); - - // did we find the session in the distributed store? - if(session!=null) { - // set attributes that were not serialized (are marked transient) - session.initAfterLoad(this,log); + // first in local store + session=(ClusteredSession)sessions.get(id); + + if(session == null){ + //check for sessionid with new jvmRoute because of session failover + session = (ClusteredSession)sessions.get(getJvmRouteId(id)); + + //set cookie with new sessionid + if(session != null){ + // Do we use Cookies for session id storage? + setSessionCookie(response, session.getId()); + } + } + + // not found --> distributed store + if(session==null) { + session=loadSession(id); + + if(session == null) { + session=loadSession(getJvmRouteId(id)); + } + // did we find the session in the distributed store? + if(session!=null) { + // set attributes that were not serialized (are marked transient) + session.initAfterLoad(this,log); // If jvmRoute is set manipulate the sessionid and generate a cookie to make // the session sticky on its new node - String jvmRoute=this.getJvmRoute(); - if(jvmRoute!=null) { - String sessionid=id; - HttpServletResponse response=(HttpServletResponse)ClusteredSessionValve.responseThreadLocal.get( ); - - // kill the old Cookie - Cookie oldCookie=new Cookie(Globals.SESSION_COOKIE_NAME,id); - oldCookie.setMaxAge(0); - oldCookie.setPath(contextPath); - response.addCookie(oldCookie); - - // remove the session from the local store - sessions.remove(id); - - // remove the session from clustered store - removeSession(id); - - // modify the sessionid for the new node - int index=sessionid.lastIndexOf('.'); - sessionid=sessionid.substring(0,index+1)+jvmRoute; - session.setId(sessionid); - - // add the modified session to the local store - sessions.put(sessionid,session); - - // set a new session cookie - Cookie newCookie=new Cookie(Globals.SESSION_COOKIE_NAME,sessionid); - newCookie.setMaxAge(-1); - newCookie.setPath(contextPath); - response.addCookie(newCookie); - } - - // add to local store - log.debug("Found in distributed store - adding to local store"); - add(session); - } - } + + if(this.getJvmRoute()!=null) { + String sessionid = getJvmRouteId(id); + + //setId() resets session id and adds it back to local & distributed store + session.setId(sessionid); + + //set cookie (if using cookies for session) + setSessionCookie(response,sessionid); + + } else { + // add to local store - no jvmRoute specified + log.debug("Found in distributed store - adding to local store"); + add(session); + } + } + } } if(session!=null) { - log.debug("Found"); + log.debug("Found"); } return session; } ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ jboss-cvs-commits mailing list [EMAIL PROTECTED] > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Bruce > Bleasdale > Sent: Wednesday, February 26, 2003 2:48 PM > To: [EMAIL PROTECTED] > Subject: [JBoss-user] JBoss 3.2 RC1 and session clustering > > > > Hey all, > > I have been tinkering around with JBoss 3.2 RC1's session > clustering feature > using a simple jsp app to test that sessions are communicated > between nodes. > > This sounds crazy, but does anyone know for a fact that RC1 or > RC2 can perform > session clustering? > > I run into null pointer exceptions when I create a session on > node1 and then > try to request a jsp page on node2. It looks like node2 is > attempting to look > up the session id when it fails. Here is the stack trace from a failure: > > ------------------------------------------------------------------ > --------------------------------------------- > -662189858=jboss.j2ee:jndiName=clustering/HTTPSession,service=EJB > 11:37:13,362 ERROR [Engine] CoyoteAdapter An exception or error > occurred in > the container during the request processing > java.lang.NullPointerException > at > org.jboss.web.catalina.session.ClusterManager.findSession(ClusterM > anager.java:188) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValv > e.java:173) > at > org.apache.catalina.core.StandardPipeline$StandardPipelineValveCon > text.invokeNext(StandardPipeline.java:643) > at > org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispat > cherValve.java:170) > at > org.apache.catalina.core.StandardPipeline$StandardPipelineValveCon > text.invokeNext(StandardPipeline.java:641) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValv > e.java:172) > at > org.apache.catalina.core.StandardPipeline$StandardPipelineValveCon > text.invokeNext(StandardPipeline.java:641) > at > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:509) > at > org.apache.catalina.core.StandardPipeline$StandardPipelineValveCon > text.invokeNext(StandardPipeline.java:641) > at > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline. > java:480) > ------------------------------------------------------------------ > --------------------------------------------- > > In the cluster manager file, here is the line that the stack trace if > refferencing: > > ------------------------------------------------------------------ > --------------------------------------------- > > 177 // If jvmRoute is set manipulate the sessionid and > generate a cookie to make > 178 // the session sticky on its new node > 179 String jvmRoute=this.getJvmRoute(); > 180 if(jvmRoute!=null) { > 181 String sessionid=id; > 182 HttpServletResponse > response=(HttpServletResponse)ClusteredSessionValve.responseThread > Local.get(); > 183 > 184 // kill the old Cookie > 185 Cookie oldCookie=new > Cookie(Globals.SESSION_COOKIE_NAME,id); > 186 oldCookie.setMaxAge(0); > 187 oldCookie.setPath(contextPath); > 188 response.addCookie(oldCookie); > 189 > ------------------------------------------------------------------ > --------------------------------------------- > > Hence is the response object that is comming back null from the > ClusteredSessionValve. > > -- > Bruce > Playboy.com > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Scholarships for Techies! > Can't afford IT training? All 2003 ictp students receive scholarships. > Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more. > www.ictp.com/training/sourceforge.asp > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user ------------------------------------------------------- This SF.net email is sponsored by: Scholarships for Techies! Can't afford IT training? All 2003 ictp students receive scholarships. Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more. www.ictp.com/training/sourceforge.asp _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user