org.jasig.cas.web.init
Class SafeContextLoaderListener
java.lang.Object
org.jasig.cas.web.init.SafeContextLoaderListener
- All Implemented Interfaces:
- java.util.EventListener, javax.servlet.ServletContextListener
public final class SafeContextLoaderListener
- extends java.lang.Object
- implements javax.servlet.ServletContextListener
A ServletContextListener which wraps Spring's
ContextLoaderListener and catches anything that delegate throws so as
to prevent its having thrown a Throwable from aborting the initialization of
our entire web application context. Use of this ContextListener will not be
appropriate for all deployments of a web application. Sometimes, a context
listener's aborting context initialization is exactly the desired behavior.
This might be because the resulting application inavailability is acceptable
or because another layer (Apache, a proxy, a balancer, etc.) detects the
inavailability of the context and provides an appropriate user experience. Or
because a root context handles all requests that aren't otherwise handled.
There are many fine alternatives to this approach. However, when using the
bare Tomcat container with CAS as the root context, if your desired behavior
is that a failure at context initialization results in a dummy CAS context
that presents a user-friendly "CAS is unavailable at this time" message,
using this ContextListener in place of Spring's ContextLoaderListener
should do the trick. The error page associated with this deployment failure
is configured in the web.xml via the standard error handling mechanism.
Rather than being a generic ContextListener wrapper that will make safe any
ContextListener, instead this implementation specifically wraps and delegates
to a Spring ContextLoaderListener. As such, mapping this listener in
web.xml is a one for one replacement for ContextLoaderListener.
The exception thrown is exposed in the Servlet Context under the key
"exceptionCaughtByListener".
- Version:
- $Revision: 48180 $ $Date: 2010-03-14 00:05:58 -0500 (Sun, 14 Mar 2010) $
- Author:
- Andrew Petro
- See Also:
ContextLoaderListener
|
Field Summary |
static java.lang.String |
CAUGHT_THROWABLE_KEY
The name of the ServletContext attribute whereat we will place a List of
Throwables that we caught from our delegate context listeners. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CAUGHT_THROWABLE_KEY
public static final java.lang.String CAUGHT_THROWABLE_KEY
- The name of the ServletContext attribute whereat we will place a List of
Throwables that we caught from our delegate context listeners.
- See Also:
- Constant Field Values
SafeContextLoaderListener
public SafeContextLoaderListener()
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent sce)
- Specified by:
contextInitialized in interface javax.servlet.ServletContextListener
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent sce)
- Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener
Copyright © 2004-2010 Java Architectures Special Interest Group. All Rights Reserved.