use of org.springframework.web.util.pattern.PathPatternParser in project spring-boot by spring-projects.
the class WebMvcTagsTests method uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable.
@Test
void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable() {
this.request.setAttribute("org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH", new PathPatternParser().parse("/api/cities"));
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/api/{repository}");
Tag tag = WebMvcTags.uri(this.request, this.response);
assertThat(tag.getValue()).isEqualTo("/api/cities");
}
use of org.springframework.web.util.pattern.PathPatternParser 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.PathPatternParser 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);
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-boot by spring-projects.
the class MetricsWebFilterTests method createExchange.
private MockServerWebExchange createExchange(String path, String pathPattern) {
PathPatternParser parser = new PathPatternParser();
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(path).build());
exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, parser.parse(pathPattern));
return exchange;
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method customPathMatchConfig.
@Test
public void customPathMatchConfig() {
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
ReflectionUtils.makeAccessible(field);
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertThat(mapping).isNotNull();
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertThat(matchOptionalTrailingSlash).isFalse();
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
assertThat(map.size()).isEqualTo(1);
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")));
}
Aggregations