Java Code Examples for org.springframework.web.util.pattern.PathPattern#matches()
The following examples show how to use
org.springframework.web.util.pattern.PathPattern#matches() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatternsRequestCondition.java From spring-analysis-note with MIT License | 5 votes |
/** * Find the patterns matching the given lookup path. Invoking this method should * yield results equivalent to those of calling * {@link #getMatchingCondition(ServerWebExchange)}. * This method is provided as an alternative to be used if no request is available * (e.g. introspection, tooling, etc). * @param exchange the current exchange * @return a sorted set of matching patterns sorted with the closest match first */ private SortedSet<PathPattern> getMatchingPatterns(ServerWebExchange exchange) { PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication(); TreeSet<PathPattern> pathPatterns = new TreeSet<>(); for (PathPattern pattern : this.patterns) { if (pattern.matches(lookupPath)) { pathPatterns.add(pattern); } } return pathPatterns; }
Example 2
Source File: ApiVersionWebFilter.java From spring-cloud-open-service-broker with Apache License 2.0 | 5 votes |
/** * 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); Mono<Void> filterMono = chain.filter(exchange); if (p.matches(exchange.getRequest().getPath()) && version != null && !anyVersionAllowed()) { String apiVersion = exchange.getRequest().getHeaders().getFirst(version.getBrokerApiVersionHeader()); ServerHttpResponse response = exchange.getResponse(); String message = null; if (apiVersion == null) { response.setStatusCode(HttpStatus.BAD_REQUEST); message = ServiceBrokerApiVersionErrorMessage.from(version.getApiVersion(), "null").toString(); } else if (!version.getApiVersion().equals(apiVersion)) { response.setStatusCode(HttpStatus.PRECONDITION_FAILED); message = ServiceBrokerApiVersionErrorMessage.from(version.getApiVersion(), apiVersion) .toString(); } if (message != null) { String json; try { json = new ObjectMapper().writeValueAsString(new ErrorMessage(message)); } catch (JsonProcessingException e) { json = "{}"; } Flux<DataBuffer> responseBody = Flux.just(json) .map(s -> toDataBuffer(s, response.bufferFactory())); filterMono = response.writeWith(responseBody); } } return filterMono; }
Example 3
Source File: HandlerMethodMappingTests.java From spring-analysis-note with MIT License | 4 votes |
@Override protected String getMatchingMapping(String pattern, ServerWebExchange exchange) { PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication(); PathPattern parsedPattern = this.parser.parse(pattern); return (parsedPattern.matches(lookupPath) ? pattern : null); }
Example 4
Source File: HandlerMethodMappingTests.java From java-technology-stack with MIT License | 4 votes |
@Override protected String getMatchingMapping(String pattern, ServerWebExchange exchange) { PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication(); PathPattern parsedPattern = this.parser.parse(pattern); return (parsedPattern.matches(lookupPath) ? pattern : null); }