T
- The mapping for a HandlerMethod
containing the conditions
needed to match the handler method to incoming request.public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMapping implements InitializingBean
HandlerMapping
implementations that define
a mapping between a request and a HandlerMethod
.
For each registered handler method, a unique mapping is maintained with
subclasses defining the details of the mapping type <T>
.
Modifier and Type | Class and Description |
---|---|
private static class |
AbstractHandlerMethodMapping.MappingRegistration<T> |
(package private) class |
AbstractHandlerMethodMapping.MappingRegistry
A registry that maintains all mappings to handler methods, exposing methods
to perform lookups and providing concurrent access.
|
private class |
AbstractHandlerMethodMapping.Match
A thin wrapper around a matched HandlerMethod and its mapping, for the purpose of
comparing the best match with a comparator in the context of the current request.
|
private class |
AbstractHandlerMethodMapping.MatchComparator |
private static class |
AbstractHandlerMethodMapping.PreFlightAmbiguousMatchHandler |
Modifier and Type | Field and Description |
---|---|
private static CorsConfiguration |
ALLOW_CORS_CONFIG |
private AbstractHandlerMethodMapping.MappingRegistry |
mappingRegistry |
private static HandlerMethod |
PREFLIGHT_AMBIGUOUS_MATCH
HandlerMethod to return on a pre-flight request match when the request
mappings are more nuanced than the access control headers.
|
private static java.lang.String |
SCOPED_TARGET_NAME_PREFIX
Bean name prefix for target beans behind scoped proxies.
|
logger
BEST_MATCHING_HANDLER_ATTRIBUTE, 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 |
---|
AbstractHandlerMethodMapping() |
Modifier and Type | Method and Description |
---|---|
private void |
addMatchingMappings(java.util.Collection<T> mappings,
java.util.List<AbstractHandlerMethodMapping.Match> matches,
ServerWebExchange exchange) |
void |
afterPropertiesSet()
Detects handler methods at initialization.
|
protected HandlerMethod |
createHandlerMethod(java.lang.Object handler,
java.lang.reflect.Method method)
Create the HandlerMethod instance.
|
protected void |
detectHandlerMethods(java.lang.Object handler)
Look for handler methods in a handler.
|
protected CorsConfiguration |
getCorsConfiguration(java.lang.Object handler,
ServerWebExchange exchange)
Retrieve the CORS configuration for the given handler.
|
<any> |
getHandlerInternal(ServerWebExchange exchange)
Look up a handler method for the given request.
|
java.util.Map<T,HandlerMethod> |
getHandlerMethods()
Return a (read-only) map with all mappings and HandlerMethod's.
|
protected abstract java.util.Comparator<T> |
getMappingComparator(ServerWebExchange exchange)
Return a comparator for sorting matching mappings.
|
protected abstract T |
getMappingForMethod(java.lang.reflect.Method method,
java.lang.Class<?> handlerType)
Provide the mapping for a handler method.
|
(package private) AbstractHandlerMethodMapping.MappingRegistry |
getMappingRegistry()
Return the internal mapping registry.
|
protected abstract T |
getMatchingMapping(T mapping,
ServerWebExchange exchange)
Check if a mapping matches the current request and return a (potentially
new) mapping with conditions relevant to the current request.
|
protected void |
handleMatch(T mapping,
HandlerMethod handlerMethod,
ServerWebExchange exchange)
Invoked when a matching mapping is found.
|
protected HandlerMethod |
handleNoMatch(java.util.Set<T> mappings,
ServerWebExchange exchange)
Invoked when no matching mapping is not found.
|
protected void |
handlerMethodsInitialized(java.util.Map<T,HandlerMethod> handlerMethods)
Invoked after all handler methods have been detected.
|
protected CorsConfiguration |
initCorsConfiguration(java.lang.Object handler,
java.lang.reflect.Method method,
T mapping)
Extract and return the CORS configuration for the mapping.
|
protected void |
initHandlerMethods()
Scan beans in the ApplicationContext, detect and register handler methods.
|
protected abstract boolean |
isHandler(java.lang.Class<?> beanType)
Whether the given type is a handler with handler methods.
|
protected HandlerMethod |
lookupHandlerMethod(ServerWebExchange exchange)
Look up the best-matching handler method for the current request.
|
protected void |
registerHandlerMethod(java.lang.Object handler,
java.lang.reflect.Method method,
T mapping)
Register a handler method and its unique mapping.
|
void |
registerMapping(T mapping,
java.lang.Object handler,
java.lang.reflect.Method method)
Register the given mapping.
|
void |
unregisterMapping(T mapping)
Un-register the given mapping.
|
getCorsProcessor, getHandler, getOrder, getPathPatternParser, setCorsConfigurations, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatch
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
private static final java.lang.String SCOPED_TARGET_NAME_PREFIX
We're not checking the autowire-candidate status here, which is how the
proxy target filtering problem is being handled at the autowiring level,
since autowire-candidate may have been turned to false
for other
reasons, while still expecting the bean to be eligible for handler methods.
Originally defined in ScopedProxyUtils
but duplicated here to avoid a hard dependency on the spring-aop module.
private static final HandlerMethod PREFLIGHT_AMBIGUOUS_MATCH
private static final CorsConfiguration ALLOW_CORS_CONFIG
private final AbstractHandlerMethodMapping.MappingRegistry mappingRegistry
public java.util.Map<T,HandlerMethod> getHandlerMethods()
AbstractHandlerMethodMapping.MappingRegistry getMappingRegistry()
public void registerMapping(T mapping, java.lang.Object handler, java.lang.reflect.Method method)
This method may be invoked at runtime after initialization has completed.
mapping
- the mapping for the handler methodhandler
- the handlermethod
- the methodpublic void unregisterMapping(T mapping)
This method may be invoked at runtime after initialization has completed.
mapping
- the mapping to unregisterpublic void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected void initHandlerMethods()
protected void detectHandlerMethods(java.lang.Object handler)
handler
- the bean name of a handler or a handler instanceprotected void registerHandlerMethod(java.lang.Object handler, java.lang.reflect.Method method, T mapping)
handler
- the bean name of the handler or the handler instancemethod
- the method to registermapping
- the mapping conditions associated with the handler methodjava.lang.IllegalStateException
- if another method was already registered
under the same mappingprotected HandlerMethod createHandlerMethod(java.lang.Object handler, java.lang.reflect.Method method)
handler
- either a bean name or an actual handler instancemethod
- the target method@Nullable protected CorsConfiguration initCorsConfiguration(java.lang.Object handler, java.lang.reflect.Method method, T mapping)
protected void handlerMethodsInitialized(java.util.Map<T,HandlerMethod> handlerMethods)
handlerMethods
- a read-only map with handler methods and mappings.public <any> getHandlerInternal(ServerWebExchange exchange)
getHandlerInternal
in class AbstractHandlerMapping
exchange
- the current exchangeMono
for the matching handler, if any@Nullable protected HandlerMethod lookupHandlerMethod(ServerWebExchange exchange) throws java.lang.Exception
exchange
- the current exchangenull
if no matchjava.lang.Exception
handleMatch(T, org.springframework.web.method.HandlerMethod, org.springframework.web.server.ServerWebExchange)
,
handleNoMatch(java.util.Set<T>, org.springframework.web.server.ServerWebExchange)
private void addMatchingMappings(java.util.Collection<T> mappings, java.util.List<AbstractHandlerMethodMapping.Match> matches, ServerWebExchange exchange)
protected void handleMatch(T mapping, HandlerMethod handlerMethod, ServerWebExchange exchange)
mapping
- the matching mappinghandlerMethod
- the matching methodexchange
- the current exchange@Nullable protected HandlerMethod handleNoMatch(java.util.Set<T> mappings, ServerWebExchange exchange) throws java.lang.Exception
mappings
- all registered mappingsexchange
- the current exchangenull
java.lang.Exception
- provides details that can be translated into an error status codeprotected CorsConfiguration getCorsConfiguration(java.lang.Object handler, ServerWebExchange exchange)
AbstractHandlerMapping
getCorsConfiguration
in class AbstractHandlerMapping
handler
- the handler to check (never null
)exchange
- the current exchangenull
if noneprotected abstract boolean isHandler(java.lang.Class<?> beanType)
beanType
- the type of the bean being checked@Nullable protected abstract T getMappingForMethod(java.lang.reflect.Method method, java.lang.Class<?> handlerType)
method
- the method to provide a mapping forhandlerType
- the handler type, possibly a sub-type of the method's
declaring classnull
if the method is not mapped@Nullable protected abstract T getMatchingMapping(T mapping, ServerWebExchange exchange)
mapping
- the mapping to get a match forexchange
- the current exchangenull
if the mapping doesn't matchprotected abstract java.util.Comparator<T> getMappingComparator(ServerWebExchange exchange)
exchange
- the current exchangenull
)