use of org.springframework.http.server.PathContainer in project spring-security by spring-projects.
the class PathPatternParserServerWebExchangeMatcher method matches.
@Override
public Mono<MatchResult> matches(ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest();
PathContainer path = request.getPath().pathWithinApplication();
if (this.method != null && !this.method.equals(request.getMethod())) {
return MatchResult.notMatch().doOnNext((result) -> {
if (logger.isDebugEnabled()) {
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method + " " + this.pattern.getPatternString() + "'");
}
});
}
boolean match = this.pattern.matches(path);
if (!match) {
return MatchResult.notMatch().doOnNext((result) -> {
if (logger.isDebugEnabled()) {
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method + " " + this.pattern.getPatternString() + "'");
}
});
}
Map<String, String> pathVariables = this.pattern.matchAndExtract(path).getUriVariables();
Map<String, Object> variables = new HashMap<>(pathVariables);
if (logger.isDebugEnabled()) {
logger.debug("Checking match of request : '" + path + "'; against '" + this.pattern.getPatternString() + "'");
}
return MatchResult.match(variables);
}
use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.
the class PathPatternTests method checkMatches.
private void checkMatches(String uriTemplate, String path) {
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(true);
PathPattern p = parser.parse(uriTemplate);
PathContainer pc = toPathContainer(path);
assertThat(p.matches(pc)).isTrue();
}
use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.
the class SimpleUrlHandlerMappingTests method testUrl.
void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
Object actual = handlerMapping.getHandler(exchange).block();
if (bean != null) {
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(bean);
// noinspection OptionalGetWithoutIsPresent
PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
assertThat(path).isNotNull();
assertThat(path.value()).isEqualTo(pathWithinMapping);
} else {
assertThat(actual).isNull();
}
}
use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.
the class PathResourceLookupFunction method apply.
@Override
public Optional<Resource> apply(ServerRequest request) {
PathContainer pathContainer = request.requestPath().pathWithinApplication();
if (!this.pattern.matches(pathContainer)) {
return Optional.empty();
}
pathContainer = this.pattern.extractPathWithinPattern(pathContainer);
String path = processPath(pathContainer.value());
if (path.contains("%")) {
path = StringUtils.uriDecode(path, StandardCharsets.UTF_8);
}
if (!StringUtils.hasLength(path) || isInvalidPath(path)) {
return Optional.empty();
}
try {
Resource resource = this.location.createRelative(path);
if (resource.isReadable() && isResourceUnderLocation(resource)) {
return Optional.of(resource);
} else {
return Optional.empty();
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
use of org.springframework.http.server.PathContainer in project spring-framework by spring-projects.
the class PathPatternMatchableHandlerMapping method match.
@Nullable
@Override
public RequestMatchResult match(HttpServletRequest request, String pattern) {
PathPattern pathPattern = this.pathPatternCache.computeIfAbsent(pattern, value -> {
Assert.isTrue(this.pathPatternCache.size() < MAX_PATTERNS, "Max size for pattern cache exceeded.");
return this.parser.parse(pattern);
});
PathContainer path = ServletRequestPathUtils.getParsedRequestPath(request).pathWithinApplication();
return (pathPattern.matches(path) ? new RequestMatchResult(pathPattern, path) : null);
}
Aggregations