/** * Create a new {@link PartialMatch} instance. * @param info the RequestMappingInfo that matches the URL path * @param exchange the current exchange */ public PartialMatch(RequestMappingInfo info, ServerWebExchange exchange) { this.info = info; this.methodsMatch = info.getMethodsCondition().getMatchingCondition(exchange) != null; this.consumesMatch = info.getConsumesCondition().getMatchingCondition(exchange) != null; this.producesMatch = info.getProducesCondition().getMatchingCondition(exchange) != null; this.paramsMatch = info.getParamsCondition().getMatchingCondition(exchange) != null; }
/** * Checks if all conditions in this request mapping info match the provided request and returns * a potentially new request mapping info with conditions tailored to the current request. * <p>For example the returned instance may contain the subset of URL patterns that match to * the current request, sorted with best matching patterns on top. * @return a new instance in case all conditions match; or {@code null} otherwise */ @Override @Nullable public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange); ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange); HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange); ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange); ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange); if (methods == null || params == null || headers == null || consumes == null || produces == null) { return null; } PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange); if (patterns == null) { return null; } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange); if (custom == null) { return null; } return new RequestMappingInfo(this.name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
@Test public void paramPresent() throws Exception { ParamsRequestCondition condition = new ParamsRequestCondition("foo"); assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=")))); }
@Test public void paramValueMatch() throws Exception { ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar"); assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar")))); }
@Test // SPR-15831 public void paramPresentNullValue() throws Exception { ParamsRequestCondition condition = new ParamsRequestCondition("foo"); assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo")))); }
@Test public void paramNotPresent() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(get("/")); assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange)); }
@Test public void paramPresentNoMatch() throws Exception { ParamsRequestCondition condition = new ParamsRequestCondition("foo"); assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar=")))); }
@Test public void paramValueNoMatch() throws Exception { ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar"); assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz")))); }
/** * @param info RequestMappingInfo that matches the URL path * @param exchange the current exchange */ public PartialMatch(RequestMappingInfo info, ServerWebExchange exchange) { this.info = info; this.methodsMatch = info.getMethodsCondition().getMatchingCondition(exchange) != null; this.consumesMatch = info.getConsumesCondition().getMatchingCondition(exchange) != null; this.producesMatch = info.getProducesCondition().getMatchingCondition(exchange) != null; this.paramsMatch = info.getParamsCondition().getMatchingCondition(exchange) != null; }
/** * Checks if all conditions in this request mapping info match the provided request and returns * a potentially new request mapping info with conditions tailored to the current request. * <p>For example the returned instance may contain the subset of URL patterns that match to * the current request, sorted with best matching patterns on top. * @return a new instance in case all conditions match; or {@code null} otherwise */ @Override public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange); ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange); HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange); ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange); ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange); if (methods == null || params == null || headers == null || consumes == null || produces == null) { return null; } PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange); if (patterns == null) { return null; } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange); if (custom == null) { return null; } return new RequestMappingInfo(this.name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }