Example usage for org.springframework.web.util.pattern PathPattern getPatternString

List of usage examples for org.springframework.web.util.pattern PathPattern getPatternString

Introduction

In this page you can find the example usage for org.springframework.web.util.pattern PathPattern getPatternString.

Prototype

public String getPatternString() 

Source Link

Document

Return the original String that was parsed to create this PathPattern.

Usage

From source file:org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory.java

@Override
public Predicate<ServerWebExchange> apply(Config config) {
    final ArrayList<PathPattern> pathPatterns = new ArrayList<>();
    synchronized (this.pathPatternParser) {
        pathPatternParser.setMatchOptionalTrailingSeparator(config.isMatchOptionalTrailingSeparator());
        config.getPatterns().forEach(pattern -> {
            PathPattern pathPattern = this.pathPatternParser.parse(pattern);
            pathPatterns.add(pathPattern);
        });/*from w  w  w  . ja  v a2s  .  co  m*/
    }
    return exchange -> {
        PathContainer path = parsePath(exchange.getRequest().getURI().getRawPath());

        Optional<PathPattern> optionalPathPattern = pathPatterns.stream()
                .filter(pattern -> pattern.matches(path)).findFirst();

        if (optionalPathPattern.isPresent()) {
            PathPattern pathPattern = optionalPathPattern.get();
            traceMatch("Pattern", pathPattern.getPatternString(), path, true);
            PathMatchInfo pathMatchInfo = pathPattern.matchAndExtract(path);
            putUriTemplateVariables(exchange, pathMatchInfo.getUriVariables());
            return true;
        } else {
            traceMatch("Pattern", config.getPatterns(), path, false);
            return false;
        }
    };
}