public class ResourceUrlProvider extends java.lang.Object implements ApplicationListener<ContextRefreshedEvent>
This class is aware of Spring WebFlux handler mappings used to serve static
resources and uses the ResourceResolver
chains of the configured
ResourceHttpRequestHandler
s to make its decisions.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<PathPattern,ResourceWebHandler> |
handlerMap |
private static Log |
logger |
private PathPatternParser |
patternParser |
Constructor and Description |
---|
ResourceUrlProvider() |
Modifier and Type | Method and Description |
---|---|
private void |
detectResourceHandlers(ApplicationContext context) |
<any> |
getForUriString(java.lang.String uriString,
ServerWebExchange exchange)
Get the public resource URL for the given URI string.
|
java.util.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 |
getQueryIndex(java.lang.String path) |
void |
onApplicationEvent(ContextRefreshedEvent event)
Handle an application event.
|
private static java.lang.String |
prependLeadingSlash(java.lang.String pattern) |
void |
registerHandlers(java.util.Map<java.lang.String,ResourceWebHandler> handlerMap)
Manually configure resource handler mappings.
|
private <any> |
resolveResourceUrl(PathContainer lookupPath) |
private static final Log logger
private final PathPatternParser patternParser
private final java.util.Map<PathPattern,ResourceWebHandler> handlerMap
public java.util.Map<PathPattern,ResourceWebHandler> getHandlerMap()
public void registerHandlers(java.util.Map<java.lang.String,ResourceWebHandler> handlerMap)
Note: by default resource mappings are auto-detected
from the Spring ApplicationContext
. If this property is used,
auto-detection is turned off.
private static java.lang.String prependLeadingSlash(java.lang.String pattern)
public void onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond toprivate void detectResourceHandlers(ApplicationContext context)
public final <any> getForUriString(java.lang.String uriString, ServerWebExchange exchange)
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.
uriString
- the URI string to transformexchange
- the current exchangeprivate int getQueryIndex(java.lang.String path)
private <any> resolveResourceUrl(PathContainer lookupPath)