public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping
HandlerMapping
implementations.
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 under "/test",
"/test/**" matches all paths below "/test". For details, see the
ParsingPathMatcher
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.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
handlerMap |
private boolean |
lazyInitHandlers |
private boolean |
useTrailingSlashMatch |
logger
BEST_MATCHING_PATTERN_ATTRIBUTE, 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 |
---|---|
private java.lang.String |
getHandlerDescription(java.lang.Object handler) |
<any> |
getHandlerInternal(ServerWebExchange exchange)
Look up a handler for the given request, returning an empty
Mono
if no specific one is found. |
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.
|
private java.lang.Object |
handleMatch(java.lang.Object handler,
java.lang.String bestMatch,
java.lang.String pathWithinMapping,
ServerWebExchange exchange) |
protected java.lang.Object |
lookupHandler(java.lang.String urlPath,
ServerWebExchange exchange)
Look up a handler instance for the given URL path.
|
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 |
setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.
|
boolean |
useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
|
protected void |
validateHandler(java.lang.Object handler,
ServerWebExchange exchange)
Validate the given handler against the current request.
|
getCorsConfiguration, getCorsConfigurations, getCorsProcessor, getHandler, getOrder, getPathHelper, getPathMatcher, setCorsConfigurations, setCorsProcessor, setOrder, setPathHelper, setPathMatcher, setUrlDecode
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext
private boolean useTrailingSlashMatch
private boolean lazyInitHandlers
private final java.util.Map<java.lang.String,java.lang.Object> handlerMap
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.
public final java.util.Map<java.lang.String,java.lang.Object> getHandlerMap()
public <any> getHandlerInternal(ServerWebExchange exchange)
AbstractHandlerMapping
Mono
if no specific one is found. This method is called by AbstractHandlerMapping.getHandler(org.springframework.web.server.ServerWebExchange)
.
On CORS pre-flight requests this method should return a match not for
the pre-flight request but for the expected actual request based on the URL
path, the HTTP methods from the "Access-Control-Request-Method" header, and
the headers from the "Access-Control-Request-Headers" header thus allowing
the CORS configuration to be obtained via AbstractHandlerMapping.getCorsConfigurations()
,
getHandlerInternal
in class AbstractHandlerMapping
exchange
- current exchangeMono
for the matching handler, if anyprotected java.lang.Object lookupHandler(java.lang.String urlPath, ServerWebExchange exchange) 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 toexchange
- the current exchangenull
if not foundjava.lang.Exception
ParsingPathMatcher
private java.lang.Object handleMatch(java.lang.Object handler, java.lang.String bestMatch, java.lang.String pathWithinMapping, ServerWebExchange exchange) throws java.lang.Exception
java.lang.Exception
protected void validateHandler(java.lang.Object handler, ServerWebExchange exchange) 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 validateexchange
- current exchangejava.lang.Exception
- if validation failedprotected 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 registeredprivate java.lang.String getHandlerDescription(java.lang.Object handler)