questions for clustering tomcat sessions servlet spec 2.5

262 views
Skip to first unread message

Colin

unread,
May 20, 2011, 12:29:33 PM5/20/11
to Hazelcast, slo...@lim.com
Hello,

I'm interested in using Hazelcast to cluster Tomcat 6 session
information on EC2 cloud servers. I've read the hazelcast docs and
ran the clusterWebapp.sh script (hazelcast 1.9.3) As expected it
makes many changes to my web.xml file.

The docs also mention that all this filter, servlet, and jsp wrapping
is unnecessary for web apps on servlet spec 2.4+. All things being
equal I'd rather not have all my filters & servlets wrapped if this is
unnecessary, but I couldn't find any docs on how to configure session
clustering w/o clusterWebapp.sh.

Another post in forum mentioned a Hazelcast implementation of Tomcat
session manager interface, but again I never found a working example.

So my questions are
1. Is it possible to cluster sessions (servlet api 2.5) using only a
single Hazelcast filter entry in web.xml? To me this would be a nice,
simple solution, if possible.
2. If #1 is not possible then I need only replace Tomcat's default
session manager with a Hazelcast implementation? This would be ok
too.

Thank you,
Colin Ingarfield

Mehmet Dogan

unread,
May 20, 2011, 4:01:41 PM5/20/11
to haze...@googlegroups.com
It is not possible using servlet filter. You should set both a a catalina valve and a catalina session manager. Drop hazelcast-vm.jar into your server classpath.
Add a Manager element in context.xml; 

<Manager className="com.hazelcast.web.tomcat.HazelcastManager" />

and add a Valve element into server.xml

<Valve className="com.hazelcast.web.tomcat.HazelcastValve" />

Note that this feature uses default HazelcastInstance. To configure hazelcast you should use hazelcast.xml and drop it into server classpath too.

@mmdogan





--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


coli...@gmail.com

unread,
May 23, 2011, 5:27:02 PM5/23/11
to haze...@googlegroups.com, slo...@lim.com
mmdogan,

Thanks for replying so quickly.

Can you clarify .. is it possible to enable clustering using only the clusterWebapp.sh script, or is it also necessary to configure the Hazlecast Manager and Valve classes in Tomcat?  Or do the Manager/Valve classes eliminate the need to wrap elements in web.xml?

Thanks,
Colin

Mehmet Dogan

unread,
May 24, 2011, 1:15:35 AM5/24/11
to haze...@googlegroups.com

Hi

Hazelcast session manager and valve is second way of session clustering. Yes it is to eliminate need to wrap elements in web.xml and modify jsps.

@mmdogan

Colin Ingarfield

unread,
May 26, 2011, 1:22:20 PM5/26/11
to haze...@googlegroups.com
I tried using the Hazelcast Manager and Valve but I receive this error immediately after the my app context is loaded:

java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2400)
    at org.apache.catalina.connector.Request.getSession(Request.java:2104)
    at com.hazelcast.web.tomcat.HazelcastValve.invoke(HazelcastValve.java:47)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:889)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:732)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2262)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)


The HazelcastManager is in my <Context> element and the HazelcastValve is in the enclosing <Host> element.  I also receive this error if I put the valve in the outer <Engine> element.

However I do not receive this error if I put the valve in my <Context> (with the Manager.)  With this set up my app context starts successfully and I do see the __hz_ses_attrs map in the Hz Monitoring Tool.  Unfortunately my application behaves as if no session information is replicated.

I don't know how to proceed from here.  Is there a sample Tomcat configuration that is known to work that I could look at?  That would be helpful.

thanks,
Colin

Mehmet Dogan

unread,
Jun 6, 2011, 4:04:01 AM6/6/11
to haze...@googlegroups.com
Hi, 

Sorry for late response. There is a little bug that causes IllegalStateException when you put valve definition in either server.xml's Engine or Host. It is ok to put valve into context.xml (Context). This bug's will be in next release.

When you say "Unfortunately my application behaves as if no session information is replicated", how do you verify that session clustering is not working? 

@mmdogan




--
Reply all
Reply to author
Forward
0 new messages