Skip to content

Sessions across servers enabled by just applying a ServletFilter

License

Notifications You must be signed in to change notification settings

abatorQ/global-session-filter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Global Session Filter

This library provides global session variables across multiple Servlet containers.

The usage is very simple. After applying ServletFilter, just use javax.servlet.http.HttpSession as usual.

Session attributes and lifecycle will be managed by not a single Servlet container but an external datastore.

Supported Datastores

It's also possible to add new datastore (e.g. Redis).

  • Memcached (via Spymemcached)

How to use

MemcachedSessionFilter with Spymemcached

<repositories>
    <repository>
        <id>couchbase.com</id>
        <url>http://files.couchbase.com/maven2/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.m3</groupId>
        <artifactId>global-session-filter</artifactId>
        <version>[0.2,)</version>
    </dependency>
    <dependency>
        <groupId>spy</groupId>
        <artifactId>spymemcached</artifactId>
        <version>[2.8,)</version>
    </dependency>
<dependencies>

web.xml

<!-- Global Session Filter -->
<filter>

    <filter-name>GlobalSessionFilter</filter-name>
    <filter-class>com.m3.globalsession.filter.MemcachedSessionFilter</filter-class>
    <init-param>
        <param-name>memcachedServers</param-name>
        <param-value>server1:11211,server2:11211</param-value>
    </init-param>

    <!-- Optional -->
    <!--
    <init-param>
        <param-name>memcachedClientAdaptorClassName</param-name>
        <param-value>com.m3.globalsession.memcached.adaptor.SpymemcachedAdaptor</param-value>
    </init-param>
    -->

    <!-- Optional -->
    <!--
    <init-param>
        <param-name>namespace</param-name>
        <param-value>myapp</param-value>
    </init-param>
    <init-param>
        <param-name>sessionId</param-name>
        <param-value>__gsid__</param-value>
    </init-param>
    <init-param>
        <param-name>domain</param-name>
        <param-value></param-value>
    </init-param>
    <init-param>
        <param-name>path</param-name>
        <param-value>/</param-value>
    </init-param>
    <init-param>
        <param-name>secure</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>httpOnly</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>sessionTimeout</param-name>
        <param-value>30</param-value>
    </init-param>
    <init-param>
        <param-name>excludeRegExp</param-name>
        <param-value>/.+\.(html|jpg|jpeg|png|gif|js|css|swf)</param-value>
    </init-param>
    -->

</filter>

<filter-mapping>
    <filter-name>GlobalSessionFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

License

Copyright 2012 M3, Inc.

Apache License, Version 2.0

http://www.apache.org/licenses/LICENSE-2.0.html

About

Sessions across servers enabled by just applying a ServletFilter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%