@Test public void getMatchingCondition() throws Exception { MockServerWebExchange exchange = postExchange("text/plain"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml"); ConsumesRequestCondition result = condition.getMatchingCondition(exchange); assertConditions(result, "text/plain"); condition = new ConsumesRequestCondition("application/xml"); result = condition.getMatchingCondition(exchange); assertNull(result); }
/** * 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; }
@Test public void consumesParseErrorWithNegation() throws Exception { MockServerWebExchange exchange = postExchange("01"); ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain"); assertNull(condition.getMatchingCondition(exchange)); }
/** * 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 consumesMatch() throws Exception { MockServerWebExchange exchange = postExchange("text/plain"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); assertNotNull(condition.getMatchingCondition(exchange)); }
@Test public void consumesMultipleMatch() throws Exception { MockServerWebExchange exchange = postExchange("text/plain"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml"); assertNotNull(condition.getMatchingCondition(exchange)); }
@Test public void consumesSingleNoMatch() throws Exception { MockServerWebExchange exchange = postExchange("application/xml"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); assertNull(condition.getMatchingCondition(exchange)); }
@Test public void consumesParseError() throws Exception { MockServerWebExchange exchange = postExchange("01"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); assertNull(condition.getMatchingCondition(exchange)); }
@Test public void negatedConsumesMatch() throws Exception { MockServerWebExchange exchange = postExchange("text/plain"); ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain"); assertNull(condition.getMatchingCondition(exchange)); }
@Test public void consumesWildcardMatch() throws Exception { MockServerWebExchange exchange = postExchange("text/plain"); ConsumesRequestCondition condition = new ConsumesRequestCondition("text/*"); assertNotNull(condition.getMatchingCondition(exchange)); }
/** * @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()); }