-
1. Re: how to enable custom session cookies in mod cluster/ jboss 7.1.1
rhusar Apr 26, 2012 3:17 AM (in response to dbrane)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
jfclere Apr 26, 2012 4:16 AM (in response to rhusar)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
darraghs Apr 27, 2012 7:06 AM (in response to dbrane)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
dbrane Apr 27, 2012 12:12 PM (in response to darraghs)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
darraghs May 4, 2012 6:40 AM (in response to dbrane)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