Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Sessions across servers enabled by just applying a ServletFilter
Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
samples/memcached
src
.gitignore
LICENSE.txt
README.md
eclipse-formatter.xml
pom.xml

README.md

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

Something went wrong with that request. Please try again.