Top Description Inners Fields Constructors Methods
org.springframework.web.reactive.result.method

public abstract Class AbstractHandlerMethodMapping<T>

extends AbstractHandlerMapping
implements InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean
Known Direct Subclasses
org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping
Type Parameters
<T>
the mapping for a HandlerMethod containing the conditions needed to match the handler method to an incoming request.
Imports
java.lang.reflect.Method, java.util.ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashMap, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.ReentrantReadWriteLock, java.util.function.Function, java.util.stream.Collectors, reactor.core.publisher.Mono, org.springframework.aop.support.AopUtils, org.springframework.beans.factory.InitializingBean, org.springframework.core.MethodIntrospector, org.springframework.http.server.RequestPath, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .LinkedMultiValueMap, .MultiValueMap, .StringUtils, org.springframework.web.cors.CorsConfiguration, org.springframework.web.cors.reactive.CorsUtils, org.springframework.web.method.HandlerMethod, org.springframework.web.reactive.HandlerMapping, org.springframework.web.reactive.handler.AbstractHandlerMapping, org.springframework.web.server.ServerWebExchange

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>.

Authors
Rossen Stoyanchev, Brian Clozel, Sam Brannen
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv 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
private static class

Field Summary

Modifier and TypeField and Description
private static final CorsConfiguration
private final AbstractHandlerMethodMapping<T>.MappingRegistry
private static final 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 final String
SCOPED_TARGET_NAME_PREFIX

Bean name prefix for target beans behind scoped proxies.

Inherited from org.springframework.web.reactive.handler.AbstractHandlerMapping:
mappingsLogger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Detects handler methods at initialization.

protected HandlerMethod

Returns:

the created HandlerMethod
createHandlerMethod
(Object
either a bean name or an actual handler instance
handler
,
Method
the target method
method
)

Create the HandlerMethod instance.

protected void
detectHandlerMethods(final Object
the bean name of a handler or a handler instance
handler
)

Look for handler methods in a handler.

private String
formatMappings(Class<?> userType, Map<Method, T> methods)

protected CorsConfiguration
getCorsConfiguration(Object
the handler to check (never null)
handler
,
ServerWebExchange
the current exchange
exchange
)

Overrides org.springframework.web.reactive.handler.AbstractHandlerMapping.getCorsConfiguration.

Retrieve the CORS configuration for the given handler.

protected Set<String>
getDirectPaths(T mapping)

Return the request mapping paths that are not patterns.

public Mono<HandlerMethod>
getHandlerInternal(ServerWebExchange
the current exchange
exchange
)

Implements abstract org.springframework.web.reactive.handler.AbstractHandlerMapping.getHandlerInternal.

Look up a handler method for the given request.

public Map<T, HandlerMethod>
getHandlerMethods()

Return a (read-only) map with all mappings and HandlerMethod's.

protected abstract Comparator<T>

Returns:

the comparator (never null)
getMappingComparator
(ServerWebExchange
the current exchange
exchange
)

Return a comparator for sorting matching mappings.

protected abstract T

Returns:

the mapping, or null if the method is not mapped
getMappingForMethod
(Method
the method to provide a mapping for
method
,
Class<?>
the handler type, possibly a subtype of the method's declaring class
handlerType
)

Provide the mapping for a handler method.

pack-priv AbstractHandlerMethodMapping<T>.MappingRegistry
getMappingRegistry()

Return the internal mapping registry.

protected abstract T

Returns:

the match, or null if the mapping doesn't match
getMatchingMapping
(T
the mapping to get a match for
mapping
,
ServerWebExchange
the current exchange
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
the matching mapping
mapping
,
HandlerMethod
the matching method
handlerMethod
,
ServerWebExchange
the current exchange
exchange
)

Invoked when a matching mapping is found.

protected HandlerMethod

Returns:

an alternative HandlerMethod or null
handleNoMatch
(Set<T>
all registered mappings
mappings
,
ServerWebExchange
the current exchange
exchange
)

Invoked when no matching mapping is not found.

protected void
handlerMethodsInitialized(Map<T, HandlerMethod>
a read-only map with handler methods and mappings.
handlerMethods
)

Invoked after all handler methods have been detected.

protected boolean
protected CorsConfiguration
initCorsConfiguration(Object handler, 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

Returns:

"true" if this a handler type, "false" otherwise.
isHandler
(Class<?>
the type of the bean being checked
beanType
)

Whether the given type is a handler with handler methods.

protected HandlerMethod

Returns:

the best-matching handler method, or null if no match
lookupHandlerMethod
(ServerWebExchange
the current exchange
exchange
)

Look up the best-matching handler method for the current request.

protected void
registerHandlerMethod(Object
the bean name of the handler or the handler instance
handler
,
Method
the method to register
method
,
T
the mapping conditions associated with the handler method
mapping
)

Register a handler method and its unique mapping.

public void
registerMapping(T
the mapping for the handler method
mapping
,
Object
the handler
handler
,
Method
the method
method
)

Register the given mapping.

public void
unregisterMapping(T
the mapping to unregister
mapping
)

Un-register the given mapping.

Inherited from org.springframework.web.reactive.handler.AbstractHandlerMapping:
formatMappingNamegetCorsProcessorgetHandlergetOrdergetPathPatternParsersetBeanNamesetCorsConfigurationssetCorsConfigurationSourcesetCorsProcessorsetOrdersetUseCaseSensitiveMatchsetUseTrailingSlashMatch

Field Detail

ALLOW_CORS_CONFIGback to summary
private static final CorsConfiguration ALLOW_CORS_CONFIG
mappingRegistryback to summary
private final AbstractHandlerMethodMapping<T>.MappingRegistry mappingRegistry
PREFLIGHT_AMBIGUOUS_MATCHback to summary
private static final 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.

SCOPED_TARGET_NAME_PREFIXback to summary
private static final String SCOPED_TARGET_NAME_PREFIX

Bean name prefix for target beans behind scoped proxies. Used to exclude those targets from handler method detection, in favor of the corresponding proxies.

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 org.springframework.aop.scope.ScopedProxyUtils but duplicated here to avoid a hard dependency on the spring-aop module.

Constructor Detail

AbstractHandlerMethodMappingback to summary
public AbstractHandlerMethodMapping()

Method Detail

addMatchingMappingsback to summary
private void addMatchingMappings(Collection<T> mappings, List<AbstractHandlerMethodMapping<T>.Match> matches, ServerWebExchange exchange)
afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Detects handler methods at initialization.

Annotations
@Override
createHandlerMethodback to summary
protected HandlerMethod createHandlerMethod(Object handler, Method method)

Create the HandlerMethod instance.

Parameters
handler:Object

either a bean name or an actual handler instance

method:Method

the target method

Returns:HandlerMethod

the created HandlerMethod

detectHandlerMethodsback to summary
protected void detectHandlerMethods(final Object handler)

Look for handler methods in a handler.

Parameters
handler:Object

the bean name of a handler or a handler instance

formatMappingsback to summary
private String formatMappings(Class<?> userType, Map<Method, T> methods)
getCorsConfigurationback to summary
protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange)

Overrides org.springframework.web.reactive.handler.AbstractHandlerMapping.getCorsConfiguration.

Doc from org.springframework.web.reactive.handler.AbstractHandlerMapping.getCorsConfiguration.

Retrieve the CORS configuration for the given handler.

Parameters
handler:Object

the handler to check (never null)

exchange:ServerWebExchange

the current exchange

Returns:CorsConfiguration

the CORS configuration for the handler, or null if none

Annotations
@Override
getDirectPathsback to summary
protected Set<String> getDirectPaths(T mapping)

Return the request mapping paths that are not patterns.

Since
5.3
getHandlerInternalback to summary
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange)

Implements abstract org.springframework.web.reactive.handler.AbstractHandlerMapping.getHandlerInternal.

Look up a handler method for the given request.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:Mono<HandlerMethod>

Doc from org.springframework.web.reactive.handler.AbstractHandlerMapping.getHandlerInternal.

Mono for the matching handler, if any

Annotations
@Override
getHandlerMethodsback to summary
public Map<T, HandlerMethod> getHandlerMethods()

Return a (read-only) map with all mappings and HandlerMethod's.

getMappingComparatorback to summary
protected abstract Comparator<T> getMappingComparator(ServerWebExchange exchange)

Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:Comparator<T>

the comparator (never null)

getMappingForMethodback to summary
protected abstract T getMappingForMethod(Method method, Class<?> handlerType)

Provide the mapping for a handler method. A method for which no mapping can be provided is not a handler method.

Parameters
method:Method

the method to provide a mapping for

handlerType:Class<?>

the handler type, possibly a subtype of the method's declaring class

Returns:T

the mapping, or null if the method is not mapped

Annotations
@Nullable
getMappingRegistryback to summary
pack-priv AbstractHandlerMethodMapping<T>.MappingRegistry getMappingRegistry()

Return the internal mapping registry. Provided for testing purposes.

getMatchingMappingback to summary
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.

Parameters
mapping:T

the mapping to get a match for

exchange:ServerWebExchange

the current exchange

Returns:T

the match, or null if the mapping doesn't match

Annotations
@Nullable
handleMatchback to summary
protected void handleMatch(T mapping, HandlerMethod handlerMethod, ServerWebExchange exchange)

Invoked when a matching mapping is found.

Parameters
mapping:T

the matching mapping

handlerMethod:HandlerMethod

the matching method

exchange:ServerWebExchange

the current exchange

handleNoMatchback to summary
protected HandlerMethod handleNoMatch(Set<T> mappings, ServerWebExchange exchange) throws Exception

Invoked when no matching mapping is not found.

Parameters
mappings:Set<T>

all registered mappings

exchange:ServerWebExchange

the current exchange

Returns:HandlerMethod

an alternative HandlerMethod or null

Annotations
@Nullable
Exceptions
Exception:
provides details that can be translated into an error status code
handlerMethodsInitializedback to summary
protected void handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods)

Invoked after all handler methods have been detected.

Parameters
handlerMethods:Map<T, HandlerMethod>

a read-only map with handler methods and mappings.

hasCorsConfigurationSourceback to summary
protected boolean hasCorsConfigurationSource(Object handler)

Overrides org.springframework.web.reactive.handler.AbstractHandlerMapping.hasCorsConfigurationSource.

Doc from org.springframework.web.reactive.handler.AbstractHandlerMapping.hasCorsConfigurationSource.

Return true if there is a CorsConfigurationSource for this handler.

Annotations
@Override
initCorsConfigurationback to summary
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping)

Extract and return the CORS configuration for the mapping.

Annotations
@Nullable
initHandlerMethodsback to summary
protected void initHandlerMethods()

Scan beans in the ApplicationContext, detect and register handler methods.

See Also
isHandler(Class), getMappingForMethod(Method, Class), handlerMethodsInitialized(Map)
isHandlerback to summary
protected abstract boolean isHandler(Class<?> beanType)

Whether the given type is a handler with handler methods.

Parameters
beanType:Class<?>

the type of the bean being checked

Returns:boolean

"true" if this a handler type, "false" otherwise.

lookupHandlerMethodback to summary
protected HandlerMethod lookupHandlerMethod(ServerWebExchange exchange) throws Exception

Look up the best-matching handler method for the current request. If multiple matches are found, the best match is selected.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:HandlerMethod

the best-matching handler method, or null if no match

Annotations
@Nullable
See Also
handleMatch, handleNoMatch
registerHandlerMethodback to summary
protected void registerHandlerMethod(Object handler, Method method, T mapping)

Register a handler method and its unique mapping. Invoked at startup for each detected handler method.

Parameters
handler:Object

the bean name of the handler or the handler instance

method:Method

the method to register

mapping:T

the mapping conditions associated with the handler method

Exceptions
IllegalStateException:
if another method was already registered under the same mapping
registerMappingback to summary
public void registerMapping(T mapping, Object handler, Method method)

Register the given mapping.

This method may be invoked at runtime after initialization has completed.

Parameters
mapping:T

the mapping for the handler method

handler:Object

the handler

method:Method

the method

unregisterMappingback to summary
public void unregisterMapping(T mapping)

Un-register the given mapping.

This method may be invoked at runtime after initialization has completed.

Parameters
mapping:T

the mapping to unregister

org.springframework.web.reactive.result.method back to summary

pack-priv Class AbstractHandlerMethodMapping.MappingRegistration<T>

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.MappingRegistration

Field Summary

Modifier and TypeField and Description
private final boolean
private final Set<String>
private final HandlerMethod
private final T

Constructor Summary

AccessConstructor and Description
public
MappingRegistration(T mapping, HandlerMethod handlerMethod, Set<String> directPaths, boolean corsConfig)

Method Summary

Modifier and TypeMethod and Description
public Set<String>
public HandlerMethod
public T
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

corsConfigback to summary
private final boolean corsConfig
directPathsback to summary
private final Set<String> directPaths
handlerMethodback to summary
private final HandlerMethod handlerMethod
mappingback to summary
private final T mapping

Constructor Detail

MappingRegistrationback to summary
public MappingRegistration(T mapping, HandlerMethod handlerMethod, Set<String> directPaths, boolean corsConfig)

Method Detail

getDirectPathsback to summary
public Set<String> getDirectPaths()
getHandlerMethodback to summary
public HandlerMethod getHandlerMethod()
getMappingback to summary
public T getMapping()
hasCorsConfigback to summary
public boolean hasCorsConfig()
org.springframework.web.reactive.result.method back to summary

pack-priv Class AbstractHandlerMethodMapping.MappingRegistry

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.MappingRegistry

A registry that maintains all mappings to handler methods, exposing methods to perform lookups and providing concurrent access.

Package-private for testing purposes.

Field Summary

Modifier and TypeField and Description
private final Map<HandlerMethod, CorsConfiguration>
private final MultiValueMap<String, T>
private final ReentrantReadWriteLock
private final Map<T, AbstractHandlerMethodMapping.MappingRegistration<T>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
acquireReadLock()

Acquire the read lock when using getMappings and getMappingsByUrl.

public CorsConfiguration
getCorsConfiguration(HandlerMethod handlerMethod)

Return CORS configuration.

public List<T>
getMappingsByDirectPath(ServerWebExchange exchange)

Return matches for the given URL path.

public Map<T, AbstractHandlerMethodMapping.MappingRegistration<T>>
getRegistrations()

Return all registrations.

public void
register(T mapping, Object handler, Method method)

public void
releaseReadLock()

Release the read lock after using getMappings and getMappingsByUrl.

public void
unregister(T mapping)

private void
validateMethodMapping(HandlerMethod handlerMethod, T mapping)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

corsLookupback to summary
private final Map<HandlerMethod, CorsConfiguration> corsLookup
pathLookupback to summary
private final MultiValueMap<String, T> pathLookup
readWriteLockback to summary
private final ReentrantReadWriteLock readWriteLock
registryback to summary
private final Map<T, AbstractHandlerMethodMapping.MappingRegistration<T>> registry

Constructor Detail

MappingRegistryback to summary
pack-priv MappingRegistry()

Method Detail

acquireReadLockback to summary
public void acquireReadLock()

Acquire the read lock when using getMappings and getMappingsByUrl.

getCorsConfigurationback to summary
public CorsConfiguration getCorsConfiguration(HandlerMethod handlerMethod)

Return CORS configuration. Thread-safe for concurrent use.

Annotations
@Nullable
getMappingsByDirectPathback to summary
public List<T> getMappingsByDirectPath(ServerWebExchange exchange)

Return matches for the given URL path. Not thread-safe.

Annotations
@Nullable
Since
5.3
See Also
acquireReadLock()
getRegistrationsback to summary
public Map<T, AbstractHandlerMethodMapping.MappingRegistration<T>> getRegistrations()

Return all registrations.

Since
5.3
registerback to summary
public void register(T mapping, Object handler, Method method)
releaseReadLockback to summary
public void releaseReadLock()

Release the read lock after using getMappings and getMappingsByUrl.

unregisterback to summary
public void unregister(T mapping)
validateMethodMappingback to summary
private void validateMethodMapping(HandlerMethod handlerMethod, T mapping)
org.springframework.web.reactive.result.method back to summary

private Class AbstractHandlerMethodMapping.Match

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.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.

Field Summary

Modifier and TypeField and Description
private final T
private final AbstractHandlerMethodMapping.MappingRegistration<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HandlerMethod
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

mappingback to summary
private final T mapping
registrationback to summary
private final AbstractHandlerMethodMapping.MappingRegistration<T> registration

Constructor Detail

Matchback to summary
public Match(T mapping, AbstractHandlerMethodMapping.MappingRegistration<T> registration)

Method Detail

getHandlerMethodback to summary
public HandlerMethod getHandlerMethod()
hasCorsConfigback to summary
public boolean hasCorsConfig()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.reactive.result.method back to summary

private Class AbstractHandlerMethodMapping.MatchComparator

extends Object
implements Comparator<AbstractHandlerMethodMapping<T>.Match>
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.MatchComparator
All Implemented Interfaces
java.util.Comparator

Field Summary

Modifier and TypeField and Description
private final Comparator<T>

Constructor Summary

AccessConstructor and Description
public
MatchComparator(Comparator<T> comparator)

Method Summary

Modifier and TypeMethod and Description
public int
compare(AbstractHandlerMethodMapping<T>.Match
the first object to be compared.
match1
,
AbstractHandlerMethodMapping<T>.Match
the second object to be compared.
match2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

comparatorback to summary
private final Comparator<T> comparator

Constructor Detail

MatchComparatorback to summary
public MatchComparator(Comparator<T> comparator)

Method Detail

compareback to summary
public int compare(AbstractHandlerMethodMapping<T>.Match match1, AbstractHandlerMethodMapping<T>.Match match2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
match1:AbstractHandlerMethodMapping<T>.Match

the first object to be compared.

match2:AbstractHandlerMethodMapping<T>.Match

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
org.springframework.web.reactive.result.method back to summary

private Class AbstractHandlerMethodMapping.PreFlightAmbiguousMatchHandler

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.PreFlightAmbiguousMatchHandler

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PreFlightAmbiguousMatchHandlerback to summary
private PreFlightAmbiguousMatchHandler()

Method Detail

handleback to summary
public void handle()
Annotations
@SuppressWarnings:unused