Session replication in Tomcat with Hazelcast

When running Alfresco Share in a clustered environment, it’s recommended to use sticky sessions. Sticky sessions make sure that a user stays on the same server throughout the users interaction with Alfresco Share. There is one occasion where the user experience fails and that is when the server the user currently uses goes down for some reason. The next action in Alfresco Share the user executes will lead to a login screen for the user. This can be prevented if the session is replicated to all the other Alfresco Share servers in the cluster. There are multiple ways to achieve this. One way is to use memcached or couchbase as a session storage. Another is to use Hazelcast, the clustering solution already used by Alfresco.

In order to simplify deployment and upgrades, injecting stuff into the web.xml file for Alfresco Share is done as a post-processing step when installing Alfresco. This is achieved with an ant task, xmltask.

Installation steps (Ubuntu 12.04)

  • sudo apt-get install ant
  • sudo curl -o /usr/share/java/xmltask-1.16.1.jar -L http://downloads.sourceforge.net/project/xmltask/xmltask/1.16.1/xmltask.jar?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fxmltask%2Ffiles%2Fxmltask%2F1.16.1%2F&ts=1428909584&use_mirror=softlayer-ams
  • sudo ln -s /usr/share/java/xmltask-1.16.1.jar /usr/share/java/xmltask.jar
  • sudo ln -s /usr/share/java/xmltask.jar /usr/share/ant/lib/xmltask.jar
  • Create an ant build script that injects the correct filter, filter-mapping and session-listener elements into the web.xml.
<project name="post-process-share" default="modify" basedir=".">

  <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />

  <target name="modify">
    <xmltask source="./tomcat-share/webapps/share/WEB-INF/web.xml"
             dest="./tomcat-share/webapps/share/WEB-INF/web.xml"
             failWithoutMatch="true">

      <insert path="/:web-app/:filter[1]" position="before">
        <![CDATA[
        <filter>
          <filter-name>hazelcast-filter</filter-name>
          <filter-class>com.hazelcast.web.WebFilter</filter-class>
          <init-param>
            <param-name>map-name</param-name>
            <param-value>slingshot-sessions</param-value>
          </init-param>
          <init-param>
            <param-name>sticky-session</param-name>
            <param-value>false</param-value>
          </init-param>
          <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
          </init-param>
          <init-param>
            <param-name>use-client</param-name>
            <param-value>true</param-value>
          </init-param>
          <init-param>
            <param-name>instance-name</param-name>
            <param-value>slingshot</param-value>
          </init-param>
          <init-param>
            <param-name>client-config-location</param-name>
            <param-value>hazelcast-custom-client.properties</param-value>
          </init-param>
        </filter>
        ]]>
      </insert>

      <insert path="/:web-app/:filter-mapping[1]" position="before">
        <![CDATA[
        <filter-mapping>
          <filter-name>hazelcast-filter</filter-name>
          <url-pattern>/*</url-pattern>
          <dispatcher>FORWARD</dispatcher>
          <dispatcher>INCLUDE</dispatcher>
          <dispatcher>REQUEST</dispatcher>
        </filter-mapping>
        ]]>
      </insert>

      <insert path="/:web-app/:listener" position="before">
        <![CDATA[
        <listener>
          <listener-class>com.hazelcast.web.SessionListener</listener-class>
        </listener>
        ]]>
      </insert>

    </xmltask>
  </target>

</project>
  • In the install script, do something like
echo "Executing post-process steps . . ."
# unpack the share.war file in order to to post-process the web.xml
unzip -qq $ALFRESCO_TOMCAT_HOME_SHARE/webapps/share.war -d $ALFRESCO_TOMCAT_HOME_SHARE/webapps/share
# execute the ant build script
ant -q -f build-post-process.xml
echo ""
  • Create a hazelcast client settings file (hazelcast-custom-client.properties) and place it in the tomcat/shared/classes directory.
# the group name, password and port configured in the custom-slingshot-application-context.xml
hazelcast.client.group.name = slingshot
hazelcast.client.group.pass = alfresco
hazelcast.client.addresses  = localhost:5801
  • Two new dependencies must be added in order for the WebFilter and SessionListener to work with the above configuration. If using Maven, do this:
<!-- Hazelcast VM and Client added to have session replication -->
<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-wm</artifactId>
  <version>2.4</version>
</dependency>

<!-- There is a bug in ClientConfigBuilder that's fixed in 2.4.1 -->
<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-client</artifactId>
  <version>2.4.1</version>
</dependency>

With this setup in place, each and every server that’s a member in the cluster will replicate it’s sessions to all the other members. If (when…) one server goes down all users are transparently moved to a new server.

This entry was posted in Alfresco, cluster, share. Bookmark the permalink.

82 Responses to Session replication in Tomcat with Hazelcast

  1. see pron says:

    2ubUcv I think this is a real great post.Really thank you! Cool.

  2. This website certainly has all of the information and facts I wanted about this subject and didn at know who to ask.

  3. to read more says:

    Right now it sounds like Movable Type is the top blogging platform out there right now. (from what I ave read) Is that what you are using on your blog?

  4. Just got a Blogger account, it works good, but how do I find different users blogs I like with search. I remember there is a way, but I am not seeing it now. Thanks for your help..

  5. upper! Come on over and consult with my website.

  6. read more says:

    Really informative blog.Really looking forward to read more. Fantastic.

  7. you will have an amazing weblog here! would you wish to make some invite posts on my weblog?

  8. This is a really good tip especially to those new to the blogosphere. Simple but very precise info Appreciate your sharing this one. A must read post!

  9. blog9ja says:

    Very good post.Really looking forward to read more. Really Cool.

  10. make my blog jump out. Please let me know where you got your design.

  11. Very informative blog post.Really looking forward to read more. Great.

  12. Only wanna remark that you have a very nice internet site , I the design and style it actually stands out.

  13. some really great content on this site, regards for contribution.

  14. This unique blog is really cool as well as informative. I have chosen a lot of helpful things out of this amazing blog. I ad love to go back every once in a while. Thanks!

  15. Nice blog here! Additionally your website loads up very fast! What web host are you the usage of? Can I get your associate link to your host? I want my website loaded up as fast as yours lol

  16. of the subjects you write related to here. Again, awesome web site!

  17. I really liked your article.Really thank you! Really Cool.

  18. vi da ca sau says:

    You are my inspiration, I have few blogs and often run out from post . Analyzing humor is like dissecting a frog. Few people are interested and the frog dies of it. by E. B. White.

  19. Share this says:

    This blog is without a doubt educating and besides amusing. I have found a bunch of handy stuff out of this source. I ad love to come back again soon. Thanks a lot!

  20. Thanks for sharing, this is a fantastic article.Thanks Again. Cool.

  21. this topic. You realize so much its almost hard to argue with you (not

  22. Simply wanna input that you have a very decent website , I like the style and design it actually stands out.

  23. just go to says:

    liberals liberals liberals employed by non-public enterprise (or job creators).

  24. Share says:

    It as remarkable to pay a quick visit this web site and reading the views of all friends concerning this paragraph, while I am also eager of getting experience.

  25. concordium says:

    Looking forward to reading more. Great article post.Really thank you! Awesome.

  26. Wow, great article.Thanks Again. Fantastic.

  27. Thanks again for the article post. Keep writing.

  28. previous to and you are just too fantastic. I really like what

  29. You produce a strong financially viable decision whenever you decide to purchase a motor vehicle with a

  30. Im obliged for the article. Much obliged.

  31. to read more says:

    pretty beneficial material, overall I believe this is worth a bookmark, thanks

  32. Mantra Yoga says:

    There is evidently a bundle to identify about this. I consider you made some nice points in features also.

  33. Lung Health says:

    Many thanks for sharing this first-class post. Very inspiring! (as always, btw)

  34. Very neat post.Really thank you! Will read on

  35. Racecar says:

    I think this is a real great post.Really thank you! Much obliged.

  36. go says:

    victor cruz jersey have been decided by field goals. However, there are many different levels based on ability.

  37. home page says:

    Really informative blog post.Really looking forward to read more. Great.

  38. click here says:

    Very informative article post.Really thank you! Fantastic.

  39. Major thanks for the blog post.Much thanks again. Will read on

  40. Very nice blog post. I definitely love this website. Keep writing!

  41. Kallos says:

    Motyvacija kaip tvai galt padti savo vaikams Gimtasis odis

  42. This blog is obviously entertaining and besides amusing. I have found many useful stuff out of this amazing blog. I ad love to visit it again and again. Thanks a lot!

  43. There is perceptibly a bundle to identify about this. I feel you made various good points in features also.

  44. Candace says:

    Wow! This could be one particular of the most helpful blogs We ave ever arrive across on this subject. Actually Excellent. I am also an expert in this topic so I can understand your effort.

  45. beat it up says:

    Thanks for writing such a interesting article, I stumbled onto your blog and read a few posts. I like your style of writing

  46. The pursuing are the different types of lasers we will be thinking about for the purposes I pointed out above:

  47. I think, that you commit an error. I can defend the position. Write to me in PM, we will communicate.

  48. picked up something new from right here. I did however expertise a few technical points using this web site, since I experienced to reload the site many times previous to I could

  49. Search engine optimization (SEO) is the process of affecting the visibility of a website or a web page

  50. this website says:

    You created some decent points there. I looked more than the online world for the issue and positioned many people goes as well as together with your web site.

  51. it is part of it. With a boy, you will have

  52. Some truly good stuff on this website , I it.

  53. blue nike says:

    Thanks-a-mundo for the blog article.Much thanks again. Really Great.

  54. value says:

    This is one awesome article post.Much thanks again. Fantastic.

  55. Utterly composed written content , appreciate it for information.

  56. You are my intake , I have few web logs and sometimes run out from to brand.

  57. Waec exam says:

    This website was how do I say it? Relevant!! Finally I ave found something which helped me. Thanks a lot!

  58. Really appreciate you sharing this article.Really looking forward to read more. Want more.

  59. Keep up the great piece of work, I read few content on this web site and I think that your web blog is rattling interesting and contains lots of good info.

  60. Perfect work you have done, this internet site is really cool with superb info.

  61. Some genuinely nice stuff on this site, I like it.

  62. Thank you for another fantastic post. Where else could anybody get that type of information in such an ideal way of writing? I ave a presentation next week, and I am on the look for such information.

  63. Say, you got a nice article post.Much thanks again. Will read on

  64. If I start a blog on Myspace, will it get listed in search engines like Google? If so, is there a way to keep them from being crawled?.. Thank you.

  65. repair service, routine maintenance and electricity conservation of economic roofing systems will probably be as cost-effective as is possible. And using this

  66. Open Heavens says:

    The Hargrove clip was part of the biggest obstacles for Michael Kors Handbags Outlet and it

  67. This page definitely has all of the info I needed about this subject and didn at know who to ask.

  68. I value the blog.Much thanks again. Fantastic.

  69. I truly love this blog article.Thanks Again and again. Will read on

  70. Very informative article post.Really looking forward to read more. Great.

  71. When I look at your blog in Safari, it looks fine but

  72. Im obliged for the post.Really thank you! Cool.

  73. us says:

    Thank you for your blog post.Really looking forward to read more.

  74. twitter says:

    Im obliged for the blog.Much thanks again. Will read on

  75. WOW emphatically what I was looking representing. Came here by thorough on behalf of other

  76. Thanks again for the blog.Really looking forward to read more. Much obliged.

  77. There is definately a lot to find out about this subject. I love all the points you ave made.

  78. Usually I do not learn article on blogs, however I wish to say that this write-up very pressured me to take a look at and do it! Your writing taste has been surprised me. Thanks, very great article.

  79. website says:

    Thank you for your blog article. Really Cool.

  80. If you are concerned to learn Web optimization techniques then you should read this article, I am sure you will obtain much more from this article concerning SEO.

  81. Looking around I like to look around the web, regularly I will just go to Stumble Upon and follow thru

  82. good day says:

    Simply a smiling visitor here to share the love (:, btw outstanding pattern. Make the most of your regrets. To regret deeply is to live afresh. by Henry David Thoreau.

Leave a Reply to Instagram followers Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>