org.jasig.cas.web.init
Class SafeDispatcherServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.jasig.cas.web.init.SafeDispatcherServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public final class SafeDispatcherServlet
extends javax.servlet.http.HttpServlet

This servlet wraps the Spring DispatchServlet, catching any exceptions it throws on init() to guarantee that servlet initialization succeeds. This allows our application context to succeed in initializing so that we can display a friendly "CAS is not available" page to the deployer (an appropriate use of the page in development) or to the end user (an appropriate use of the page in production). The error page associated with this deployment failure is configured in the web.xml via the standard error handling mechanism.

If the underlying Spring DispatcherServlet failed to init(), this SafeDispatcherServlet will throw an org.springframework.context.ApplicationContextException on service().

The exception thrown by the underlying Spring DispatcherServlet init() and caught in the SafeDispatcherServlet init() is exposed as a Servlet Context attribute under the key "exceptionCaughtByServlet".

Version:
$Revision: 48180 $ $Date: 2010-03-14 00:05:58 -0500 (Sun, 14 Mar 2010) $
Author:
Andrew Petro
See Also:
DispatcherServlet, Serialized Form

Field Summary
static java.lang.String CAUGHT_THROWABLE_KEY
          Key under which we will store the exception in the ServletContext.
 
Constructor Summary
SafeDispatcherServlet()
           
 
Method Summary
 void init(javax.servlet.ServletConfig config)
           
 void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAUGHT_THROWABLE_KEY

public static final java.lang.String CAUGHT_THROWABLE_KEY
Key under which we will store the exception in the ServletContext.

See Also:
Constant Field Values
Constructor Detail

SafeDispatcherServlet

public SafeDispatcherServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet

service

public void service(javax.servlet.ServletRequest req,
                    javax.servlet.ServletResponse resp)
             throws javax.servlet.ServletException,
                    java.io.IOException
Specified by:
service in interface javax.servlet.Servlet
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
org.springframework.context.ApplicationContextException - if the DispatcherServlet does not initialize properly, but the servlet attempts to process a request.
javax.servlet.ServletException
java.io.IOException


Copyright © 2004-2010 Java Architectures Special Interest Group. All Rights Reserved.