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 boolean |
autodetect |
private java.util.Map<java.lang.String,ResourceWebHandler> |
handlerMap |
protected Log |
logger |
private PathMatcher |
pathMatcher |
private HttpRequestPathHelper |
urlPathHelper |
Constructor and Description |
---|
ResourceUrlProvider() |
Modifier and Type | Method and Description |
---|---|
protected void |
detectResourceHandlers(ApplicationContext appContext) |
private int |
getEndPathIndex(java.lang.String lookupPath) |
<any> |
getForLookupPath(java.lang.String lookupPath)
Compare the given path against configured resource handler mappings and
if a match is found use the
ResourceResolver chain of the matched
ResourceHttpRequestHandler to resolve the URL path to expose for
public use. |
<any> |
getForRequestUrl(ServerWebExchange exchange,
java.lang.String requestUrl)
A variation on
getForLookupPath(String) that accepts a full request
URL path and returns the full request URL path to expose for public use. |
java.util.Map<java.lang.String,ResourceWebHandler> |
getHandlerMap()
Return the resource mappings, either manually configured or auto-detected
when the Spring
ApplicationContext is refreshed. |
private int |
getLookupPathIndex(ServerWebExchange exchange) |
PathMatcher |
getPathMatcher()
Return the configured
PathMatcher . |
HttpRequestPathHelper |
getUrlPathHelper()
Return the configured
UrlPathHelper . |
boolean |
isAutodetect()
Return
false if resource mappings were manually configured,
true otherwise. |
void |
onApplicationEvent(ContextRefreshedEvent event)
Handle an application event.
|
void |
setHandlerMap(java.util.Map<java.lang.String,ResourceWebHandler> handlerMap)
Manually configure the resource mappings.
|
void |
setPathMatcher(PathMatcher pathMatcher)
Configure a
PathMatcher to use when comparing target lookup path
against resource mappings. |
void |
setUrlPathHelper(HttpRequestPathHelper urlPathHelper)
Configure a
UrlPathHelper to use in
getForRequestUrl(ServerWebExchange, String)
in order to derive the lookup path for a target request URL path. |
protected final Log logger
private HttpRequestPathHelper urlPathHelper
private PathMatcher pathMatcher
private final java.util.Map<java.lang.String,ResourceWebHandler> handlerMap
private boolean autodetect
public void setUrlPathHelper(HttpRequestPathHelper urlPathHelper)
UrlPathHelper
to use in
getForRequestUrl(ServerWebExchange, String)
in order to derive the lookup path for a target request URL path.public HttpRequestPathHelper getUrlPathHelper()
UrlPathHelper
.public void setPathMatcher(PathMatcher pathMatcher)
PathMatcher
to use when comparing target lookup path
against resource mappings.public PathMatcher getPathMatcher()
PathMatcher
.public void setHandlerMap(java.util.Map<java.lang.String,ResourceWebHandler> handlerMap)
Note: by default resource mappings are auto-detected
from the Spring ApplicationContext
. However if this property is
used, the auto-detection is turned off.
public java.util.Map<java.lang.String,ResourceWebHandler> getHandlerMap()
ApplicationContext
is refreshed.public boolean isAutodetect()
false
if resource mappings were manually configured,
true
otherwise.public void onApplicationEvent(ContextRefreshedEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond toprotected void detectResourceHandlers(ApplicationContext appContext)
public final <any> getForRequestUrl(ServerWebExchange exchange, java.lang.String requestUrl)
getForLookupPath(String)
that accepts a full request
URL path and returns the full request URL path to expose for public use.exchange
- the current exchangerequestUrl
- the request URL path to resolvenull
if unresolvedprivate int getLookupPathIndex(ServerWebExchange exchange)
private int getEndPathIndex(java.lang.String lookupPath)
public final <any> getForLookupPath(java.lang.String lookupPath)
ResourceResolver
chain of the matched
ResourceHttpRequestHandler
to resolve the URL path to expose for
public use.
It is expected that the given path is what Spring uses for request mapping purposes.
If several handler mappings match, the handler used will be the one configured with the most specific pattern.
lookupPath
- the lookup path to checknull
if unresolved