Class AbstractHandlerMethodMapping<T>
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.reactive.handler.AbstractHandlerMapping
org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping<T>
- Type Parameters:
T- the mapping for aHandlerMethodcontaining the conditions needed to match the handler method to an incoming request.
- All Implemented Interfaces:
Aware,BeanNameAware,InitializingBean,ApplicationContextAware,Ordered,HandlerMapping
- Direct Known Subclasses:
RequestMappingInfoHandlerMapping
public abstract class AbstractHandlerMethodMapping<T>
extends AbstractHandlerMapping
implements InitializingBean
Abstract base class for
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>.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Brian Clozel, Sam Brannen
-
Field Summary
Fields inherited from class org.springframework.web.reactive.handler.AbstractHandlerMapping
mappingsLoggerFields inherited from class org.springframework.context.support.ApplicationObjectSupport
loggerFields inherited from interface org.springframework.web.reactive.HandlerMapping
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDetects handler methods at initialization.protected HandlerMethodcreateHandlerMethod(Object handler, Method method) Create the HandlerMethod instance.protected voiddetectHandlerMethods(Object handler) Look for handler methods in a handler.protected CorsConfigurationgetCorsConfiguration(Object handler, ServerWebExchange exchange) Retrieve the CORS configuration for the given handler.getDirectPaths(T mapping) Return the request mapping paths that are not patterns.reactor.core.publisher.Mono<HandlerMethod>getHandlerInternal(ServerWebExchange exchange) Look up a handler method for the given request.Return a (read-only) map with all mappings and HandlerMethod's.protected abstract Comparator<T>getMappingComparator(ServerWebExchange exchange) Return a comparator for sorting matching mappings.protected abstract TgetMappingForMethod(Method method, Class<?> handlerType) Provide the mapping for a handler method.protected abstract TgetMatchingMapping(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 voidhandleMatch(T mapping, HandlerMethod handlerMethod, ServerWebExchange exchange) Invoked when a matching mapping is found.protected HandlerMethodhandleNoMatch(Set<T> mappings, ServerWebExchange exchange) Invoked when no matching mapping is not found.protected voidhandlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods) Invoked after all handler methods have been detected.protected booleanhasCorsConfigurationSource(Object handler) Returntrueif there is aCorsConfigurationSourcefor this handler.protected CorsConfigurationinitCorsConfiguration(Object handler, Method method, T mapping) Extract and return the CORS configuration for the mapping.protected voidScan beans in the ApplicationContext, detect and register handler methods.protected abstract booleanWhether the given type is a handler with handler methods.protected HandlerMethodlookupHandlerMethod(ServerWebExchange exchange) Look up the best-matching handler method for the current request.protected voidregisterHandlerMethod(Object handler, Method method, T mapping) Register a handler method and its unique mapping.voidregisterMapping(T mapping, Object handler, Method method) Register the given mapping.voidunregisterMapping(T mapping) Un-register the given mapping.Methods inherited from class org.springframework.web.reactive.handler.AbstractHandlerMapping
formatMappingName, getCorsProcessor, getHandler, getOrder, getPathPatternParser, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatchMethods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Constructor Details
-
AbstractHandlerMethodMapping
public AbstractHandlerMethodMapping()
-
-
Method Details
-
getHandlerMethods
Return a (read-only) map with all mappings and HandlerMethod's. -
registerMapping
Register the given mapping.This method may be invoked at runtime after initialization has completed.
- Parameters:
mapping- the mapping for the handler methodhandler- the handlermethod- the method
-
unregisterMapping
Un-register the given mapping.This method may be invoked at runtime after initialization has completed.
- Parameters:
mapping- the mapping to unregister
-
afterPropertiesSet
public void afterPropertiesSet()Detects handler methods at initialization.- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
initHandlerMethods
protected void initHandlerMethods()Scan beans in the ApplicationContext, detect and register handler methods. -
detectHandlerMethods
Look for handler methods in a handler.- Parameters:
handler- the bean name of a handler or a handler instance
-
registerHandlerMethod
Register a handler method and its unique mapping. Invoked at startup for each detected handler method.- Parameters:
handler- the bean name of the handler or the handler instancemethod- the method to registermapping- the mapping conditions associated with the handler method- Throws:
IllegalStateException- if another method was already registered under the same mapping
-
createHandlerMethod
Create the HandlerMethod instance.- Parameters:
handler- either a bean name or an actual handler instancemethod- the target method- Returns:
- the created HandlerMethod
-
initCorsConfiguration
@Nullable protected CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) Extract and return the CORS configuration for the mapping. -
handlerMethodsInitialized
Invoked after all handler methods have been detected.- Parameters:
handlerMethods- a read-only map with handler methods and mappings.
-
getHandlerInternal
Look up a handler method for the given request.- Specified by:
getHandlerInternalin classAbstractHandlerMapping- Parameters:
exchange- the current exchange- Returns:
Monofor the matching handler, if any
-
lookupHandlerMethod
Look up the best-matching handler method for the current request. If multiple matches are found, the best match is selected.- Parameters:
exchange- the current exchange- Returns:
- the best-matching handler method, or
nullif no match - Throws:
Exception- See Also:
-
handleMatch
Invoked when a matching mapping is found.- Parameters:
mapping- the matching mappinghandlerMethod- the matching methodexchange- the current exchange
-
handleNoMatch
@Nullable protected HandlerMethod handleNoMatch(Set<T> mappings, ServerWebExchange exchange) throws Exception Invoked when no matching mapping is not found.- Parameters:
mappings- all registered mappingsexchange- the current exchange- Returns:
- an alternative HandlerMethod or
null - Throws:
Exception- provides details that can be translated into an error status code
-
hasCorsConfigurationSource
Description copied from class:AbstractHandlerMappingReturntrueif there is aCorsConfigurationSourcefor this handler.- Overrides:
hasCorsConfigurationSourcein classAbstractHandlerMapping
-
getCorsConfiguration
Description copied from class:AbstractHandlerMappingRetrieve the CORS configuration for the given handler.- Overrides:
getCorsConfigurationin classAbstractHandlerMapping- Parameters:
handler- the handler to check (nevernull)exchange- the current exchange- Returns:
- the CORS configuration for the handler, or
nullif none
-
isHandler
Whether the given type is a handler with handler methods.- Parameters:
beanType- the type of the bean being checked- Returns:
- "true" if this a handler type, "false" otherwise.
-
getMappingForMethod
Provide the mapping for a handler method. A method for which no mapping can be provided is not a handler method.- Parameters:
method- the method to provide a mapping forhandlerType- the handler type, possibly a subtype of the method's declaring class- Returns:
- the mapping, or
nullif the method is not mapped
-
getDirectPaths
Return the request mapping paths that are not patterns.- Since:
- 5.3
-
getMatchingMapping
Check if a mapping matches the current request and return a (potentially new) mapping with conditions relevant to the current request.- Parameters:
mapping- the mapping to get a match forexchange- the current exchange- Returns:
- the match, or
nullif the mapping doesn't match
-
getMappingComparator
Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Parameters:
exchange- the current exchange- Returns:
- the comparator (never
null)
-