Search in sources :

Example 16 with PathPattern

use of org.springframework.web.util.pattern.PathPattern in project spring-framework by spring-projects.

the class PatternsRequestCondition method getDirectPaths.

/**
 * Return the mapping paths that are not patterns.
 * @since 5.3
 */
public Set<String> getDirectPaths() {
    if (isEmptyPathMapping()) {
        return EMPTY_PATH;
    }
    Set<String> result = Collections.emptySet();
    for (PathPattern pattern : this.patterns) {
        if (!pattern.hasPatternSyntax()) {
            result = (result.isEmpty() ? new HashSet<>(1) : result);
            result.add(pattern.getPatternString());
        }
    }
    return result;
}
Also used : PathPattern(org.springframework.web.util.pattern.PathPattern)

Example 17 with PathPattern

use of org.springframework.web.util.pattern.PathPattern in project spring-framework by spring-projects.

the class PatternsRequestCondition method getMatchingPatterns.

@Nullable
private SortedSet<PathPattern> getMatchingPatterns(ServerWebExchange exchange) {
    PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
    TreeSet<PathPattern> result = null;
    for (PathPattern pattern : this.patterns) {
        if (pattern.matches(lookupPath)) {
            result = (result != null ? result : new TreeSet<>());
            result.add(pattern);
        }
    }
    return result;
}
Also used : PathContainer(org.springframework.http.server.PathContainer) PathPattern(org.springframework.web.util.pattern.PathPattern) Nullable(org.springframework.lang.Nullable)

Example 18 with PathPattern

use of org.springframework.web.util.pattern.PathPattern in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method handleMatchBestMatchingPatternAttributeNoPatternsDefined.

// gh-22543
@Test
public void handleMatchBestMatchingPatternAttributeNoPatternsDefined() {
    ServerWebExchange exchange = MockServerWebExchange.from(get(""));
    this.handlerMapping.handleMatch(paths().build(), handlerMethod, exchange);
    PathPattern pattern = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
    assertThat(pattern.getPatternString()).isEqualTo("");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) PathPattern(org.springframework.web.util.pattern.PathPattern) Test(org.junit.jupiter.api.Test)

Example 19 with PathPattern

use of org.springframework.web.util.pattern.PathPattern in project spring-framework by spring-projects.

the class RequestMappingHandlerMappingTests method assertComposedAnnotationMapping.

private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path, RequestMethod requestMethod) throws Exception {
    Class<?> clazz = ComposedAnnotationController.class;
    Method method = ClassUtils.getMethod(clazz, methodName, (Class<?>[]) null);
    RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);
    assertThat(info).isNotNull();
    Set<PathPattern> paths = info.getPatternsCondition().getPatterns();
    assertThat(paths.size()).isEqualTo(1);
    assertThat(paths.iterator().next().getPatternString()).isEqualTo(path);
    Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
    assertThat(methods.size()).isEqualTo(1);
    assertThat(methods.iterator().next()).isEqualTo(requestMethod);
    return info;
}
Also used : PathPattern(org.springframework.web.util.pattern.PathPattern) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Method(java.lang.reflect.Method) RequestMethod(org.springframework.web.bind.annotation.RequestMethod)

Aggregations

PathPattern (org.springframework.web.util.pattern.PathPattern)19 PathContainer (org.springframework.http.server.PathContainer)6 Test (org.junit.jupiter.api.Test)5 Nullable (org.springframework.lang.Nullable)4 RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)3 ServerWebExchange (org.springframework.web.server.ServerWebExchange)3 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)3 PathPatternParser (org.springframework.web.util.pattern.PathPatternParser)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ServiceBrokerApiVersionErrorMessage (org.springframework.cloud.servicebroker.exception.ServiceBrokerApiVersionErrorMessage)1 ErrorMessage (org.springframework.cloud.servicebroker.model.error.ErrorMessage)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1 ServerCodecConfigurer (org.springframework.http.codec.ServerCodecConfigurer)1