We recently started integrating spring-session in our project. This is a SOA based application and have some logic implementations to manage sessions.
- HttpSessionListener which we use to log out the sessions in case of timeout and monitored through sessionDestroyed(HttpSessionEvent httpSessionEvent).
- ServletRequestListener which we use to manage HTTP session invalidations. This is implemented in requestDestroyed(ServletRequestEvent servletRequestEvent) method.
For item #1, I found an article here, which describes the use of SessionEventHttpSessionListenerAdapter as supported by Spring Session. And have this configuration added in my session.xml.
<context:annotation-config/>
<bean class="org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration"/>
<bean class="org.springframework.session.web.http.SessionEventHttpSessionListenerAdapter">
<constructor-arg>
<list>
<bean class="xxx.xxx.xxx.xxx.xxx.xxx.MyHttpSessionListener"/>
</list>
</constructor-arg>
</bean>
Also added below configuration in my deployment descriptor (e.g. web.xml)
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
After some debugging, I have noticed that my HttpSessionListener is using the session provided by spring session.
However, for item #2, using ServletRequestListener implementation, I could not find a way to migrate it to spring session. It is still using the session provided by the container.
Is there a corresponding adapter, like SessionEventHttpSessionListenerAdapter, intended for ServletRequestListener? Is this supported by Spring Session? What other options do I have to get our functionality working with spring session?
I ended up using custom Filter to manage HTTP session invalidation. Modified the web.xml with the following entries in sequence:
(a) Register springSessionRepositoryFilter
(b) Add requestContextFilter
(c) Add custom filter
(d) Load spring session context
All HTTP requests are now using spring session.