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

public Class ResourceUrlProvider

extends Object
implements ApplicationListener<ContextRefreshedEvent>, ApplicationContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationListener, java.util.EventListener
Imports
java.util.Collections, .LinkedHashMap, .List, .Map, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Mono, org.springframework.beans.BeansException, org.springframework.context.ApplicationContext, .ApplicationContextAware, .ApplicationListener, org.springframework.context.event.ContextRefreshedEvent, org.springframework.http.server.PathContainer, org.springframework.http.server.reactive.ServerHttpRequest, org.springframework.lang.Nullable, org.springframework.web.reactive.HandlerMapping, org.springframework.web.reactive.handler.AbstractUrlHandlerMapping, org.springframework.web.server.ServerWebExchange, org.springframework.web.util.pattern.PathPattern, .PathPatternParser

A central component to use to obtain the public URL path that clients should use to access a static resource.

This class is aware of Spring WebFlux handler mappings used to serve static resources and uses the ResourceResolver chains of the configured ResourceHttpRequestHandlers to make its decisions.

Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private ApplicationContext
private final Map<PathPattern, ResourceWebHandler>
private static final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public final Mono<String>

Returns:

the resolved public resource URL path, or empty if unresolved
getForUriString
(String
the URI string to transform
uriString
,
ServerWebExchange
the current exchange
exchange
)

Get the public resource URL for the given URI string.

public Map<PathPattern, ResourceWebHandler>
getHandlerMap()

Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration.

private int
public void
onApplicationEvent(ContextRefreshedEvent
the event to respond to
event
)

Implements org.springframework.context.ApplicationListener.onApplicationEvent.

Handle an application event.

public void
registerHandlers(Map<String, ResourceWebHandler> handlerMap)

Manually configure resource handler mappings.

private Mono<String>
public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationContextback to summary
private ApplicationContext applicationContext
Annotations
@Nullable
handlerMapback to summary
private final Map<PathPattern, ResourceWebHandler> handlerMap
loggerback to summary
private static final Log logger

Constructor Detail

ResourceUrlProviderback to summary
public ResourceUrlProvider()

Method Detail

detectResourceHandlersback to summary
private void detectResourceHandlers(ApplicationContext context)
getForUriStringback to summary
public final Mono<String> getForUriString(String uriString, ServerWebExchange exchange)

Get the public resource URL for the given URI string.

The URI string is expected to be a path and if it contains a query or fragment those will be preserved in the resulting public resource URL.

Parameters
uriString:String

the URI string to transform

exchange:ServerWebExchange

the current exchange

Returns:Mono<String>

the resolved public resource URL path, or empty if unresolved

getHandlerMapback to summary
public Map<PathPattern, ResourceWebHandler> getHandlerMap()

Return a read-only view of the resource handler mappings either manually configured or auto-detected from Spring configuration.

getQueryIndexback to summary
private int getQueryIndex(String path)
onApplicationEventback to summary
public void onApplicationEvent(ContextRefreshedEvent event)

Implements org.springframework.context.ApplicationListener.onApplicationEvent.

Doc from org.springframework.context.ApplicationListener.onApplicationEvent.

Handle an application event.

Parameters
event:ContextRefreshedEvent

the event to respond to

Annotations
@Override
registerHandlersback to summary
public void registerHandlers(Map<String, ResourceWebHandler> handlerMap)

Manually configure resource handler mappings.

Note

by default resource mappings are auto-detected from the Spring ApplicationContext. If this property is used, auto-detection is turned off.

resolveResourceUrlback to summary
private Mono<String> resolveResourceUrl(ServerWebExchange exchange, PathContainer lookupPath)
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override
Exceptions
BeansException:
if thrown by application context methods