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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations