final class TestDispatcherServlet extends DispatcherServlet
DispatcherServlet
that saves the result in an
MvcResult
. The MvcResult
instance is expected to be available
as the request attribute MockMvc.MVC_RESULT_ATTRIBUTE
.Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
KEY |
EXCEPTION_ATTRIBUTE, FLASH_MAP_MANAGER_ATTRIBUTE, FLASH_MAP_MANAGER_BEAN_NAME, HANDLER_ADAPTER_BEAN_NAME, HANDLER_EXCEPTION_RESOLVER_BEAN_NAME, HANDLER_MAPPING_BEAN_NAME, INPUT_FLASH_MAP_ATTRIBUTE, LOCALE_RESOLVER_ATTRIBUTE, LOCALE_RESOLVER_BEAN_NAME, MULTIPART_RESOLVER_BEAN_NAME, OUTPUT_FLASH_MAP_ATTRIBUTE, 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
DEFAULT_CONTEXT_CLASS, DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
logger
Constructor and Description |
---|
TestDispatcherServlet(WebApplicationContext webApplicationContext)
Create a new instance with the given web application context.
|
Modifier and Type | Method and Description |
---|---|
protected HandlerExecutionChain |
getHandler(HttpServletRequest request)
Return the HandlerExecutionChain for this request.
|
protected DefaultMvcResult |
getMvcResult(ServletRequest request) |
protected ModelAndView |
processHandlerException(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
java.lang.Exception ex)
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
|
private void |
registerAsyncResultInterceptors(HttpServletRequest request) |
protected void |
render(ModelAndView mv,
HttpServletRequest request,
HttpServletResponse response)
Render the given ModelAndView.
|
protected void |
service(HttpServletRequest request,
HttpServletResponse response)
Override the parent class implementation in order to intercept PATCH requests.
|
buildLocaleContext, checkMultipart, cleanupMultipart, createDefaultStrategy, doDispatch, doService, getDefaultStrategies, getDefaultStrategy, getDefaultViewName, getHandlerAdapter, getMultipartResolver, getThemeSource, initStrategies, noHandlerFound, onRefresh, resolveViewName, setCleanupAfterInclude, setDetectAllHandlerAdapters, setDetectAllHandlerExceptionResolvers, setDetectAllHandlerMappings, setDetectAllViewResolvers, setThrowExceptionIfNoHandlerFound
applyInitializers, buildRequestAttributes, configureAndRefreshWebApplicationContext, 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, setApplicationContext, setContextAttribute, setContextClass, setContextConfigLocation, setContextId, setContextInitializerClasses, setContextInitializers, setDispatchOptionsRequest, setDispatchTraceRequest, setNamespace, setPublishContext, setPublishEvents, setThreadContextInheritable
addRequiredProperty, createEnvironment, getEnvironment, getServletContext, getServletName, init, initBeanWrapper, setEnvironment
public TestDispatcherServlet(WebApplicationContext webApplicationContext)
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
FrameworkServlet
service
in class FrameworkServlet
ServletException
java.io.IOException
private void registerAsyncResultInterceptors(HttpServletRequest request)
protected DefaultMvcResult getMvcResult(ServletRequest request)
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws java.lang.Exception
DispatcherServlet
Tries all handler mappings in order.
getHandler
in class DispatcherServlet
request
- current HTTP requestnull
if no handler could be foundjava.lang.Exception
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
DispatcherServlet
This is the last stage in handling a request. It may involve resolving the view by name.
render
in class DispatcherServlet
mv
- the ModelAndView to renderrequest
- current HTTP servlet requestresponse
- current HTTP servlet responsejava.lang.Exception
- if there's a problem rendering the viewprotected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex) throws java.lang.Exception
DispatcherServlet
processHandlerException
in class DispatcherServlet
request
- current HTTP requestresponse
- current HTTP responsehandler
- 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 executionjava.lang.Exception
- if no error ModelAndView found