org.codehaus.groovy.grails.web.servlet
Class GrailsDispatcherServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.springframework.web.servlet.HttpServletBean
              extended by org.springframework.web.servlet.FrameworkServlet
                  extended by org.springframework.web.servlet.DispatcherServlet
                      extended by org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
All Implemented Interfaces:
Serializable, EventListener, Servlet, ServletConfig, ApplicationListener
Direct Known Subclasses:
ErrorHandlingServlet

public class GrailsDispatcherServlet
extends DispatcherServlet

Servlet that handles incoming requests for Grails.

This servlet loads the Spring configuration based on the Grails application in the parent application context.

Since:
Jul 2, 2005
Author:
Steven Devijver, Graeme Rocher
See Also:
Serialized Form

Field Summary
protected  HandlerInterceptor[] interceptors
           
protected  MultipartResolver multipartResolver
           
 
Fields inherited from class org.springframework.web.servlet.DispatcherServlet
HANDLER_ADAPTER_BEAN_NAME, HANDLER_EXCEPTION_RESOLVER_BEAN_NAME, HANDLER_EXECUTION_CHAIN_ATTRIBUTE, HANDLER_MAPPING_BEAN_NAME, LOCALE_RESOLVER_ATTRIBUTE, LOCALE_RESOLVER_BEAN_NAME, MULTIPART_RESOLVER_BEAN_NAME, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger, REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, THEME_RESOLVER_ATTRIBUTE, THEME_RESOLVER_BEAN_NAME, THEME_SOURCE_ATTRIBUTE, VIEW_RESOLVER_BEAN_NAME, WEB_APPLICATION_CONTEXT_ATTRIBUTE
 
Fields inherited from class org.springframework.web.servlet.FrameworkServlet
DEFAULT_CONTEXT_CLASS, DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
 
Fields inherited from class org.springframework.web.servlet.HttpServletBean
logger
 
Constructor Summary
GrailsDispatcherServlet()
           
 
Method Summary
protected  HttpServletRequest checkMultipart(HttpServletRequest request)
          Convert the request into a multipart request, and make multipart resolver available.
protected  void copyParamsFromPreviousRequest(GrailsWebRequest previousRequestAttributes, GrailsWebRequest requestAttributes)
           
protected  WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
           
 void destroy()
           
protected  void doDispatch(HttpServletRequest request, HttpServletResponse response)
           
protected  HandlerInterceptor[] establishInterceptors(WebApplicationContext webContext)
          Evalutes the given WebApplicationContext for all HandlerInterceptor and WebRequestInterceptor instances
protected  HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache)
          Overrides the default behaviour to establish the handler from the GrailsApplication instance
protected  void initFrameworkServlet()
           
 void setApplication(GrailsApplication application)
           
protected  void triggerAfterCompletion(HandlerExecutionChain mappedHandler, int interceptorIndex, HttpServletRequest request, HttpServletResponse response, Exception ex)
          Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
protected  HttpServletResponse useWrappedOrOriginalResponse(HttpServletResponse response)
           
 
Methods inherited from class org.springframework.web.servlet.DispatcherServlet
buildLocaleContext, cleanupMultipart, createDefaultStrategy, doService, getDefaultStrategies, getDefaultStrategy, getDefaultViewName, getHandlerAdapter, getLastModified, getMultipartResolver, getThemeSource, initStrategies, noHandlerFound, onRefresh, processHandlerException, render, resolveViewName, setCleanupAfterInclude, setDetectAllHandlerAdapters, setDetectAllHandlerExceptionResolvers, setDetectAllHandlerMappings, setDetectAllViewResolvers, setThreadContextInheritable
 
Methods inherited from class org.springframework.web.servlet.FrameworkServlet
doDelete, doGet, doPost, doPut, getContextClass, getContextConfigLocation, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initServletBean, initWebApplicationContext, isPublishContext, isPublishEvents, onApplicationEvent, postProcessWebApplicationContext, processRequest, refresh, setContextClass, setContextConfigLocation, setNamespace, setPublishContext, setPublishEvents
 
Methods inherited from class org.springframework.web.servlet.HttpServletBean
addRequiredProperty, getServletContext, getServletName, init, initBeanWrapper
 
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletInfo, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interceptors

protected HandlerInterceptor[] interceptors

multipartResolver

protected MultipartResolver multipartResolver
Constructor Detail

GrailsDispatcherServlet

public GrailsDispatcherServlet()
Method Detail

initFrameworkServlet

protected void initFrameworkServlet()
                             throws ServletException,
                                    BeansException
Overrides:
initFrameworkServlet in class FrameworkServlet
Throws:
ServletException
BeansException

createWebApplicationContext

protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
                                                     throws BeansException
Overrides:
createWebApplicationContext in class FrameworkServlet
Throws:
BeansException

establishInterceptors

protected HandlerInterceptor[] establishInterceptors(WebApplicationContext webContext)
Evalutes the given WebApplicationContext for all HandlerInterceptor and WebRequestInterceptor instances

Parameters:
webContext - The WebApplicationContext
Returns:
An array of HandlerInterceptor instances

destroy

public void destroy()
Specified by:
destroy in interface Servlet
Overrides:
destroy in class FrameworkServlet

setApplication

public void setApplication(GrailsApplication application)

doDispatch

protected void doDispatch(HttpServletRequest request,
                          HttpServletResponse response)
                   throws Exception
Overrides:
doDispatch in class DispatcherServlet
Throws:
Exception

useWrappedOrOriginalResponse

protected HttpServletResponse useWrappedOrOriginalResponse(HttpServletResponse response)

copyParamsFromPreviousRequest

protected void copyParamsFromPreviousRequest(GrailsWebRequest previousRequestAttributes,
                                             GrailsWebRequest requestAttributes)

triggerAfterCompletion

protected void triggerAfterCompletion(HandlerExecutionChain mappedHandler,
                                      int interceptorIndex,
                                      HttpServletRequest request,
                                      HttpServletResponse response,
                                      Exception ex)
                               throws Exception
Trigger afterCompletion callbacks on the mapped HandlerInterceptors. Will just invoke afterCompletion for all interceptors whose preHandle invocation has successfully completed and returned true.

Parameters:
mappedHandler - the mapped HandlerExecutionChain
interceptorIndex - index of last interceptor that successfully completed
ex - Exception thrown on handler execution, or null if none
Throws:
Exception
See Also:
HandlerInterceptor.afterCompletion(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)

checkMultipart

protected HttpServletRequest checkMultipart(HttpServletRequest request)
                                     throws MultipartException
Convert the request into a multipart request, and make multipart resolver available. If no multipart resolver is set, simply use the existing request.

Overrides:
checkMultipart in class DispatcherServlet
Parameters:
request - current HTTP request
Returns:
the processed request (multipart wrapper if necessary)
Throws:
MultipartException

getHandler

protected HandlerExecutionChain getHandler(HttpServletRequest request,
                                           boolean cache)
                                    throws Exception
Overrides the default behaviour to establish the handler from the GrailsApplication instance

Overrides:
getHandler in class DispatcherServlet
Parameters:
request - The request
cache - Whether to cache the Handler in the request
Returns:
The HandlerExecutionChain
Throws:
Exception


Copyright (c) 2005-2006 The Grails project