5 Replies Latest reply: May 4, 2012 6:40 AM by Darragh Sherwin RSS

    how to enable custom session cookies in mod cluster/ jboss 7.1.1

    Ram S Newbie

      Hi

       

      I created a jboss cluster with standalone instances, and have set up mod cluster  to provide fail over and load balancing.

      The fail over part works fine, but in my application we set a custom cookie and not the jsession id.

      I am trying to make sticky sessions work with a custom cookie, but when i pull up mod_cluster-manager, it always shows

      jsession id as the sticky session cookie name;

       

      Here is my configuration:

       

      CreateBalancers 1

      Maxsessionid 10

      <VirtualHost 0.0.0.0:8081>

              <Directory />

              Order deny,allow

              Deny from all

              Allow from all

              </Directory>

       

       

              <Location /mod_cluster-manager>

              SetHandler mod_cluster-manager

              Order deny,allow

              Deny from all

              Allow from all

              </Location>

              KeepAliveTimeout 60

              MaxKeepAliveRequests 0

          

              LogLevel debug

      ProxyPass / balancer://mycluster/ stickysession=abc nofailover=On

          ProxyPassReverse / balancer://mycluster/ stickysession=abc

       

       

              ManagerBalancerName mycluster

       

       

              #ServerAdvertise Off

              AllowDisplay On

              EnableMCPMReceive

      </VirtualHost>

       

      The corresponding mod cluster config on as7 is:

      <subsystem xmlns="urn:jboss:domain:modcluster:1.0">

              <mod-cluster-config proxy-list="0.0.0.0:8081" sticky-session="true" excluded-contexts="ROOT" >

              </mod-cluster-config>

      </subsystem>

       

      I don't see an immediate way to set the session cookie name (abc) into the mod cluster subsystem, but i suspect this is how i

      need to do it, because the mod cluster manager seems to get its sticky session information from the cluster and bypasses any proxypass

      settings i have set

       

      Please let me know what i am doing wrong with the configuration.

      I am using mod cluster 1.2.0.Final and JBOSS 7.1.1

       

      Thanks

        • 1. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
          Radoslav Husar Master

          Looking at Java Servlet 3.0 spec (JSR-000315) it says

          Containers may allow the name of the session tracking cookie to be customized through container specific configuration.

          Let me find how to do that in AS...

          • 2. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
            Jean-Frederic Clere Master

            try to put values to the system properties org.apache.catalina.JSESSIONID and org.apache.catalina.jsessionid in your standalone-ha.xml

            • 3. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
              Darragh Sherwin Newbie

              I have a similar setup using the same config for mod_cluster and and custom session id.

              My solution worked with mod_cluster 1.2.0 and jBoss AS 7.1.0 but it is not working with jBoss AS 7.1.1.

              It seems stickysession is no longer being honoured as I see a few calls being routed to the first node, then the next call to being routed to the second node.

               

              Here is my mod_cluster config

              <IfModule manager_module>

                Listen 10.152.20.223:6666

                ManagerBalancerName main-server-group

                <VirtualHost 10.152.20.223:6666>

                  <Location />

                     Order deny,allow

                     Deny from all

                     Allow from 10.152

                  </Location>

               

                  LogLevel debug

                  AllowDisplay On

                  KeepAliveTimeout 60

                  MaxKeepAliveRequests 0

                  ServerAdvertise on http://@IP@:6666

                  AdvertiseFrequency 5

                  AdvertiseSecurityKey ConnectAdSecurityKey

                  #AdvertiseGroup @ADVIP@:23364

                  EnableMCPMReceive

                  ProxyPass / balancer://main-server-group/ stickysession=JSESSIONID|jsessionid nofailover=On

                  ProxyPassReverse /  balancer://main-server-group/ stickysession=JSESSIONID|jsessionid

                  ProxyPreserveHost On

                  ProxyRequests Off

               

                 <Location /mod_cluster-manager>

                     SetHandler mod_cluster-manager

                     Order deny,allow

                     Deny from all

                     Allow from 10.152

                  </Location>

               

                </VirtualHost>

              </IfModule>

               

              Config from jBoss

                            <subsystem xmlns="urn:jboss:domain:modcluster:1.0">

                              <mod-cluster-config advertise-socket="modcluster" proxy-list="10.152.20.223:6666" balancer="main-server-group" domain="main-server-group" advertise-security-key="ConnectAdSecurityKey" sticky-session="true" sticky-session-force="true">

                                  <dynamic-load-provider history="10" decay="2">

                                      <load-metric type="cpu" weight="2" capacity="100"/>

                                      <load-metric type="sessions" weight="1" capacity="512"/>

                                  </dynamic-load-provider>

                              </mod-cluster-config>

                          </subsystem>

              • 4. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
                Ram S Newbie

                Hi Darah,

                 

                I finally got sticky sessions to work, but the solution was not pretty

                The servlet spec does allow custom session cookies to be used, and in Catalina Engine, you do that by

                setting the system property org.apache.catalina.SESSION_COOKIE_NAME and org.apache.catalina.SESSION_PARAMETER_NAME

                 

                Initially, I tried to simply set these properties in standalone-ha.xml (basically as a <system-properties> tag)

                However, it did not seem to matter.

                 

                Finally, I got the source cod eof mod_cluster, and went into DefaultMCMPRequestFactory and added logging to it

                 

                I notice that the following lines return the session cookie name and parameter to be JSESSIONID,jsessionid

                 

                String sessionCookieName = engine.getSessionCookieName();

                      if (!sessionCookieName.equals(DEFAULT_SESSION_COOKIE_NAME))

                      {

                         parameters.put("StickySessionCookie", sessionCookieName);

                      }

                      String sessionParameterName = engine.getSessionParameterName();

                      if (!sessionParameterName.equals(DEFAULT_SESSION_PARAMETER_NAME))

                      {

                         parameters.put("StickySessionPath", sessionParameterName);

                      }

                 

                 

                Irrespective of the system property that is being set. It looks like whatever engine is being used was hardcoding

                the session cookie name and parameter.

                I patched this class to override engine.getSessionCookieName(), with a system property if it found org.apache.catalina.SESSION_COOKIE_NAME

                and with this patch, sticky sessions work.

                 

                I still need to investigate why the engine hardcodes jsessionid....

                cursorily looking at mod_cluster source code, it appears to me CatalinaEngine is the only thing hardcoding this , but when i changed it to accept Globals.SESSION_COOKIE_NAME

                and Globals.SESSION_PARAMETER_NAME,, it did not seem to make a difference.

                 

                 

                Update :

                 

                Just checked out jboss as7 source code as well, and realized that the Globals.java class has been modified.  The session cookie system property is not

                org.apache.catalina.SESSION_COOKIE_NAME, but org.apache.catalina.JSESSIONID...

                when you set this property in standalone.xml sticky sessions will work

                • 5. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
                  Darragh Sherwin Newbie

                  Ram, 

                   

                  This is my code for setting the cookie as my sessionIds are coming from an upstream system.


                  ResponseBuilder responseBuilder = Response.status(status);
                  sessionId = sessionId + "." + java.net.InetAddress.getLocalHost().getHostName(); 
                  NewCookie sessionCookie = new NewCookie("JSESSIONID", sessionId, request.getContextPath(), null, 1, null,           600, false);      
                  responseBuilder.cookie(sessionCookie);      
                  return responseBuilder.build();

                   

                  This solution worked with jBoss7.1.0 but not when I moved to jBoss 7.1.1

                   

                  Thanks

                  Darragh