Top Description Fields Constructors Methods
org.springframework.web.reactive.handler

public abstract Class AbstractUrlHandlerMapping

extends AbstractHandlerMapping
Class Inheritance
Known Direct Subclasses
org.springframework.web.reactive.handler.SimpleUrlHandlerMapping
Imports
java.util.ArrayList, .Collections, .LinkedHashMap, .List, .Map, java.util.function.BiPredicate, reactor.core.publisher.Mono, org.springframework.beans.BeansException, org.springframework.http.server.PathContainer, org.springframework.http.server.reactive.observation.ServerRequestObservationContext, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.server.ServerWebExchange, org.springframework.web.util.pattern.PathPattern, .PathPatternParser

Abstract base class for URL-mapped org.springframework.web.reactive.HandlerMapping implementations.

Supports direct matches, e.g. a registered "/test" matches "/test", and various path 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 org.springframework.web.util.pattern.PathPattern javadoc.

Will search all path patterns to find the most specific match for the current request path. The most specific pattern is defined as the longest path pattern with the fewest captured variables and wildcards.

Authors
Rossen Stoyanchev, Juergen Hoeller, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private final Map<PathPattern, Object>
private BiPredicate<Object, ServerWebExchange>
private boolean
Inherited from org.springframework.web.reactive.handler.AbstractHandlerMapping:
mappingsLogger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private String
public Mono<Object>
getHandlerInternal(ServerWebExchange
current exchange
exchange
)

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

Look up a handler for the given request, returning an empty Mono if no specific one is found.

public final Map<PathPattern, Object>
getHandlerMap()

Return a read-only view of registered path patterns and handlers which may be an actual handler instance or the bean name of lazily initialized handler.

protected Object

Returns:

the associated handler instance, or null if not found
lookupHandler
(PathContainer
the URL the handler is mapped to
lookupPath
,
ServerWebExchange
the current exchange
exchange
)

Look up a handler instance for the given URL lookup path.

protected void
registerHandler(String[]
the URLs that the bean should be mapped to
urlPaths
,
String
the name of the handler bean
beanName
)

Register the specified handler for the given URL paths.

protected void
registerHandler(String
the URL the bean should be mapped to
urlPath
,
Object
the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
handler
)

Register the specified handler for the given URL path.

public void
setHandlerPredicate(BiPredicate<Object, ServerWebExchange>
a bi-predicate to match the candidate handler against the current exchange.
handlerPredicate
)

Configure a predicate for extended matching of the handler that was matched by URL path.

public void
setLazyInitHandlers(boolean lazyInitHandlers)

Set whether to lazily initialize handlers.

protected void
validateHandler(Object
the handler object to validate
handler
,
ServerWebExchange
current exchange
exchange
)

Validate the given handler against the current request.

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

Field Detail

handlerMapback to summary
private final Map<PathPattern, Object> handlerMap
handlerPredicateback to summary
private BiPredicate<Object, ServerWebExchange> handlerPredicate
Annotations
@Nullable
lazyInitHandlersback to summary
private boolean lazyInitHandlers

Constructor Detail

AbstractUrlHandlerMappingback to summary
public AbstractUrlHandlerMapping()

Method Detail

getHandlerDescriptionback to summary
private String getHandlerDescription(Object handler)
getHandlerInternalback to summary
public Mono<Object> getHandlerInternal(ServerWebExchange exchange)

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

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

Look up a handler for the given request, returning an empty Mono if no specific one is found. This method is called by getHandler.

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.

Parameters
exchange:ServerWebExchange

current exchange

Returns:Mono<Object>

Mono for the matching handler, if any

Annotations
@Override
getHandlerMapback to summary
public final Map<PathPattern, Object> getHandlerMap()

Return a read-only view of registered path patterns and handlers which may be an actual handler instance or the bean name of lazily initialized handler.

lookupHandlerback to summary
protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception

Look up a handler instance for the given URL lookup path.

Supports direct matches, e.g. a registered "/test" matches "/test", and various path pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the PathPattern class.

Parameters
lookupPath:PathContainer

the URL the handler is mapped to

exchange:ServerWebExchange

the current exchange

Returns:Object

the associated handler instance, or null if not found

Annotations
@Nullable
@SuppressWarnings:removal
See Also
org.springframework.web.util.pattern.PathPattern
registerHandlerback to summary
protected void registerHandler(String[] urlPaths, String beanName) throws BeansException, IllegalStateException

Register the specified handler for the given URL paths.

Parameters
urlPaths:String[]

the URLs that the bean should be mapped to

beanName:String

the name of the handler bean

Exceptions
BeansException:
if the handler couldn't be registered
IllegalStateException:
if there is a conflicting handler registered
registerHandlerback to summary
protected void registerHandler(String urlPath, Object handler) throws BeansException, IllegalStateException

Register the specified handler for the given URL path.

Parameters
urlPath:String

the URL the bean should be mapped to

handler:Object

the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)

Exceptions
BeansException:
if the handler couldn't be registered
IllegalStateException:
if there is a conflicting handler registered
setHandlerPredicateback to summary
public void setHandlerPredicate(BiPredicate<Object, ServerWebExchange> handlerPredicate)

Configure a predicate for extended matching of the handler that was matched by URL path. This allows for further narrowing of the mapping by checking additional properties of the request. If the predicate returns "false", it result in a no-match, which allows another org.springframework.web.reactive.HandlerMapping to match or result in a 404 (NOT_FOUND) response.

Parameters
handlerPredicate:BiPredicate<Object, ServerWebExchange>

a bi-predicate to match the candidate handler against the current exchange.

Since
5.3.5
See Also
org.springframework.web.reactive.socket.server.support.WebSocketUpgradeHandlerPredicate
setLazyInitHandlersback to summary
public void setLazyInitHandlers(boolean lazyInitHandlers)

Set whether to lazily initialize handlers. Only applicable to singleton handlers, as prototypes are always lazily initialized. Default is "false", as eager initialization allows for more efficiency through referencing the controller objects directly.

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.

validateHandlerback to summary
protected void validateHandler(Object handler, ServerWebExchange exchange)

Validate the given handler against the current request.

The default implementation is empty. Can be overridden in subclasses, for example to enforce specific preconditions expressed in URL mappings.

Parameters
handler:Object

the handler object to validate

exchange:ServerWebExchange

current exchange

Annotations
@SuppressWarnings:UnusedParameters