@Override public int hashCode() { return (this.patternsCondition.hashCode() * 31 + // primary differentiation this.methodsCondition.hashCode() + this.paramsCondition.hashCode() + this.headersCondition.hashCode() + this.consumesCondition.hashCode() + this.producesCondition.hashCode() + this.customConditionHolder.hashCode()); }
/** * Get the matching condition for the held request condition wrap it in a * new RequestConditionHolder instance. Or otherwise if this is an empty * holder, return the same holder instance. */ @Override public RequestConditionHolder getMatchingCondition(ServerWebExchange exchange) { if (this.condition == null) { return this; } RequestCondition<?> match = (RequestCondition<?>) this.condition.getMatchingCondition(exchange); return (match != null ? new RequestConditionHolder(match) : null); }
public final boolean match(ServerWebExchange exchange) { boolean isMatch; if (this.value != null) { isMatch = matchValue(exchange); } else { isMatch = matchName(exchange); } return this.isNegated != isMatch; }
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns, @Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params, @Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes, @Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) { this.name = (StringUtils.hasText(name) ? name : null); this.patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition()); this.methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition()); this.paramsCondition = (params != null ? params : new ParamsRequestCondition()); this.headersCondition = (headers != null ? headers : new HeadersRequestCondition()); this.consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition()); this.producesCondition = (produces != null ? produces : new ProducesRequestCondition()); this.customConditionHolder = new RequestConditionHolder(custom); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof RequestMappingInfo)) { return false; } RequestMappingInfo otherInfo = (RequestMappingInfo) other; return (this.patternsCondition.equals(otherInfo.patternsCondition) && this.methodsCondition.equals(otherInfo.methodsCondition) && this.paramsCondition.equals(otherInfo.paramsCondition) && this.headersCondition.equals(otherInfo.headersCondition) && this.consumesCondition.equals(otherInfo.consumesCondition) && this.producesCondition.equals(otherInfo.producesCondition) && this.customConditionHolder.equals(otherInfo.customConditionHolder)); }
/** * 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(expected = ClassCastException.class) public void combineIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.combine(headers); }
@Test(expected = ClassCastException.class) public void compareIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.compareTo(headers, this.exchange); }
@Test public void getMatchingConditionWithHttpHead() throws Exception { testMatch(new RequestMethodsRequestCondition(HEAD), HEAD); testMatch(new RequestMethodsRequestCondition(GET), GET); testNoMatch(new RequestMethodsRequestCondition(POST), HEAD); }
@Test public void parseConsumesAndHeaders() throws Exception { String[] consumes = new String[] {"text/plain"}; String[] headers = new String[]{"foo=bar", "content-type=application/xml,application/pdf"}; ConsumesRequestCondition condition = new ConsumesRequestCondition(consumes, headers); assertConditions(condition, "text/plain", "application/xml", "application/pdf"); }
@Test public void instantiateWithProducesAndHeaderConditions() { String[] produces = new String[] {"text/plain"}; String[] headers = new String[]{"foo=bar", "accept=application/xml,application/pdf"}; ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers); assertConditions(condition, "text/plain", "application/xml", "application/pdf"); }
private RequestConditionHolder[] wrap(RequestCondition<?>... rawConditions) { RequestConditionHolder[] wrappedConditions = new RequestConditionHolder[rawConditions.length]; for (int i = 0; i < rawConditions.length; i++) { wrappedConditions[i] = new RequestConditionHolder(rawConditions[i]); } return wrappedConditions; }
/** * Return the underlying conditions, possibly empty but never {@code null}. */ public List<RequestCondition<?>> getConditions() { return unwrap(); }
/** * Create a new instance from the given param expressions. * @param params expressions with syntax defined in {@link RequestMapping#params()}; * if 0, the condition will match to every request. */ public ParamsRequestCondition(String... params) { this(parseExpressions(params)); }
/** * Creates a new instance with "consumes" and "header" expressions. * "Header" expressions where the header name is not 'Content-Type' or have * no header value defined are ignored. If 0 expressions are provided in * total, the condition will match to every request * @param consumes as described in {@link RequestMapping#consumes()} * @param headers as described in {@link RequestMapping#headers()} */ public ConsumesRequestCondition(String[] consumes, String[] headers) { this(parseExpressions(consumes, headers)); }
/** * Create a new instance with the given request methods. * @param requestMethods 0 or more HTTP request methods; * if, 0 the condition will match to every request */ public RequestMethodsRequestCondition(RequestMethod... requestMethods) { this(asList(requestMethods)); }
/** * Create a new instance from the given header expressions. Expressions with * header names 'Accept' or 'Content-Type' are ignored. See {@link ConsumesRequestCondition} * and {@link ProducesRequestCondition} for those. * @param headers media type expressions with syntax defined in {@link RequestMapping#headers()}; * if 0, the condition will match to every request */ public HeadersRequestCondition(String... headers) { this(parseExpressions(headers)); }
/** * Create an instance with 0 or more {@code RequestCondition} types. It is * important to create {@code CompositeRequestCondition} instances with the * same number of conditions so they may be compared and combined. * It is acceptable to provide {@code null} conditions. */ public CompositeRequestCondition(RequestCondition<?>... requestConditions) { this.requestConditions = wrap(requestConditions); }
public final boolean match(ServerWebExchange exchange) { try { boolean match = matchMediaType(exchange); return (!this.isNegated == match); } catch (NotAcceptableStatusException | UnsupportedMediaTypeStatusException ex) { return false; } }
@Test public void getMatchingCondition() throws Exception { testMatch(new RequestMethodsRequestCondition(GET), GET); testMatch(new RequestMethodsRequestCondition(GET, POST), GET); testNoMatch(new RequestMethodsRequestCondition(GET), POST); }