/appng-tomcat-session

Support for stateless appNG nodes by storing the user session in an external session store.

Primary LanguageJavaApache License 2.0Apache-2.0

appng logo

appNG Tomcat Session

This library contains implementations of Apache Tomcats org.apache.catalina.Manager using Redis, Hazelcast and MongoDB.

Prerequisites

By default, Tomcats uses it’s own logging component named JULI, writing logfiles to CATALINA_HOME/logs.

However, if you want to see some logging in the appNG.log of your appNG installation, move the following files from APPNG_HOME/WEB-INF/lib into the CATALINA_HOME/lib directory:

  • log4j-1.2.17.jar

  • slf4j-api-1.7.25.jar

  • slf4j-log4j12-1.7.25.jar

Next, set the category for org.appng.tomcat.session in APPNG_HOME/WEB-INF/conf/log4j.properties to the required level:

log4j.category.org.appng.tomcat.session = trace

Using Redis

This implementation uses Redis to store sessions. It is based on the great work of James Coleman’s tomcat-redis-session-manager.

A few changes were made to support Tomcat 8 and the latest version of Redis.

Configuration

Add the following into your Tomcat context.xml (or the context block of the server.xml if applicable.)

<Valve className="org.appng.tomcat.session.redis.RedisSessionHandlerValve" />
<Manager className="org.appng.tomcat.session.redis.RedisSessionManager"
    host="localhost"
    port="6379"
    database="0"
    maxInactiveInterval="60"
    sessionPersistPolicies="ALWAYS_SAVE_AFTER_REQUEST" />

Copy the following files into the TOMCAT_BASE/lib directory:

Reboot the server, and sessions should now be stored in Redis.

Using MongoDB

This implementation uses MongoDB to store sessions.

Configuration

Add the following into your Tomcat context.xml (or the context block of the server.xml if applicable.)

<Valve className="org.appng.tomcat.session.mongo.MongoSessionTrackerValve" />
<Manager className="org.appng.tomcat.session.mongo.MongoPersistentManager" maxIdleBackup="30">
	<Store className="org.appng.tomcat.session.mongo.MongoStore"
		hosts="localhost:27017"
		dbName="tomcat_sessions"
		maxPoolSize="25"
	/>
</Manager>

Copy the following files into the TOMCAT_BASE/lib directory:

Reboot the server, and sessions should now be stored in MongoDB.

Using Hazelcast

The implementation is based on Hazelcast, using an IMap.

Configuration

Add the following into your Tomcat context.xml (or the context block of the server.xml if applicable.)

<?xml version='1.0' encoding='utf-8'?>
<Context>
	<Valve   className="org.appng.tomcat.session.hazelcast.HazelcastSessionTrackerValve" />
	<!-- configFile must use a path from classpath -->
	<Manager className="org.appng.tomcat.session.hazelcast.HazelcastManager" configFile="hazelcast.xml" />
</Context>

Copy the following files into the TOMCAT_BASE/lib directory:

Reboot the server, and sessions are now stored in Hazelcast.

License

appNG is licensed under the Apache License 2.0.