public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping
HandlerMapping
implementations. Provides infrastructure for mapping handlers to URLs and configurable
URL lookup. For information on the latter, see "alwaysUseFullPath" property.
Supports direct matches, e.g. a registered "/test" matches "/test", and
various Ant-style pattern matches, e.g. a registered "/t*" pattern matches
both "/test" and "/team", "/test/*" matches all paths in the "/test" directory,
"/test/**" matches all paths below "/test". For details, see the
AntPathMatcher
javadoc.
Will search all path patterns to find the most exact match for the current request path. The most exact match is defined as the longest path pattern that matches the current request path.
logger
BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
AbstractUrlHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
buildPathExposingHandler(java.lang.Object rawHandler,
java.lang.String bestMatchingPattern,
java.lang.String pathWithinMapping,
java.util.Map<java.lang.String,java.lang.String> uriTemplateVariables)
Build a handler object for the given raw handler, exposing the actual
handler, the
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE , as well as
the HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE before executing the handler. |
protected void |
exposePathWithinMapping(java.lang.String bestMatchingPattern,
java.lang.String pathWithinMapping,
HttpServletRequest request)
Expose the path within the current mapping as request attribute.
|
protected void |
exposeUriTemplateVariables(java.util.Map<java.lang.String,java.lang.String> uriTemplateVariables,
HttpServletRequest request)
Expose the URI templates variables as request attribute.
|
protected java.lang.Object |
getHandlerInternal(HttpServletRequest request)
Look up a handler for the URL path of the given request.
|
java.util.Map<java.lang.String,java.lang.Object> |
getHandlerMap()
Return the registered handlers as an unmodifiable Map, with the registered path
as key and the handler object (or handler bean name in case of a lazy-init handler)
as value.
|
java.lang.Object |
getRootHandler()
Return the root handler for this handler mapping (registered for "/"),
or
null if none. |
protected java.lang.Object |
lookupHandler(java.lang.String urlPath,
HttpServletRequest request)
Look up a handler instance for the given URL path.
|
RequestMatchResult |
match(HttpServletRequest request,
java.lang.String pattern)
Determine whether the given request matches the request criteria.
|
protected void |
registerHandler(java.lang.String[] urlPaths,
java.lang.String beanName)
Register the specified handler for the given URL paths.
|
protected void |
registerHandler(java.lang.String urlPath,
java.lang.Object handler)
Register the specified handler for the given URL path.
|
void |
setLazyInitHandlers(boolean lazyInitHandlers)
Set whether to lazily initialize handlers.
|
void |
setRootHandler(java.lang.Object rootHandler)
Set the root handler for this handler mapping, that is,
the handler to be registered for the root path ("/").
|
void |
setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.
|
protected boolean |
supportsTypeLevelMappings()
Indicates whether this handler mapping support type-level mappings.
|
boolean |
useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
|
protected void |
validateHandler(java.lang.Object handler,
HttpServletRequest request)
Validate the given handler against the current request.
|
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getCorsConfiguration, getCorsConfigurations, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initApplicationContext, initInterceptors, setAlwaysUseFullPath, setCorsConfigurations, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHandler
public void setRootHandler(java.lang.Object rootHandler)
Default is null
, indicating no root handler.
public java.lang.Object getRootHandler()
null
if none.public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
The default value is false
.
public boolean useTrailingSlashMatch()
public void setLazyInitHandlers(boolean lazyInitHandlers)
If you want to allow your controllers to be lazily initialized, make them "lazy-init" and set this flag to true. Just making them "lazy-init" will not work, as they are initialized through the references from the handler mapping in this case.
protected java.lang.Object getHandlerInternal(HttpServletRequest request) throws java.lang.Exception
getHandlerInternal
in class AbstractHandlerMapping
request
- current HTTP requestnull
if none foundjava.lang.Exception
- if there is an internal errorprotected java.lang.Object lookupHandler(java.lang.String urlPath, HttpServletRequest request) throws java.lang.Exception
Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
Looks for the most exact pattern, where most exact is defined as the longest path pattern.
urlPath
- URL the bean is mapped torequest
- current HTTP request (to expose the path within the mapping to)null
if not foundjava.lang.Exception
exposePathWithinMapping(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
,
AntPathMatcher
protected void validateHandler(java.lang.Object handler, HttpServletRequest request) throws java.lang.Exception
The default implementation is empty. Can be overridden in subclasses, for example to enforce specific preconditions expressed in URL mappings.
handler
- the handler object to validaterequest
- current HTTP requestjava.lang.Exception
- if validation failedprotected java.lang.Object buildPathExposingHandler(java.lang.Object rawHandler, java.lang.String bestMatchingPattern, java.lang.String pathWithinMapping, java.util.Map<java.lang.String,java.lang.String> uriTemplateVariables)
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
, as well as
the HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE
before executing the handler.
The default implementation builds a HandlerExecutionChain
with a special interceptor that exposes the path attribute and uri template variables
rawHandler
- the raw handler to exposepathWithinMapping
- the path to expose before executing the handleruriTemplateVariables
- the URI template variables, can be null
if no variables foundprotected void exposePathWithinMapping(java.lang.String bestMatchingPattern, java.lang.String pathWithinMapping, HttpServletRequest request)
pathWithinMapping
- the path within the current mappingrequest
- the request to expose the path toHandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
protected void exposeUriTemplateVariables(java.util.Map<java.lang.String,java.lang.String> uriTemplateVariables, HttpServletRequest request)
uriTemplateVariables
- the URI template variablesrequest
- the request to expose the path toHandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
public RequestMatchResult match(HttpServletRequest request, java.lang.String pattern)
MatchableHandlerMapping
match
in interface MatchableHandlerMapping
request
- the current requestpattern
- the pattern to matchnull
if noneprotected void registerHandler(java.lang.String[] urlPaths, java.lang.String beanName) throws BeansException, java.lang.IllegalStateException
urlPaths
- the URLs that the bean should be mapped tobeanName
- the name of the handler beanBeansException
- if the handler couldn't be registeredjava.lang.IllegalStateException
- if there is a conflicting handler registeredprotected void registerHandler(java.lang.String urlPath, java.lang.Object handler) throws BeansException, java.lang.IllegalStateException
urlPath
- the URL the bean should be mapped tohandler
- the handler instance or handler bean name String
(a bean name will automatically be resolved into the corresponding handler bean)BeansException
- if the handler couldn't be registeredjava.lang.IllegalStateException
- if there is a conflicting handler registeredpublic final java.util.Map<java.lang.String,java.lang.Object> getHandlerMap()
protected boolean supportsTypeLevelMappings()
false
.