com.hazelcast.web
Class WebFilter
java.lang.Object
com.hazelcast.web.WebFilter
- All Implemented Interfaces:
- javax.servlet.Filter
- Direct Known Subclasses:
- SpringAwareWebFilter
public class WebFilter
- extends Object
- implements javax.servlet.Filter
Provides clustered sessions by backing session data with an IMap
.
Using this filter requires also registering a SessionListener
to provide session timeout notifications.
Failure to register the listener when using this filter will result in session state getting out of sync between
the servlet container and Hazelcast.
This filter supports the following <init-param>
values:
use-client
: When enabled, a HazelcastClient
is
used to connect to the cluster, rather than joining as a full node. (Default: false
)
config-location
: Specifies the location of an XML configuration file that can be used to
initialize the HazelcastInstance
(Default: None; the HazelcastInstance
is initialized
using its own defaults)
client-config-location
: Specifies the location of an XML configuration file that can be
used to initialize the HazelcastInstance
. This setting is only checked when use-client
is set to true
. (Default: Falls back on config-location
)
instance-name
: Names the HazelcastInstance
. This can be used to reference an already-
initialized HazelcastInstance
in the same JVM (Default: The configured instance name, or a
generated name if the configuration does not specify a value)
shutdown-on-destroy
: When enabled, shuts down the HazelcastInstance
when the filter is
destroyed (Default: true
)
map-name
: Names the IMap
the filter should use to persist session details (Default:
"_web_" + ServletContext.getServletContextName()
; e.g. "_web_MyApp")
session-ttl-seconds
: Sets the time-to-live
for
the IMap
used to persist session details (Default: Uses the existing MapConfig
setting
for the IMap
, which defaults to infinite)
sticky-session
: When enabled, optimizes IMap
interactions by assuming individual sessions
are only used from a single node (Default: true
)
deferred-write
: When enabled, optimizes IMap
interactions by only writing session attributes
at the end of a request. This can yield significant performance improvements for session-heavy applications
(Default: false
)
cookie-name
: Sets the name for the Hazelcast session cookie (Default:
"hazelcast.sessionId"
cookie-domain
: Sets the domain for the Hazelcast session cookie (Default: null
)
cookie-secure
: When enabled, indicates the Hazelcast session cookie should only be sent over
secure protocols (Default: false
)
cookie-http-only
: When enabled, marks the Hazelcast session cookie as "HttpOnly", indicating
it should not be available to scripts (Default: false
)
cookie-http-only
requires a Servlet 3.0-compatible container, such as Tomcat 7+ or Jetty 8+
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
WEB_FILTER_ATTRIBUTE_KEY
public static final String WEB_FILTER_ATTRIBUTE_KEY
HAZELCAST_SESSION_ATTRIBUTE_SEPARATOR
protected static final String HAZELCAST_SESSION_ATTRIBUTE_SEPARATOR
- See Also:
- Constant Field Values
LOGGER
protected static final ILogger LOGGER
NULL_ENTRY
protected static final WebFilter.LocalCacheEntry NULL_ENTRY
HAZELCAST_REQUEST
protected static final String HAZELCAST_REQUEST
- See Also:
- Constant Field Values
HAZELCAST_SESSION_COOKIE_NAME
protected static final String HAZELCAST_SESSION_COOKIE_NAME
- See Also:
- Constant Field Values
servletContext
protected javax.servlet.ServletContext servletContext
filterConfig
protected javax.servlet.FilterConfig filterConfig
WebFilter
public WebFilter()
WebFilter
public WebFilter(Properties properties)
init
public final void init(javax.servlet.FilterConfig config)
throws javax.servlet.ServletException
- Specified by:
init
in interface javax.servlet.Filter
- Throws:
javax.servlet.ServletException
createNewSession
protected WebFilter.HazelcastHttpSession createNewSession(WebFilter.RequestWrapper requestWrapper,
String existingSessionId)
createHazelcastHttpSession
protected WebFilter.HazelcastHttpSession createHazelcastHttpSession(String id,
javax.servlet.http.HttpSession originalSession,
boolean deferredWrite)
HazelcastHttpSession instance
creation is split off to a separate method to allow subclasses to return a
customized / extended version of HazelcastHttpSession
.
- Parameters:
id
- the session idoriginalSession
- the original sessiondeferredWrite
- whether writes are deferred
- Returns:
- a new HazelcastHttpSession instance
destroySession
protected void destroySession(WebFilter.HazelcastHttpSession session,
boolean invalidate)
- Destroys a session, determining if it should be destroyed clusterwide automatically or via expiry.
- Parameters:
session
- the session to be destroyed locallyinvalidate
- true
if the session has been invalidated and should be destroyed on all nodes
in the cluster; otherwise, false
to only remove the session globally if this
node was the final node referencing it
doFilter
public final void doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
- Specified by:
doFilter
in interface javax.servlet.Filter
- Throws:
IOException
javax.servlet.ServletException
destroy
public final void destroy()
- Specified by:
destroy
in interface javax.servlet.Filter
getInstance
protected HazelcastInstance getInstance(Properties properties)
throws javax.servlet.ServletException
- Throws:
javax.servlet.ServletException
shutdownInstance
protected void shutdownInstance()
Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.