org.springframework.web.servlet
Class DispatcherServlet

java.lang.Object
  extended by HttpServlet
      extended by org.springframework.web.servlet.HttpServletBean
          extended by org.springframework.web.servlet.FrameworkServlet
              extended by org.springframework.web.servlet.DispatcherServlet

public class DispatcherServlet
extends FrameworkServlet

Central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers or HTTP-based remote service exporters. Dispatches to registered handlers for processing a web request, providing convenient mapping and exception handling facilities.

This servlet is very flexible: It can be used with just about any workflow, with the installation of the appropriate adapter classes. It offers the following functionality that distinguishes it from other request-driven web MVC frameworks:

NOTE: The @RequestMapping annotation will only be processed if a corresponding HandlerMapping (for type level annotations) and/or HandlerAdapter (for method level annotations) is present in the dispatcher. This is the case by default. However, if you are defining custom HandlerMappings or HandlerAdapters, then you need to make sure that a corresponding custom DefaultAnnotationHandlerMapping and/or AnnotationMethodHandlerAdapter is defined as well - provided that you intend to use @RequestMapping.

A web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.

Author:
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
HttpRequestHandler, Controller, ContextLoaderListener

Field Summary
private  boolean cleanupAfterInclude
          Perform cleanup of request attributes after include request?
private static java.lang.String DEFAULT_STRATEGIES_PATH
          Name of the class path resource (relative to the DispatcherServlet class) that defines DispatcherServlet's default strategy names.
private static java.util.Properties defaultStrategies
           
private  boolean detectAllHandlerAdapters
          Detect all HandlerAdapters or just expect "handlerAdapter" bean?
private  boolean detectAllHandlerExceptionResolvers
          Detect all HandlerExceptionResolvers or just expect "handlerExceptionResolver" bean?
private  boolean detectAllHandlerMappings
          Detect all HandlerMappings or just expect "handlerMapping" bean?
private  boolean detectAllViewResolvers
          Detect all ViewResolvers or just expect "viewResolver" bean?
static java.lang.String HANDLER_ADAPTER_BEAN_NAME
          Well-known name for the HandlerAdapter object in the bean factory for this namespace.
static java.lang.String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
          Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace.
static java.lang.String HANDLER_MAPPING_BEAN_NAME
          Well-known name for the HandlerMapping object in the bean factory for this namespace.
private  java.util.List<HandlerAdapter> handlerAdapters
          List of HandlerAdapters used by this servlet
private  java.util.List<HandlerExceptionResolver> handlerExceptionResolvers
          List of HandlerExceptionResolvers used by this servlet
private  java.util.List<HandlerMapping> handlerMappings
          List of HandlerMappings used by this servlet
static java.lang.String LOCALE_RESOLVER_ATTRIBUTE
          Request attribute to hold the current LocaleResolver, retrievable by views.
static java.lang.String LOCALE_RESOLVER_BEAN_NAME
          Well-known name for the LocaleResolver object in the bean factory for this namespace.
private  LocaleResolver localeResolver
          LocaleResolver used by this servlet
static java.lang.String MULTIPART_RESOLVER_BEAN_NAME
          Well-known name for the MultipartResolver object in the bean factory for this namespace.
private  MultipartResolver multipartResolver
          MultipartResolver used by this servlet
static java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
          Log category to use when no mapped handler is found for a request.
protected static Log pageNotFoundLogger
          Additional logger to use when no mapped handler is found for a request.
static java.lang.String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME
          Well-known name for the RequestToViewNameTranslator object in the bean factory for this namespace.
static java.lang.String THEME_RESOLVER_ATTRIBUTE
          Request attribute to hold the current ThemeResolver, retrievable by views.
static java.lang.String THEME_RESOLVER_BEAN_NAME
          Well-known name for the ThemeResolver object in the bean factory for this namespace.
static java.lang.String THEME_SOURCE_ATTRIBUTE
          Request attribute to hold the current ThemeSource, retrievable by views.
private  ThemeResolver themeResolver
          ThemeResolver used by this servlet
private static UrlPathHelper urlPathHelper
           
static java.lang.String VIEW_RESOLVER_BEAN_NAME
          Well-known name for the ViewResolver object in the bean factory for this namespace.
private  RequestToViewNameTranslator viewNameTranslator
          RequestToViewNameTranslator used by this servlet
private  java.util.List<ViewResolver> viewResolvers
          List of ViewResolvers used by this servlet
static java.lang.String WEB_APPLICATION_CONTEXT_ATTRIBUTE
          Request attribute to hold the current web application context.
 
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
DispatcherServlet()
           
 
Method Summary
protected  LocaleContext buildLocaleContext(HttpServletRequest request)
          Build a LocaleContext for the given request, exposing the request's primary locale as current locale.
protected  HttpServletRequest checkMultipart(HttpServletRequest request)
          Convert the request into a multipart request, and make multipart resolver available.
protected  void cleanupMultipart(HttpServletRequest request)
          Clean up any resources used by the given multipart request (if any).
protected  java.lang.Object createDefaultStrategy(ApplicationContext context, java.lang.Class<?> clazz)
          Create a default strategy.
protected  void doDispatch(HttpServletRequest request, HttpServletResponse response)
          Process the actual dispatching to the handler.
protected  void doService(HttpServletRequest request, HttpServletResponse response)
          Exposes the DispatcherServlet-specific request attributes and delegates to doDispatch(HttpServletRequest, HttpServletResponse) for the actual dispatching.
protected
<T> java.util.List<T>
getDefaultStrategies(ApplicationContext context, java.lang.Class<T> strategyInterface)
          Create a List of default strategy objects for the given strategy interface.
protected
<T> T
getDefaultStrategy(ApplicationContext context, java.lang.Class<T> strategyInterface)
          Return the default strategy object for the given strategy interface.
protected  java.lang.String getDefaultViewName(HttpServletRequest request)
          Translate the supplied request into a default view name.
protected  HandlerExecutionChain getHandler(HttpServletRequest request)
          Return the HandlerExecutionChain for this request.
protected  HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache)
          Deprecated. as of Spring 3.0.4, in favor of #getHandler(javax.servlet.http.HttpServletRequest), with this method's cache attribute now effectively getting ignored
protected  HandlerAdapter getHandlerAdapter(java.lang.Object handler)
          Return the HandlerAdapter for this handler object.
 MultipartResolver getMultipartResolver()
          Obtain this servlet's MultipartResolver, if any.
 ThemeSource getThemeSource()
          Return this servlet's ThemeSource, if any; else return null.
private  void initHandlerAdapters(ApplicationContext context)
          Initialize the HandlerAdapters used by this class.
private  void initHandlerExceptionResolvers(ApplicationContext context)
          Initialize the HandlerExceptionResolver used by this class.
private  void initHandlerMappings(ApplicationContext context)
          Initialize the HandlerMappings used by this class.
private  void initLocaleResolver(ApplicationContext context)
          Initialize the LocaleResolver used by this class.
private  void initMultipartResolver(ApplicationContext context)
          Initialize the MultipartResolver used by this class.
private  void initRequestToViewNameTranslator(ApplicationContext context)
          Initialize the RequestToViewNameTranslator used by this servlet instance.
protected  void initStrategies(ApplicationContext context)
          Initialize the strategy objects that this servlet uses.
private  void initThemeResolver(ApplicationContext context)
          Initialize the ThemeResolver used by this class.
private  void initViewResolvers(ApplicationContext context)
          Initialize the ViewResolvers used by this class.
protected  void noHandlerFound(HttpServletRequest request, HttpServletResponse response)
          No handler found -> set appropriate HTTP response status.
protected  void onRefresh(ApplicationContext context)
          This implementation calls initStrategies(org.springframework.context.ApplicationContext).
protected  ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex)
          Determine an error ModelAndView via the registered HandlerExceptionResolvers.
protected  void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
          Render the given ModelAndView.
protected  View resolveViewName(java.lang.String viewName, java.util.Map<java.lang.String,java.lang.Object> model, java.util.Locale locale, HttpServletRequest request)
          Resolve the given view name into a View object (to be rendered).
private  void restoreAttributesAfterInclude(HttpServletRequest request, java.util.Map attributesSnapshot)
          Restore the request attributes after an include.
 void setCleanupAfterInclude(boolean cleanupAfterInclude)
          Set whether to perform cleanup of request attributes after an include request, that is, whether to reset the original state of all request attributes after the DispatcherServlet has processed within an include request.
 void setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters)
          Set whether to detect all HandlerAdapter beans in this servlet's context.
 void setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers)
          Set whether to detect all HandlerExceptionResolver beans in this servlet's context.
 void setDetectAllHandlerMappings(boolean detectAllHandlerMappings)
          Set whether to detect all HandlerMapping beans in this servlet's context.
 void setDetectAllViewResolvers(boolean detectAllViewResolvers)
          Set whether to detect all ViewResolver beans in this servlet's context.
private  void triggerAfterCompletion(HandlerExecutionChain mappedHandler, int interceptorIndex, HttpServletRequest request, HttpServletResponse response, java.lang.Exception ex)
          Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 
Methods inherited from class org.springframework.web.servlet.FrameworkServlet
createWebApplicationContext, createWebApplicationContext, destroy, doDelete, doGet, doOptions, doPost, doPut, doTrace, findWebApplicationContext, getContextAttribute, getContextClass, getContextConfigLocation, getContextId, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initFrameworkServlet, initServletBean, initWebApplicationContext, onApplicationEvent, postProcessWebApplicationContext, processRequest, refresh, setContextAttribute, setContextClass, setContextConfigLocation, setContextId, setDispatchOptionsRequest, setDispatchTraceRequest, setNamespace, setPublishContext, setPublishEvents, setThreadContextInheritable
 
Methods inherited from class org.springframework.web.servlet.HttpServletBean
addRequiredProperty, getServletContext, getServletName, init, initBeanWrapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTIPART_RESOLVER_BEAN_NAME

public static final java.lang.String MULTIPART_RESOLVER_BEAN_NAME
Well-known name for the MultipartResolver object in the bean factory for this namespace.

See Also:
Constant Field Values

LOCALE_RESOLVER_BEAN_NAME

public static final java.lang.String LOCALE_RESOLVER_BEAN_NAME
Well-known name for the LocaleResolver object in the bean factory for this namespace.

See Also:
Constant Field Values

THEME_RESOLVER_BEAN_NAME

public static final java.lang.String THEME_RESOLVER_BEAN_NAME
Well-known name for the ThemeResolver object in the bean factory for this namespace.

See Also:
Constant Field Values

HANDLER_MAPPING_BEAN_NAME

public static final java.lang.String HANDLER_MAPPING_BEAN_NAME
Well-known name for the HandlerMapping object in the bean factory for this namespace. Only used when "detectAllHandlerMappings" is turned off.

See Also:
setDetectAllHandlerMappings(boolean), Constant Field Values

HANDLER_ADAPTER_BEAN_NAME

public static final java.lang.String HANDLER_ADAPTER_BEAN_NAME
Well-known name for the HandlerAdapter object in the bean factory for this namespace. Only used when "detectAllHandlerAdapters" is turned off.

See Also:
setDetectAllHandlerAdapters(boolean), Constant Field Values

HANDLER_EXCEPTION_RESOLVER_BEAN_NAME

public static final java.lang.String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace. Only used when "detectAllHandlerExceptionResolvers" is turned off.

See Also:
setDetectAllHandlerExceptionResolvers(boolean), Constant Field Values

REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME

public static final java.lang.String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME
Well-known name for the RequestToViewNameTranslator object in the bean factory for this namespace.

See Also:
Constant Field Values

VIEW_RESOLVER_BEAN_NAME

public static final java.lang.String VIEW_RESOLVER_BEAN_NAME
Well-known name for the ViewResolver object in the bean factory for this namespace. Only used when "detectAllViewResolvers" is turned off.

See Also:
setDetectAllViewResolvers(boolean), Constant Field Values

WEB_APPLICATION_CONTEXT_ATTRIBUTE

public static final java.lang.String WEB_APPLICATION_CONTEXT_ATTRIBUTE
Request attribute to hold the current web application context. Otherwise only the global web app context is obtainable by tags etc.

See Also:
RequestContextUtils.getWebApplicationContext(ServletRequest)

LOCALE_RESOLVER_ATTRIBUTE

public static final java.lang.String LOCALE_RESOLVER_ATTRIBUTE
Request attribute to hold the current LocaleResolver, retrievable by views.

See Also:
RequestContextUtils.getLocaleResolver(HttpServletRequest)

THEME_RESOLVER_ATTRIBUTE

public static final java.lang.String THEME_RESOLVER_ATTRIBUTE
Request attribute to hold the current ThemeResolver, retrievable by views.

See Also:
RequestContextUtils.getThemeResolver(HttpServletRequest)

THEME_SOURCE_ATTRIBUTE

public static final java.lang.String THEME_SOURCE_ATTRIBUTE
Request attribute to hold the current ThemeSource, retrievable by views.

See Also:
RequestContextUtils.getThemeSource(HttpServletRequest)

PAGE_NOT_FOUND_LOG_CATEGORY

public static final java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.

See Also:
Constant Field Values

DEFAULT_STRATEGIES_PATH

private static final java.lang.String DEFAULT_STRATEGIES_PATH
Name of the class path resource (relative to the DispatcherServlet class) that defines DispatcherServlet's default strategy names.

See Also:
Constant Field Values

pageNotFoundLogger

protected static final Log pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.


urlPathHelper

private static final UrlPathHelper urlPathHelper

defaultStrategies

private static final java.util.Properties defaultStrategies

detectAllHandlerMappings

private boolean detectAllHandlerMappings
Detect all HandlerMappings or just expect "handlerMapping" bean?


detectAllHandlerAdapters

private boolean detectAllHandlerAdapters
Detect all HandlerAdapters or just expect "handlerAdapter" bean?


detectAllHandlerExceptionResolvers

private boolean detectAllHandlerExceptionResolvers
Detect all HandlerExceptionResolvers or just expect "handlerExceptionResolver" bean?


detectAllViewResolvers

private boolean detectAllViewResolvers
Detect all ViewResolvers or just expect "viewResolver" bean?


cleanupAfterInclude

private boolean cleanupAfterInclude
Perform cleanup of request attributes after include request?


multipartResolver

private MultipartResolver multipartResolver
MultipartResolver used by this servlet


localeResolver

private LocaleResolver localeResolver
LocaleResolver used by this servlet


themeResolver

private ThemeResolver themeResolver
ThemeResolver used by this servlet


handlerMappings

private java.util.List<HandlerMapping> handlerMappings
List of HandlerMappings used by this servlet


handlerAdapters

private java.util.List<HandlerAdapter> handlerAdapters
List of HandlerAdapters used by this servlet


handlerExceptionResolvers

private java.util.List<HandlerExceptionResolver> handlerExceptionResolvers
List of HandlerExceptionResolvers used by this servlet


viewNameTranslator

private RequestToViewNameTranslator viewNameTranslator
RequestToViewNameTranslator used by this servlet


viewResolvers

private java.util.List<ViewResolver> viewResolvers
List of ViewResolvers used by this servlet

Constructor Detail

DispatcherServlet

public DispatcherServlet()
Method Detail

setDetectAllHandlerMappings

public void setDetectAllHandlerMappings(boolean detectAllHandlerMappings)
Set whether to detect all HandlerMapping beans in this servlet's context. Otherwise, just a single bean with name "handlerMapping" will be expected.

Default is "true". Turn this off if you want this servlet to use a single HandlerMapping, despite multiple HandlerMapping beans being defined in the context.


setDetectAllHandlerAdapters

public void setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters)
Set whether to detect all HandlerAdapter beans in this servlet's context. Otherwise, just a single bean with name "handlerAdapter" will be expected.

Default is "true". Turn this off if you want this servlet to use a single HandlerAdapter, despite multiple HandlerAdapter beans being defined in the context.


setDetectAllHandlerExceptionResolvers

public void setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers)
Set whether to detect all HandlerExceptionResolver beans in this servlet's context. Otherwise, just a single bean with name "handlerExceptionResolver" will be expected.

Default is "true". Turn this off if you want this servlet to use a single HandlerExceptionResolver, despite multiple HandlerExceptionResolver beans being defined in the context.


setDetectAllViewResolvers

public void setDetectAllViewResolvers(boolean detectAllViewResolvers)
Set whether to detect all ViewResolver beans in this servlet's context. Otherwise, just a single bean with name "viewResolver" will be expected.

Default is "true". Turn this off if you want this servlet to use a single ViewResolver, despite multiple ViewResolver beans being defined in the context.


setCleanupAfterInclude

public void setCleanupAfterInclude(boolean cleanupAfterInclude)
Set whether to perform cleanup of request attributes after an include request, that is, whether to reset the original state of all request attributes after the DispatcherServlet has processed within an include request. Otherwise, just the DispatcherServlet's own request attributes will be reset, but not model attributes for JSPs or special attributes set by views (for example, JSTL's).

Default is "true", which is strongly recommended. Views should not rely on request attributes having been set by (dynamic) includes. This allows JSP views rendered by an included controller to use any model attributes, even with the same names as in the main JSP, without causing side effects. Only turn this off for special needs, for example to deliberately allow main JSPs to access attributes from JSP views rendered by an included controller.


onRefresh

protected void onRefresh(ApplicationContext context)
This implementation calls initStrategies(org.springframework.context.ApplicationContext).

Overrides:
onRefresh in class FrameworkServlet
Parameters:
context - the current WebApplicationContext
See Also:
FrameworkServlet.refresh()

initStrategies

protected void initStrategies(ApplicationContext context)
Initialize the strategy objects that this servlet uses.

May be overridden in subclasses in order to initialize further strategy objects.


initMultipartResolver

private void initMultipartResolver(ApplicationContext context)
Initialize the MultipartResolver used by this class.

If no bean is defined with the given name in the BeanFactory for this namespace, no multipart handling is provided.


initLocaleResolver

private void initLocaleResolver(ApplicationContext context)
Initialize the LocaleResolver used by this class.

If no bean is defined with the given name in the BeanFactory for this namespace, we default to AcceptHeaderLocaleResolver.


initThemeResolver

private void initThemeResolver(ApplicationContext context)
Initialize the ThemeResolver used by this class.

If no bean is defined with the given name in the BeanFactory for this namespace, we default to a FixedThemeResolver.


initHandlerMappings

private void initHandlerMappings(ApplicationContext context)
Initialize the HandlerMappings used by this class.

If no HandlerMapping beans are defined in the BeanFactory for this namespace, we default to BeanNameUrlHandlerMapping.


initHandlerAdapters

private void initHandlerAdapters(ApplicationContext context)
Initialize the HandlerAdapters used by this class.

If no HandlerAdapter beans are defined in the BeanFactory for this namespace, we default to SimpleControllerHandlerAdapter.


initHandlerExceptionResolvers

private void initHandlerExceptionResolvers(ApplicationContext context)
Initialize the HandlerExceptionResolver used by this class.

If no bean is defined with the given name in the BeanFactory for this namespace, we default to no exception resolver.


initRequestToViewNameTranslator

private void initRequestToViewNameTranslator(ApplicationContext context)
Initialize the RequestToViewNameTranslator used by this servlet instance.

If no implementation is configured then we default to DefaultRequestToViewNameTranslator.


initViewResolvers

private void initViewResolvers(ApplicationContext context)
Initialize the ViewResolvers used by this class.

If no ViewResolver beans are defined in the BeanFactory for this namespace, we default to InternalResourceViewResolver.


getThemeSource

public final ThemeSource getThemeSource()
Return this servlet's ThemeSource, if any; else return null.

Default is to return the WebApplicationContext as ThemeSource, provided that it implements the ThemeSource interface.

Returns:
the ThemeSource, if any
See Also:
FrameworkServlet.getWebApplicationContext()

getMultipartResolver

public final MultipartResolver getMultipartResolver()
Obtain this servlet's MultipartResolver, if any.

Returns:
the MultipartResolver used by this servlet, or null if none (indicating that no multipart support is available)

getDefaultStrategy

protected <T> T getDefaultStrategy(ApplicationContext context,
                                   java.lang.Class<T> strategyInterface)
Return the default strategy object for the given strategy interface.

The default implementation delegates to getDefaultStrategies(org.springframework.context.ApplicationContext, java.lang.Class), expecting a single object in the list.

Parameters:
context - the current WebApplicationContext
strategyInterface - the strategy interface
Returns:
the corresponding strategy object
See Also:
getDefaultStrategies(org.springframework.context.ApplicationContext, java.lang.Class)

getDefaultStrategies

protected <T> java.util.List<T> getDefaultStrategies(ApplicationContext context,
                                                     java.lang.Class<T> strategyInterface)
Create a List of default strategy objects for the given strategy interface.

The default implementation uses the "DispatcherServlet.properties" file (in the same package as the DispatcherServlet class) to determine the class names. It instantiates the strategy objects through the context's BeanFactory.

Parameters:
context - the current WebApplicationContext
strategyInterface - the strategy interface
Returns:
the List of corresponding strategy objects

createDefaultStrategy

protected java.lang.Object createDefaultStrategy(ApplicationContext context,
                                                 java.lang.Class<?> clazz)
Create a default strategy.

The default implementation uses AutowireCapableBeanFactory.createBean(java.lang.Class).

Parameters:
context - the current WebApplicationContext
clazz - the strategy implementation class to instantiate
Returns:
the fully configured strategy instance
See Also:
ApplicationContext.getAutowireCapableBeanFactory(), AutowireCapableBeanFactory.createBean(java.lang.Class)

doService

protected void doService(HttpServletRequest request,
                         HttpServletResponse response)
                  throws java.lang.Exception
Exposes the DispatcherServlet-specific request attributes and delegates to doDispatch(HttpServletRequest, HttpServletResponse) for the actual dispatching.

Specified by:
doService in class FrameworkServlet
Parameters:
request - current HTTP request
response - current HTTP response
Throws:
java.lang.Exception - in case of any kind of processing failure
See Also:
javax.servlet.http.HttpServlet#doGet, javax.servlet.http.HttpServlet#doPost

doDispatch

protected void doDispatch(HttpServletRequest request,
                          HttpServletResponse response)
                   throws java.lang.Exception
Process the actual dispatching to the handler.

The handler will be obtained by applying the servlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the servlet's installed HandlerAdapters to find the first that supports the handler class.

All HTTP methods are handled by this method. It's up to HandlerAdapters or handlers themselves to decide which methods are acceptable.

Parameters:
request - current HTTP request
response - current HTTP response
Throws:
java.lang.Exception - in case of any kind of processing failure

buildLocaleContext

protected LocaleContext buildLocaleContext(HttpServletRequest request)
Build a LocaleContext for the given request, exposing the request's primary locale as current locale.

The default implementation uses the dispatcher's LocaleResolver to obtain the current locale, which might change during a request.

Overrides:
buildLocaleContext in class FrameworkServlet
Parameters:
request - current HTTP request
Returns:
the corresponding LocaleContext

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.

Parameters:
request - current HTTP request
Returns:
the processed request (multipart wrapper if necessary)
Throws:
MultipartException
See Also:
MultipartResolver.resolveMultipart(HttpServletRequest)

cleanupMultipart

protected void cleanupMultipart(HttpServletRequest request)
Clean up any resources used by the given multipart request (if any).

Parameters:
request - current HTTP request
See Also:
MultipartResolver.cleanupMultipart(org.springframework.web.multipart.MultipartHttpServletRequest)

getHandler

@Deprecated
protected HandlerExecutionChain getHandler(HttpServletRequest request,
                                                      boolean cache)
                                    throws java.lang.Exception
Deprecated. as of Spring 3.0.4, in favor of #getHandler(javax.servlet.http.HttpServletRequest), with this method's cache attribute now effectively getting ignored

Return the HandlerExecutionChain for this request. Try all handler mappings in order.

Parameters:
request - current HTTP request
cache - whether to cache the HandlerExecutionChain in a request attribute
Returns:
the HandlerExecutionChain, or null if no handler could be found
Throws:
java.lang.Exception

getHandler

protected HandlerExecutionChain getHandler(HttpServletRequest request)
                                    throws java.lang.Exception
Return the HandlerExecutionChain for this request.

Tries all handler mappings in order.

Parameters:
request - current HTTP request
Returns:
the HandlerExecutionChain, or null if no handler could be found
Throws:
java.lang.Exception

noHandlerFound

protected void noHandlerFound(HttpServletRequest request,
                              HttpServletResponse response)
                       throws java.lang.Exception
No handler found -> set appropriate HTTP response status.

Parameters:
request - current HTTP request
response - current HTTP response
Throws:
java.lang.Exception - if preparing the response failed

getHandlerAdapter

protected HandlerAdapter getHandlerAdapter(java.lang.Object handler)
                                    throws ServletException
Return the HandlerAdapter for this handler object.

Parameters:
handler - the handler object to find an adapter for
Throws:
ServletException - if no HandlerAdapter can be found for the handler. This is a fatal error.

processHandlerException

protected ModelAndView processHandlerException(HttpServletRequest request,
                                               HttpServletResponse response,
                                               java.lang.Object handler,
                                               java.lang.Exception ex)
                                        throws java.lang.Exception
Determine an error ModelAndView via the registered HandlerExceptionResolvers.

Parameters:
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
ex - the exception that got thrown during handler execution
Returns:
a corresponding ModelAndView to forward to
Throws:
java.lang.Exception - if no error ModelAndView found

render

protected void render(ModelAndView mv,
                      HttpServletRequest request,
                      HttpServletResponse response)
               throws java.lang.Exception
Render the given ModelAndView.

This is the last stage in handling a request. It may involve resolving the view by name.

Parameters:
mv - the ModelAndView to render
request - current HTTP servlet request
response - current HTTP servlet response
Throws:
ServletException - if view is missing or cannot be resolved
java.lang.Exception - if there's a problem rendering the view

getDefaultViewName

protected java.lang.String getDefaultViewName(HttpServletRequest request)
                                       throws java.lang.Exception
Translate the supplied request into a default view name.

Parameters:
request - current HTTP servlet request
Returns:
the view name (or null if no default found)
Throws:
java.lang.Exception - if view name translation failed

resolveViewName

protected View resolveViewName(java.lang.String viewName,
                               java.util.Map<java.lang.String,java.lang.Object> model,
                               java.util.Locale locale,
                               HttpServletRequest request)
                        throws java.lang.Exception
Resolve the given view name into a View object (to be rendered).

The default implementations asks all ViewResolvers of this dispatcher. Can be overridden for custom resolution strategies, potentially based on specific model attributes or request parameters.

Parameters:
viewName - the name of the view to resolve
model - the model to be passed to the view
locale - the current locale
request - current HTTP servlet request
Returns:
the View object, or null if none found
Throws:
java.lang.Exception - if the view cannot be resolved (typically in case of problems creating an actual View object)
See Also:
ViewResolver.resolveViewName(java.lang.String, java.util.Locale)

triggerAfterCompletion

private void triggerAfterCompletion(HandlerExecutionChain mappedHandler,
                                    int interceptorIndex,
                                    HttpServletRequest request,
                                    HttpServletResponse response,
                                    java.lang.Exception ex)
                             throws java.lang.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:
java.lang.Exception
See Also:
HandlerInterceptor.afterCompletion(HttpServletRequest, HttpServletResponse, java.lang.Object, java.lang.Exception)

restoreAttributesAfterInclude

private void restoreAttributesAfterInclude(HttpServletRequest request,
                                           java.util.Map attributesSnapshot)
Restore the request attributes after an include.

Parameters:
request - current HTTP request
attributesSnapshot - the snapshot of the request attributes before the include