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

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

Introduction

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

Prototype

String value();

Source Link

Document

The original path from which this instance was parsed.

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(/*from ww w  .  ja  v a 2  s.  co m*/
                            "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());
}

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

protected Mono<Resource> getResource(ServerWebExchange exchange) {

    String name = HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
    PathContainer pathWithinHandler = exchange.getRequiredAttribute(name);
    String path = processPath(pathWithinHandler.value());
    if (!StringUtils.hasText(path) || isInvalidPath(path)) {
        if (logger.isTraceEnabled()) {
            logger.trace("Ignoring invalid resource path [" + path + "]");
        }/*from   www .  ja va2s . co  m*/
        return Mono.empty();
    }

    if (path.contains("%")) {
        try {
            // Use URLDecoder (vs UriUtils) to preserve potentially decoded UTF-8 chars
            if (isInvalidPath(URLDecoder.decode(path, "UTF-8"))) {
                if (logger.isTraceEnabled()) {
                    logger.trace("Ignoring invalid resource path with escape sequences [" + path + "].");
                }
                return Mono.empty();
            }
        } catch (IllegalArgumentException ex) {
            // ignore
        } catch (UnsupportedEncodingException ex) {
            return Mono.error(Exceptions.propagate(ex));
        }
    }

    ResourceResolverChain resolveChain = createResolverChain();
    return resolveChain.resolveResource(exchange, path, getLocations()).flatMap(resource -> {
        ResourceTransformerChain transformerChain = createTransformerChain(resolveChain);
        return transformerChain.transform(exchange, resource);
    });
}