tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Kerber <dcker...@verizon.net>
Subject Re: Logging session timeouts
Date Thu, 09 Feb 2006 15:56:01 GMT
I got your code in, and it compiles, but I don't understand how I 
configure the url-mapping you refer to.  Could you point me to some docs 
for that?  I looked through the web.xml files (both the server one, and 
the one for the app), but couldn't find anything about url-mapping or 
filters that seemed to apply to this.  It may be there, but I don't know 
enough about it to recognize it.

Thanks!
Dave


Tim Lucia wrote:

>Below is a filter which keeps track of how many sessions are attached to a
>web app.  The key part is the HttpSessionBindingListener interface.
>
>Tim
>
>
>/**
> * J2EE "Filter" to count page hits.  What it counts depends on the
>url-mapping
> * in web.xml.
> * 
> * @author tim.lucia
> */
>public class SessionCountFilter
>    implements Filter, HttpSessionBindingListener, Serializable
>{
>    private final static Log logger =
>LogFactory.getLog(SessionCountFilter.class);
>    
>    public static final Hashtable sessions = new Hashtable();
>    public static int sessionCountHighWater = 0;
>    
>    /**
>     * Container startup notification
>     */
>    public void init(FilterConfig arg0) throws ServletException 
>    {
>        logger.debug("init(): " + arg0);
>    }
>
>    /**
>     * Container shutdown notification
>     */
>    public void destroy() 
>    {
>        logger.debug("destroy()");
>    }
>
>    /**
>     * Process the container's filter request.
>     * @param request - Request object
>     * @param response - response object
>     * @param chain - next filter in the chain.
>     */    
>    public void doFilter(ServletRequest request, ServletResponse response,
>                         FilterChain chain)
>        throws IOException, ServletException 
>    {
>        chain.doFilter(request, response);
>
>        HttpServletRequest httpRequest = (HttpServletRequest)request;
>        HttpSession session = httpRequest.getSession(false);
>        if (logger.isDebugEnabled()) {
>            logger.debug("Request " + httpRequest.getRequestURI() + 
>                    (session == null ? " returned no session" :
>                     " belongs to session ID " + session.getId()));
>        }
>
>        // Bind to the session, if there is one, and it is new:
>        if (null != session && session.isNew()) {
>            session.setAttribute(toString(), this);
>        }
>    }
>
>    /**
>     * Implement HttpSessionBindingListener#valueBound
>     */
>    public void valueBound(HttpSessionBindingEvent bindEvent) 
>    {
>        HttpSession session = bindEvent.getSession();
>        final String sessionID = session.getId();
>        sessions.put(session, sessionID);
>        if (logger.isDebugEnabled()) {
>            logger.debug("[" + sessions.size() + "] CREATE:  " + sessionID);
>        }
>        sessionCountHighWater = 
>            (sessionCountHighWater < sessions.size() ? sessions.size() :
>sessionCountHighWater);
>    }
>
>    /**
>     * Implement HttpSessionBindingListener#valueUnbound
>     */
>    public void valueUnbound(HttpSessionBindingEvent bindEvent) 
>    {
>        HttpSession session = bindEvent.getSession();
>        final String sessionID = (String)sessions.get(session);
>        sessions.remove(session);
>        if (logger.isDebugEnabled()) {
>            logger.debug("[" + sessions.size() + "] DESTROY: " + sessionID);
>        }
>    }
>    
>    /**
>     * Return current count of sessions
>     * @return The number of sessions currently tracked
>     */
>    public static int getSessionCount()
>    {
>        return sessions.size();
>    }
>    
>    /**
>     * Return high water mark of number of sessions
>     * @return The high water mark of sessions tracked
>     */
>    public static int getSessionCountHighWater()
>    {
>        return sessionCountHighWater;
>    }
>    
>    /**
>     * Return string representation of this object
>     * @return a String representation of this object
>     */
>    public String toString()
>    {
>        return getClass().getName() + "#" + hashCode();        
>    }
>} 
>
>-----Original Message-----
>From: David Kerber [mailto:dckerber@verizon.net] 
>Sent: Thursday, February 09, 2006 9:38 AM
>To: Tomcat Users List
>Subject: Logging session timeouts
>
>Is there any way of trapping session timeouts, so I can log them?  I am
>logging when a user logs in and when they explicitly log out, but would like
>to log when their session times out, if that is possible.
>
>TIA!
>Dave
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message