views:

74

answers:

2

I am runnig a web application on tomcat 5.5.

How can I force dump of a session into disk

  1. on each request
  2. on each interval of time
A: 

Question 1 could be done using a filter or valve:

    public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws java.io.IOException, ServletException {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            HttpSession session = req.getSession(false);
            if(session != null) {
            dumpSession( session );
            }
            chain.doFilter(request, response);
        }
}

For Question 2 see this discussion

stacker
regarding solution one - I'd rather provide a solution that can be given using configuration files without code change.regarding solution 2 and the discussion you refered to- Assuming that the configuration is through context.xml file and 'manager' object, I couldn't figure what is the attribute that control the time-interval in which the session will be persisted
Spiderman
in addition regarding your code- 'dumpSession()' is not a known API
Spiderman
@Spiderman Right this left to the reader to implement this to write whatever format ;-)
stacker
A: 

Look at Persistent Manager http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html Setting maxIdleBackup and maxIdleSwap to 0 or near-zero time would persist session on every request. Setting these parameters to bigger value will give You dump in intervals.

Bartek Jablonski