Example usage for org.springframework.web.reactive.resource PathResourceResolver getAllowedLocations

List of usage examples for org.springframework.web.reactive.resource PathResourceResolver getAllowedLocations

Introduction

In this page you can find the example usage for org.springframework.web.reactive.resource PathResourceResolver getAllowedLocations.

Prototype

@Nullable
    public Resource[] getAllowedLocations() 

Source Link

Usage

From source file:org.springframework.web.reactive.resource.ResourceWebHandler.java

/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this class.
 *//*from   w w  w  .  j a  v  a 2 s  .  co  m*/
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        if (logger.isWarnEnabled()) {
            logger.warn("Locations list is empty. No resources will be served unless a "
                    + "custom ResourceResolver is configured as an alternative to PathResourceResolver.");
        }
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver resolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) {
                resolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
            }
            break;
        }
    }
}