public class WebSessionFilter extends Object implements javax.servlet.Filter
This is a request filter, that you need to specify in your web.xml
along
with ServletContextListenerStartup
to enable web sessions caching:
<listener> <listener-class>org.apache.ignite.startup.servlet.ServletContextListenerStartup</listener-class> </listener> <filter> <filter-name>WebSessionFilter</filter-name> <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class> </filter> <!-- You can also specify a custom URL pattern. --> <filter-mapping> <filter-name>IgniteWebSessionsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>It is also possible to specify a servlet name in a filter mapping, and a servlet URL pattern will be used in this case:
<filter> <filter-name>WebSessionFilter</filter-name> <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class> </filter> <filter-mapping> <filter-name>WebSessionFilter</filter-name> <servlet-name>YourServletName</servlet-name> </filter-mapping>The filter has the following optional configuration parameters:
Name | Description | Default |
---|---|---|
IgniteWebSessionsGridName | Name of the grid that contains cache for web session storage. | null (default grid) |
IgniteWebSessionsCacheName | Name of the cache for web session storage. | null (default cache) |
IgniteWebSessionsMaximumRetriesOnFail |
Valid for ATOMIC caches only. Maximum number of retries for session updates in case
node leaves topology and update fails. If retry is enabled,
some updates can be applied more than once, otherwise some
updates can be lost.
To disable retries, set this parameter to |
3 |
IgniteWebSessionsRetriesTimeout |
Retry timeout. Related to IgniteWebSessionsMaximumRetriesOnFail param.
Further attempts will be cancelled in case timeout was exceeded. |
10000 (10 seconds) |
<filter> <filter-name>WebSessionFilter</filter-name> <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class> <init-param> <param-name>IgniteWebSessionsGridName</param-name> <param-value>WebGrid</param-value> </init-param> <init-param> <param-name>IgniteWebSessionsCacheName</param-name> <param-value>WebCache</param-value> </init-param> <!-- Valid for ATOMIC caches only. --> <init-param> <param-name>IgniteWebSessionsMaximumRetriesOnFail</param-name> <param-value>10</param-value> </init-param> </filter>Note: filter init parameter has a priority over servlet context parameter; if you specify both, the servlet context parameter will be ignored.
CacheAtomicityMode.TRANSACTIONAL
cache
instead of CacheAtomicityMode.ATOMIC
. In this case each request
be processed inside pessimistic transaction which will guarantee that all
updates will be applied in correct order. This is important, for example,
if you get some attribute from the session, update its value and set new
value back to the session. In case of CacheAtomicityMode.ATOMIC
cache concurrent requests can get equal value, but CacheAtomicityMode.TRANSACTIONAL
cache will always process such updates one after another.Modifier and Type | Field and Description |
---|---|
static boolean |
DFLT_KEEP_BINARY_FLAG
Default keep binary flag.
|
static int |
DFLT_MAX_RETRIES_ON_FAIL
Default retry on fail flag value.
|
static int |
DFLT_RETRIES_ON_FAIL_TIMEOUT
Default retry on fail timeout flag value.
|
static String |
WEB_SES_CACHE_NAME_PARAM
Web sessions caching cache name parameter name.
|
static String |
WEB_SES_KEEP_BINARY_PARAM |
static String |
WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM
Web sessions caching retry on fail parameter name (valid for ATOMIC cache only).
|
static String |
WEB_SES_NAME_PARAM
Web sessions caching grid name parameter name.
|
static String |
WEB_SES_RETRIES_TIMEOUT_NAME_PARAM
Web sessions caching retry on fail timeout parameter name.
|
Constructor and Description |
---|
WebSessionFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
destroySession(String sesId) |
void |
doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain) |
void |
init(javax.servlet.FilterConfig cfg) |
String |
toString() |
void |
updateAttributes(String sesId,
Collection<org.apache.ignite.internal.util.typedef.T2<String,Object>> updates,
int maxInactiveInterval) |
void |
updateAttributesV2(String sesId,
org.apache.ignite.cache.websession.WebSessionV2 ses) |
public static final String WEB_SES_NAME_PARAM
public static final String WEB_SES_CACHE_NAME_PARAM
public static final String WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM
public static final String WEB_SES_RETRIES_TIMEOUT_NAME_PARAM
public static final String WEB_SES_KEEP_BINARY_PARAM
public static final int DFLT_MAX_RETRIES_ON_FAIL
public static final int DFLT_RETRIES_ON_FAIL_TIMEOUT
public static final boolean DFLT_KEEP_BINARY_FLAG
public void init(javax.servlet.FilterConfig cfg) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Filter
public void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
public void destroySession(String sesId)
sesId
- Session ID.public void updateAttributes(String sesId, Collection<org.apache.ignite.internal.util.typedef.T2<String,Object>> updates, int maxInactiveInterval)
sesId
- Session ID.updates
- Updates list.maxInactiveInterval
- Max session inactive interval.public void updateAttributesV2(String sesId, org.apache.ignite.cache.websession.WebSessionV2 ses) throws IOException
sesId
- Session ID.ses
- Web session.IOException
GridGain In-Memory Computing Platform : ver. 8.9.19 Release Date : April 10 2025