RequestMappingHandlerAdapter
@Deprecated public class AnnotationMethodHandlerAdapter extends WebContentGenerator implements HandlerAdapter, Ordered, BeanFactoryAware
HandlerAdapter
interface
that maps handler methods based on HTTP paths, HTTP methods and request parameters
expressed through the RequestMapping
annotation.
Supports request parameter binding through the RequestParam
annotation.
Also supports the ModelAttribute
annotation for exposing model attribute
values to the view, as well as InitBinder
for binder initialization methods
and SessionAttributes
for automatic session management of specific attributes.
This adapter can be customized through various bean properties.
A common use case is to apply shared binder initialization logic through
a custom WebBindingInitializer
.
setPathMatcher(org.springframework.util.PathMatcher)
,
setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver)
,
setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer)
,
setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore)
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AnnotationMethodHandlerAdapter.RequestMappingInfo
Deprecated.
Holder for request mapping metadata.
|
(package private) static class |
AnnotationMethodHandlerAdapter.RequestSpecificMappingInfo
Deprecated.
Subclass of
AnnotationMethodHandlerAdapter.RequestMappingInfo that holds request-specific data. |
(package private) static class |
AnnotationMethodHandlerAdapter.RequestSpecificMappingInfoComparator
Deprecated.
Comparator capable of sorting
AnnotationMethodHandlerAdapter.RequestSpecificMappingInfo s (RHIs) so that
sorting a list with this comparator will result in:
RHIs with better matched paths
take prescedence over those with a weaker match (as expressed by the path pattern comparator.) Typically, this means that patterns without wild cards and uri templates
will be ordered before those without.
RHIs with one single request method will be
ordered before those without a method, or with more than one method.
RHIs with more request parameters will be ordered
before those with less parameters
|
private class |
AnnotationMethodHandlerAdapter.ServletHandlerMethodInvoker
Deprecated.
Servlet-specific subclass of
HandlerMethodInvoker . |
private class |
AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver
Deprecated.
Servlet-specific subclass of
HandlerMethodResolver . |
Modifier and Type | Field and Description |
---|---|
private ConfigurableBeanFactory |
beanFactory
Deprecated.
|
private int |
cacheSecondsForSessionAttributeHandlers
Deprecated.
|
private WebArgumentResolver[] |
customArgumentResolvers
Deprecated.
|
private ModelAndViewResolver[] |
customModelAndViewResolvers
Deprecated.
|
private BeanExpressionContext |
expressionContext
Deprecated.
|
private HttpMessageConverter<?>[] |
messageConverters
Deprecated.
|
private MethodNameResolver |
methodNameResolver
Deprecated.
|
private java.util.Map<java.lang.Class<?>,AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver> |
methodResolverCache
Deprecated.
|
private int |
order
Deprecated.
|
static java.lang.String |
PAGE_NOT_FOUND_LOG_CATEGORY
Deprecated.
Log category to use when no mapped handler is found for a request.
|
protected static Log |
pageNotFoundLogger
Deprecated.
Additional logger to use when no mapped handler is found for a request.
|
private ParameterNameDiscoverer |
parameterNameDiscoverer
Deprecated.
|
private PathMatcher |
pathMatcher
Deprecated.
|
private java.util.Map<java.lang.Class<?>,java.lang.Boolean> |
sessionAnnotatedClassesCache
Deprecated.
|
private SessionAttributeStore |
sessionAttributeStore
Deprecated.
|
private boolean |
synchronizeOnSession
Deprecated.
|
private UrlPathHelper |
urlPathHelper
Deprecated.
|
private WebBindingInitializer |
webBindingInitializer
Deprecated.
|
METHOD_GET, METHOD_HEAD, METHOD_POST
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
AnnotationMethodHandlerAdapter()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected ServletRequestDataBinder |
createBinder(HttpServletRequest request,
java.lang.Object target,
java.lang.String objectName)
Deprecated.
Template method for creating a new ServletRequestDataBinder instance.
|
protected HttpInputMessage |
createHttpInputMessage(HttpServletRequest servletRequest)
Deprecated.
Template method for creating a new HttpInputMessage instance.
|
protected HttpOutputMessage |
createHttpOutputMessage(HttpServletResponse servletResponse)
Deprecated.
Template method for creating a new HttpOuputMessage instance.
|
long |
getLastModified(HttpServletRequest request,
java.lang.Object handler)
Deprecated.
This method always returns -1 since an annotated controller can have many methods,
each requiring separate lastModified calculations.
|
HttpMessageConverter<?>[] |
getMessageConverters()
Deprecated.
Return the message body converters that this adapter has been configured with.
|
private AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver |
getMethodResolver(java.lang.Object handler)
Deprecated.
Build a HandlerMethodResolver for the given handler type.
|
int |
getOrder()
Deprecated.
Return the order value of this object, with a
higher value meaning greater in terms of sorting.
|
ModelAndView |
handle(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler)
Deprecated.
Use the given handler to handle this request.
|
protected ModelAndView |
invokeHandlerMethod(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler)
Deprecated.
|
void |
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Deprecated.
Set if URL lookup should always use the full path within the current servlet
context.
|
void |
setBeanFactory(BeanFactory beanFactory)
Deprecated.
Callback that supplies the owning factory to a bean instance.
|
void |
setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
Deprecated.
Cache content produced by
@SessionAttributes annotated handlers
for the given number of seconds. |
void |
setCustomArgumentResolver(WebArgumentResolver argumentResolver)
Deprecated.
Set a custom WebArgumentResolvers to use for special method parameter types.
|
void |
setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers)
Deprecated.
Set one or more custom WebArgumentResolvers to use for special method parameter types.
|
void |
setCustomModelAndViewResolver(ModelAndViewResolver customModelAndViewResolver)
Deprecated.
Set a custom ModelAndViewResolvers to use for special method return types.
|
void |
setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers)
Deprecated.
Set one or more custom ModelAndViewResolvers to use for special method return types.
|
void |
setMessageConverters(HttpMessageConverter<?>[] messageConverters)
Deprecated.
Set the message body converters to use.
|
void |
setMethodNameResolver(MethodNameResolver methodNameResolver)
Deprecated.
Set the MethodNameResolver to use for resolving default handler methods
(carrying an empty
@RequestMapping annotation). |
void |
setOrder(int order)
Deprecated.
Specify the order value for this HandlerAdapter bean.
|
void |
setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Deprecated.
Set the ParameterNameDiscoverer to use for resolving method parameter names if needed
(e.g.
|
void |
setPathMatcher(PathMatcher pathMatcher)
Deprecated.
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.
|
void |
setSessionAttributeStore(SessionAttributeStore sessionAttributeStore)
Deprecated.
Specify the strategy to store session attributes with.
|
void |
setSynchronizeOnSession(boolean synchronizeOnSession)
Deprecated.
Set if controller execution should be synchronized on the session,
to serialize parallel invocations from the same client.
|
void |
setUrlDecode(boolean urlDecode)
Deprecated.
Set if context path and request URI should be URL-decoded.
|
void |
setUrlPathHelper(UrlPathHelper urlPathHelper)
Deprecated.
Set the UrlPathHelper to use for resolution of lookup paths.
|
void |
setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
Deprecated.
Specify a WebBindingInitializer which will apply pre-configured
configuration to every DataBinder that this controller uses.
|
boolean |
supports(java.lang.Object handler)
Deprecated.
Given a handler instance, return whether or not this HandlerAdapter can
support it.
|
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setAlwaysMustRevalidate, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
public static final java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
pageNotFoundLogger
,
Constant Field Valuesprotected static final Log pageNotFoundLogger
PAGE_NOT_FOUND_LOG_CATEGORY
private UrlPathHelper urlPathHelper
private PathMatcher pathMatcher
private MethodNameResolver methodNameResolver
private WebBindingInitializer webBindingInitializer
private SessionAttributeStore sessionAttributeStore
private int cacheSecondsForSessionAttributeHandlers
private boolean synchronizeOnSession
private ParameterNameDiscoverer parameterNameDiscoverer
private WebArgumentResolver[] customArgumentResolvers
private ModelAndViewResolver[] customModelAndViewResolvers
private HttpMessageConverter<?>[] messageConverters
private int order
private ConfigurableBeanFactory beanFactory
private BeanExpressionContext expressionContext
private final java.util.Map<java.lang.Class<?>,AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver> methodResolverCache
private final java.util.Map<java.lang.Class<?>,java.lang.Boolean> sessionAnnotatedClassesCache
public AnnotationMethodHandlerAdapter()
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Default is "false".
public void setUrlDecode(boolean urlDecode)
Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
UrlPathHelper.setUrlDecode(boolean)
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and HandlerAdapters.
public void setPathMatcher(PathMatcher pathMatcher)
Default is AntPathMatcher
.
public void setMethodNameResolver(MethodNameResolver methodNameResolver)
@RequestMapping
annotation).
Will only kick in when the handler method cannot be resolved uniquely through the annotation metadata already.
public void setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
public void setSessionAttributeStore(SessionAttributeStore sessionAttributeStore)
Default is DefaultSessionAttributeStore
,
storing session attributes in the HttpSession, using the same attribute name as in the model.
public void setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
@SessionAttributes
annotated handlers
for the given number of seconds. Default is 0, preventing caching completely.
In contrast to the "cacheSeconds" property which will apply to all general handlers
(but not to @SessionAttributes
annotated handlers), this setting will
apply to @SessionAttributes
annotated handlers only.
public void setSynchronizeOnSession(boolean synchronizeOnSession)
More specifically, the execution of the handleRequestInternal
method will get synchronized if this flag is "true". The best available
session mutex will be used for the synchronization; ideally, this will
be a mutex exposed by HttpSessionMutexListener.
The session mutex is guaranteed to be the same object during
the entire lifetime of the session, available under the key defined
by the SESSION_MUTEX_ATTRIBUTE
constant. It serves as a
safe reference to synchronize on for locking on the current session.
In many cases, the HttpSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.
HttpSessionMutexListener
,
org.springframework.web.util.WebUtils#getSessionMutex(javax.servlet.http.HttpSession)
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Default is a LocalVariableTableParameterNameDiscoverer
.
public void setCustomArgumentResolver(WebArgumentResolver argumentResolver)
Such a custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.
public void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers)
Any such custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.
public void setCustomModelAndViewResolver(ModelAndViewResolver customModelAndViewResolver)
Such a custom ModelAndViewResolver will kick in first, having a chance to resolve a return value before the standard ModelAndView handling kicks in.
public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers)
Any such custom ModelAndViewResolver will kick in first, having a chance to resolve a return value before the standard ModelAndView handling kicks in.
public void setMessageConverters(HttpMessageConverter<?>[] messageConverters)
These converters are used to convert from and to HTTP requests and responses.
public HttpMessageConverter<?>[] getMessageConverters()
public void setOrder(int order)
Default value is Integer.MAX_VALUE
, meaning that it's non-ordered.
Ordered.getOrder()
public int getOrder()
Ordered
Normally starting with 0, with Integer.MAX_VALUE
indicating the greatest value. Same order values will result
in arbitrary positions for the affected objects.
Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).
public void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public boolean supports(java.lang.Object handler)
HandlerAdapter
A typical implementation:
return (handler instanceof MyHandler);
supports
in interface HandlerAdapter
handler
- handler object to checkpublic ModelAndView handle(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler) throws java.lang.Exception
HandlerAdapter
handle
in interface HandlerAdapter
request
- current HTTP requestresponse
- current HTTP responsehandler
- handler to use. This object must have previously been passed
to the supports
method of this interface, which must have
returned true
.null
if the request has been handled directlyjava.lang.Exception
- in case of errorsprotected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler) throws java.lang.Exception
java.lang.Exception
public long getLastModified(HttpServletRequest request, java.lang.Object handler)
RequestMapping
-annotated method can calculate the lastModified value, call
WebRequest.checkNotModified(long)
to check it, and return null
if that returns true
.getLastModified
in interface HandlerAdapter
request
- current HTTP requesthandler
- handler to useWebRequest.checkNotModified(long)
private AnnotationMethodHandlerAdapter.ServletHandlerMethodResolver getMethodResolver(java.lang.Object handler)
protected ServletRequestDataBinder createBinder(HttpServletRequest request, java.lang.Object target, java.lang.String objectName) throws java.lang.Exception
The default implementation creates a standard ServletRequestDataBinder. This can be overridden for custom ServletRequestDataBinder subclasses.
request
- current HTTP requesttarget
- the target object to bind onto (or null
if the binder is just used to convert a plain parameter value)objectName
- the objectName of the target objectjava.lang.Exception
- in case of invalid state or argumentsServletRequestDataBinder#bind(javax.servlet.ServletRequest)
,
DataBinder.convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)
protected HttpInputMessage createHttpInputMessage(HttpServletRequest servletRequest) throws java.lang.Exception
The default implementation creates a standard ServletServerHttpRequest
.
This can be overridden for custom HttpInputMessage
implementations
servletRequest
- current HTTP requestjava.lang.Exception
- in case of errorsprotected HttpOutputMessage createHttpOutputMessage(HttpServletResponse servletResponse) throws java.lang.Exception
The default implementation creates a standard ServletServerHttpResponse
.
This can be overridden for custom HttpOutputMessage
implementations
servletResponse
- current HTTP responsejava.lang.Exception
- in case of errors