use of org.springframework.web.util.pattern.PathPattern 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);
}
use of org.springframework.web.util.pattern.PathPattern in project spring-framework by spring-projects.
the class PathPatternsRequestCondition method getMatchingPatterns.
@Nullable
private SortedSet<PathPattern> getMatchingPatterns(PathContainer path) {
TreeSet<PathPattern> result = null;
for (PathPattern pattern : this.patterns) {
if (pattern.matches(path)) {
result = (result != null ? result : new TreeSet<>());
result.add(pattern);
}
}
return result;
}
use of org.springframework.web.util.pattern.PathPattern 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);
}
use of org.springframework.web.util.pattern.PathPattern 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);
}
use of org.springframework.web.util.pattern.PathPattern in project spring-cloud-open-service-broker by spring-cloud.
the class ApiVersionWebFilter method filter.
/**
* Process the web request and validate the API version in the header. If the API version
* does not match, then set an HTTP 412 status and write the error message to the response.
*
* @param exchange {@inheritDoc}
* @param chain {@inheritDoc}
* @return {@inheritDoc}
*/
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
PathPattern p = new PathPatternParser().parse(V2_API_PATH_PATTERN);
if (p.matches(exchange.getRequest().getPath()) && version != null && !anyVersionAllowed()) {
String apiVersion = exchange.getRequest().getHeaders().getFirst(version.getBrokerApiVersionHeader());
if (!version.getApiVersion().equals(apiVersion)) {
String message = ServiceBrokerApiVersionErrorMessage.from(version.getApiVersion(), apiVersion).toString();
ServerHttpResponse response = exchange.getResponse();
String json;
try {
json = new ObjectMapper().writeValueAsString(new ErrorMessage(message));
} catch (JsonProcessingException e) {
json = "{}";
}
response.setStatusCode(HttpStatus.PRECONDITION_FAILED);
Flux<DataBuffer> responseBody = Flux.just(json).map(s -> toDataBuffer(s, response.bufferFactory()));
return response.writeWith(responseBody);
}
}
return chain.filter(exchange);
}
Aggregations