Example usage for org.springframework.http.server PathContainer subPath

List of usage examples for org.springframework.http.server PathContainer subPath

Introduction

In this page you can find the example usage for org.springframework.http.server PathContainer subPath.

Prototype

default PathContainer subPath(int startIndex, int endIndex) 

Source Link

Document

Extract a sub-path from the given start offset into the element list (inclusive) and to the end offset (exclusive).

Usage

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

private Mono<String> resolveResourceUrl(PathContainer lookupPath) {
    return this.handlerMap
            .entrySet().stream().filter(entry -> entry.getKey().matches(lookupPath)).sorted((entry1,
                    entry2) -> PathPattern.SPECIFICITY_COMPARATOR.compare(entry1.getKey(), entry2.getKey()))
            .findFirst().map(entry -> {
                PathContainer path = entry.getKey().extractPathWithinPattern(lookupPath);
                int endIndex = lookupPath.elements().size() - path.elements().size();
                PathContainer mapping = lookupPath.subPath(0, endIndex);
                if (logger.isTraceEnabled()) {
                    logger.trace(// www .j a  v  a2 s  .  c  om
                            "Invoking ResourceResolverChain for URL pattern " + "\"" + entry.getKey() + "\"");
                }
                ResourceWebHandler handler = entry.getValue();
                List<ResourceResolver> resolvers = handler.getResourceResolvers();
                ResourceResolverChain chain = new DefaultResourceResolverChain(resolvers);
                return chain.resolveUrlPath(path.value(), handler.getLocations()).map(resolvedPath -> {
                    if (logger.isTraceEnabled()) {
                        logger.trace("Resolved public resource URL path \"" + resolvedPath + "\"");
                    }
                    return mapping.value() + resolvedPath;
                });

            }).orElse(Mono.empty());
}