Search in sources :

Example 6 with PathContainer

use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMapping method extractMatchDetails.

private void extractMatchDetails(PathPatternsRequestCondition condition, String lookupPath, HttpServletRequest request) {
    PathPattern bestPattern;
    Map<String, String> uriVariables;
    if (condition.isEmptyPathMapping()) {
        bestPattern = condition.getFirstPattern();
        uriVariables = Collections.emptyMap();
    } else {
        PathContainer path = ServletRequestPathUtils.getParsedRequestPath(request).pathWithinApplication();
        bestPattern = condition.getFirstPattern();
        PathPattern.PathMatchInfo result = bestPattern.matchAndExtract(path);
        Assert.notNull(result, () -> "Expected bestPattern: " + bestPattern + " to match lookupPath " + path);
        uriVariables = result.getUriVariables();
        request.setAttribute(MATRIX_VARIABLES_ATTRIBUTE, result.getMatrixVariables());
    }
    request.setAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern.getPatternString());
    request.setAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
}
Also used : PathContainer(org.springframework.http.server.PathContainer) PathPattern(org.springframework.web.util.pattern.PathPattern)

Example 7 with PathContainer

use of org.springframework.http.server.PathContainer in project flow by vaadin.

the class EndpointUtil method getEndpoint.

private Optional<Method> getEndpoint(HttpServletRequest request) {
    PathPatternParser pathParser = new PathPatternParser();
    PathPattern pathPattern = pathParser.parse(endpointProperties.getEndpointPrefix() + EndpointController.ENDPOINT_METHODS);
    RequestPath requestPath = ServletRequestPathUtils.parseAndCache(request);
    PathContainer pathWithinApplication = requestPath.pathWithinApplication();
    PathMatchInfo matchInfo = pathPattern.matchAndExtract(pathWithinApplication);
    if (matchInfo == null) {
        return Optional.empty();
    }
    Map<String, String> uriVariables = matchInfo.getUriVariables();
    String endpointName = uriVariables.get("endpoint");
    String endpointMethod = uriVariables.get("method");
    EndpointRegistry.VaadinEndpointData data = registry.get(endpointName);
    if (data == null) {
        return Optional.empty();
    }
    return data.getMethod(endpointMethod);
}
Also used : RequestPath(org.springframework.http.server.RequestPath) PathContainer(org.springframework.http.server.PathContainer) PathMatchInfo(org.springframework.web.util.pattern.PathPattern.PathMatchInfo) PathPattern(org.springframework.web.util.pattern.PathPattern) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser)

Example 8 with PathContainer

use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.

the class PathPatternTests method checkNoMatch.

private void checkNoMatch(String uriTemplate, String path) {
    PathPatternParser p = new PathPatternParser();
    PathPattern pattern = p.parse(uriTemplate);
    PathContainer PathContainer = toPathContainer(path);
    assertThat(pattern.matches(PathContainer)).isFalse();
}
Also used : PathContainer(org.springframework.http.server.PathContainer)

Example 9 with PathContainer

use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.

the class PathPatternTests method extractPathWithinPatternCustomSeparator.

@Test
public void extractPathWithinPatternCustomSeparator() {
    PathPatternParser ppp = new PathPatternParser();
    ppp.setPathOptions(PathContainer.Options.create('.', true));
    PathPattern pp = ppp.parse("test.**");
    PathContainer pathContainer = PathContainer.parsePath("test.projects..spring-framework", PathContainer.Options.create('.', true));
    PathContainer result = pp.extractPathWithinPattern(pathContainer);
    assertThat(result.value()).isEqualTo("projects.spring-framework");
    assertThat(result.elements()).hasSize(3);
}
Also used : PathContainer(org.springframework.http.server.PathContainer) Test(org.junit.jupiter.api.Test)

Example 10 with PathContainer

use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.

the class PathPatternsRequestCondition method getMatchingCondition.

/**
 * Checks if any of the patterns match the given request and returns an
 * instance that is guaranteed to contain matching patterns, sorted.
 * @param request the current request
 * @return the same instance if the condition contains no patterns;
 * or a new condition with sorted matching patterns;
 * or {@code null} if no patterns match.
 */
@Override
@Nullable
public PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request) {
    PathContainer path = ServletRequestPathUtils.getParsedRequestPath(request).pathWithinApplication();
    SortedSet<PathPattern> matches = getMatchingPatterns(path);
    return (matches != null ? new PathPatternsRequestCondition(matches) : null);
}
Also used : PathContainer(org.springframework.http.server.PathContainer) PathPattern(org.springframework.web.util.pattern.PathPattern) Nullable(org.springframework.lang.Nullable)

Aggregations

PathContainer (org.springframework.http.server.PathContainer)14 PathPattern (org.springframework.web.util.pattern.PathPattern)6 Nullable (org.springframework.lang.Nullable)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Resource (org.springframework.core.io.Resource)2 UrlResource (org.springframework.core.io.UrlResource)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 MediaType (org.springframework.http.MediaType)1 RequestPath (org.springframework.http.server.RequestPath)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1 MultiValueMap (org.springframework.util.MultiValueMap)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)1 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)1 PathMatchInfo (org.springframework.web.util.pattern.PathPattern.PathMatchInfo)1