Jetty Web Session Replication
Web Session Replication is replicating web sessions to other members of the cluster each time there is a change in the session data. With session replication, session-failover is automatic. If an application server goes offline, the load balancer simply sends incoming requests to another server. The user can be sent to any server, as all servers have a copy of the user’s session.
Jetty Web Server
Jetty is a pure Java-based HTTP (Web) server and Java Servlet container. While web servers are usually associated with serving documents to people, Jetty is often used for machine-to-machine communications, usually within larger software frameworks. Jetty is developed as a free and open source project as part of the Eclipse Foundation. Jetty supports the latest Java Servlet API (with JSP support) as well as protocols SPDY and WebSocket.
Hazelcast IMDG and Jetty
You can use Jetty Web Session Replication with Hazelcast IMDG® version 3.0 or higher. Jetty Web Session Replication with Hazelcast IMDG is a container specific module that enables you to perform session replication for JEE Web Applications without making changes to your applications. Jetty Session Replication in Hazelcast IMDG is a Hazelcast® Module where the state of each created HttpSessionObject is kept in the Hazelcast Distributed Map.
No Lost User Sessions
Let’s say you have more than one web server (A,B,C) with a load balancer. Once one of the servers goes down, you don’t lose user sessions. Users will be routed to other servers (B or C) and they will not notice something is wrong with Server A. You can also scale your web servers under heavy load. You can easily add new servers to your cluster. Sessions will be evenly distributed across the Hazelcast Cluster. You can even shut down servers from cluster without losing any session.
The following are required for enabling Hazelcast Session Clustering with Jetty.
- Jetty 7, 8, and 9 are supported
- The target application or web server should support Java 1.6+
- The target application or web server should support Servlet 3.0+ spec
- The session objects that need to be clustered have to be serializable
Easy to Set Up
An advantage of the Jetty Session Replication Module for Hazelcast IMDG is that you don’t change anything in your application. You only need to perform some configuration in your Jetty container to easily attach Hazelcast Session Replication to your web applications.
To configure Jetty for Hazelcast IMDG:
hazelcast.xmlin the folder
hazelcast.xml (if you want to change defaults) in the folder $JETTY_HOME/lib/ext.
Configuring the HazelcastSessionIdManager
<Set name="sessionIdManager"> <New id="hazelcastIdMgr" class="com.hazelcast.session.HazelcastSessionIdManager"> <Arg><Ref id="Server"/></Arg> <Set name="configLocation">etc/hazelcast.xml</Set> </New> </Set>
Configuring the HazelcastSessionManager
The file context.xml should have the following content.
<Ref name="Server" id="Server"> <Call id="hazelcastIdMgr" name="getSessionIdManager"/> </Ref> <Set name="sessionHandler"> <New class="org.eclipse.jetty.server.session.SessionHandler"> <Arg> <New id="hazelcastMgr" class="com.hazelcast.session.HazelcastSessionManager"> <Set name="idManager"> <Ref id="hazelcastIdMgr"/> </Set> </New> </Arg> </New> </Set>
Products in this Use Case: