com.wwm.context.servlet
Class WebContainerAppListener

java.lang.Object
  extended by com.wwm.context.servlet.WebContainerAppListener
All Implemented Interfaces:
EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener

public class WebContainerAppListener
extends Object
implements javax.servlet.ServletContextListener, javax.servlet.http.HttpSessionListener

Class to listen for servlet start/stop events, and session start/end events, and ensure that we make things available elsewhere. This class can be registered in web.xml to configure then servlet container to call here at the appropriate points.

Author:
Neale Upstone

Constructor Summary
WebContainerAppListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent arg0)
           
 void contextInitialized(javax.servlet.ServletContextEvent event)
          Anything need doing when registering
static WebContainerAppListener getInstance()
           
static SessionContext getSessionContext(javax.servlet.http.HttpSession session)
          Get our SessionContext for this session.
 void postRequest(javax.servlet.http.HttpServletRequest request)
           
 void preRequest(ApplicationContext applicationContext, javax.servlet.http.HttpServletRequest request)
          Prior to the request, we need to pass our app context and session context data into our ThreadLocal based container, so that correct ones for this request can be retrieved during servicing of the request.
 void sessionCreated(javax.servlet.http.HttpSessionEvent event)
          Things to do at beginning of a new session.
 void sessionDestroyed(javax.servlet.http.HttpSessionEvent arg0)
          Do whatever needs doing at end of the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebContainerAppListener

public WebContainerAppListener()
Method Detail

getInstance

public static WebContainerAppListener getInstance()

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)
Anything need doing when registering

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent arg0)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

sessionCreated

public void sessionCreated(javax.servlet.http.HttpSessionEvent event)
Things to do at beginning of a new session.

Specified by:
sessionCreated in interface javax.servlet.http.HttpSessionListener

sessionDestroyed

public void sessionDestroyed(javax.servlet.http.HttpSessionEvent arg0)
Do whatever needs doing at end of the session.

Specified by:
sessionDestroyed in interface javax.servlet.http.HttpSessionListener

preRequest

public void preRequest(ApplicationContext applicationContext,
                       javax.servlet.http.HttpServletRequest request)
Prior to the request, we need to pass our app context and session context data into our ThreadLocal based container, so that correct ones for this request can be retrieved during servicing of the request. The good news about ThreadLocals is that they are tied to the Thread instance, so when the Thread is destroyed, so is the data we have tied to that thread. The BAD news, which we do deal with, is that under a Web App Server, the threads don't get destroyed so we need to do some cleaning up.

Parameters:
applicationContext - - supplied from external singleton bean, so we don't need
request -

getSessionContext

public static SessionContext getSessionContext(javax.servlet.http.HttpSession session)
Get our SessionContext for this session. This is stored in the HttpSession for persistence between requests, so this method will first try to retrieve it from the session, and if one isn't found, it creates one and then adds it to the session.

Parameters:
session -
Returns:

postRequest

public void postRequest(javax.servlet.http.HttpServletRequest request)


Copyright © 2004 or was it 2003-2011 Whirlwind Match Limited. All Rights Reserved.