Browse Source

RequestPredicateFactory args use Tuple

Rather than String[]. Still indexed though.
pull/41/head
Spencer Gibb 8 years ago
parent
commit
bcd76d82a5
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 16
      pom.xml
  2. 8
      spring-cloud-gateway-core/pom.xml
  3. 3
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java
  4. 28
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java
  5. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactory.java
  6. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactory.java
  7. 10
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java
  8. 7
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java
  9. 7
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRequestPredicateFactory.java
  10. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java
  11. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java
  12. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java
  13. 9
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java
  14. 7
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java
  15. 8
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java
  16. 20
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java
  17. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java
  18. 3
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactoryTests.java
  19. 3
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactoryTests.java
  20. 3
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactoryTests.java
  21. 3
      spring-cloud-gateway-core/src/test/resources/application.yml

16
pom.xml

@ -52,6 +52,7 @@ @@ -52,6 +52,7 @@
<spring-boot.version>2.0.0.BUILD-SNAPSHOT</spring-boot.version>
<spring-cloud-commons.version>1.2.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-netflix.version>1.3.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-tuple.version>1.0.0.RELEASE</spring-tuple.version>
</properties>
<dependencyManagement>
@ -135,6 +136,21 @@ @@ -135,6 +136,21 @@
<artifactId>spring-boot-devtools</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tuple</artifactId>
<version>${spring-tuple.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

8
spring-cloud-gateway-core/pom.xml

@ -18,6 +18,10 @@ @@ -18,6 +18,10 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
@ -54,6 +58,10 @@ @@ -54,6 +58,10 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tuple</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>

3
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
package org.springframework.cloud.gateway.discovery;
import java.net.URI;
import java.util.Collections;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.gateway.api.RouteLocator;
@ -57,7 +58,7 @@ public class DiscoveryClientRouteLocator implements RouteLocator { @@ -57,7 +58,7 @@ public class DiscoveryClientRouteLocator implements RouteLocator {
// add a predicate that matches the url at /serviceId/**
PredicateDefinition predicate = new PredicateDefinition();
predicate.setName(normalizePredicateName(PathRequestPredicateFactory.class));
predicate.setArgs("/" + serviceId + "/**");
predicate.setArgs(Collections.singletonMap("path", "/" + serviceId + "/**"));
route.getPredicates().add(predicate);
//TODO: support for other default predicates

28
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java

@ -17,8 +17,6 @@ @@ -17,8 +17,6 @@
package org.springframework.cloud.gateway.handler;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -27,19 +25,21 @@ import java.util.function.Function; @@ -27,19 +25,21 @@ import java.util.function.Function;
import org.springframework.cloud.gateway.api.RouteLocator;
import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory;
import org.springframework.cloud.gateway.model.Route;
import org.springframework.cloud.gateway.model.PredicateDefinition;
import org.springframework.cloud.gateway.model.Route;
import org.springframework.tuple.Tuple;
import org.springframework.tuple.TupleBuilder;
import org.springframework.web.reactive.function.server.PublicDefaultServerRequest;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler;
import reactor.core.publisher.Mono;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_HANDLER_MAPPER_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
import reactor.core.publisher.Mono;
/**
* @author Spencer Gibb
*/
@ -165,16 +165,18 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping { @@ -165,16 +165,18 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
throw new IllegalArgumentException("Unable to find RequestPredicateFactory with name " + predicate.getName());
}
if (logger.isDebugEnabled()) {
List<String> args;
if (predicate.getArgs() != null) {
args = Arrays.asList(predicate.getArgs());
} else {
args = Collections.emptyList();
}
logger.debug("Route " + route.getId() + " applying "
+ args + " to " + predicate.getName());
+ predicate.getArgs() + " to " + predicate.getName());
}
return found.apply(predicate.getArgs());
TupleBuilder builder = TupleBuilder.tuple();
for (Map.Entry<String, String> entry : predicate.getArgs().entrySet()) {
builder.put(entry.getKey(), entry.getValue());
}
Tuple tuple = builder.build();
return found.apply(tuple);
}
/**

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactory.java

@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; @@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.time.ZonedDateTime;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactory.parseZonedDateTime;
@ -29,9 +30,9 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest @@ -29,9 +30,9 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest
public class AfterRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
final ZonedDateTime dateTime = parseZonedDateTime(args[0]);
final ZonedDateTime dateTime = parseZonedDateTime(args.getString(0));
return request -> {
final ZonedDateTime now = ZonedDateTime.now();

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactory.java

@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; @@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.time.ZonedDateTime;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactory.parseZonedDateTime;
@ -29,9 +30,9 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest @@ -29,9 +30,9 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest
public class BeforeRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
final ZonedDateTime dateTime = parseZonedDateTime(args[0]);
final ZonedDateTime dateTime = parseZonedDateTime(args.getString(0));
return request -> {
final ZonedDateTime now = ZonedDateTime.now();

10
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java

@ -21,6 +21,7 @@ import java.time.Instant; @@ -21,6 +21,7 @@ import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import org.springframework.tuple.Tuple;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.server.RequestPredicate;
@ -30,13 +31,14 @@ import org.springframework.web.reactive.function.server.RequestPredicate; @@ -30,13 +31,14 @@ import org.springframework.web.reactive.function.server.RequestPredicate;
public class BetweenRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(2, args);
//TODO: is ZonedDateTime the right thing to use?
final ZonedDateTime dateTime1 = parseZonedDateTime(args[0]);
final ZonedDateTime dateTime2 = parseZonedDateTime(args[1]);
Assert.isTrue(dateTime1.isBefore(dateTime2), args[0] + " must be before " + args[1]);
final ZonedDateTime dateTime1 = parseZonedDateTime(args.getString(0));
final ZonedDateTime dateTime2 = parseZonedDateTime(args.getString(1));
Assert.isTrue(dateTime1.isBefore(dateTime2), args.getString(0) +
" must be before " + args.getString(1));
return request -> {
final ZonedDateTime now = ZonedDateTime.now();

7
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java

@ -20,6 +20,7 @@ package org.springframework.cloud.gateway.handler.predicate; @@ -20,6 +20,7 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.util.List;
import org.springframework.http.HttpCookie;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.PublicDefaultServerRequest;
import org.springframework.web.reactive.function.server.RequestPredicate;
@ -29,10 +30,10 @@ import org.springframework.web.reactive.function.server.RequestPredicate; @@ -29,10 +30,10 @@ import org.springframework.web.reactive.function.server.RequestPredicate;
public class CookieRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(2, args);
String name = args[0];
String regexp = args[1];
String name = args.getString(0);
String regexp = args.getString(1);
return request -> {
//TODO: bad cast?

7
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRequestPredicateFactory.java

@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; @@ -19,6 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.util.List;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -28,10 +29,10 @@ import org.springframework.web.reactive.function.server.RequestPredicates; @@ -28,10 +29,10 @@ import org.springframework.web.reactive.function.server.RequestPredicates;
public class HeaderRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(2, args);
String header = args[0];
String regexp = args[1];
String header = args.getString(0);
String regexp = args.getString(1);
return RequestPredicates.headers(headers -> {
List<String> values = headers.asHttpHeaders().get(header);

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.tuple.Tuple;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.reactive.function.server.RequestPredicate;
@ -34,9 +35,9 @@ public class HostRequestPredicateFactory implements RequestPredicateFactory { @@ -34,9 +35,9 @@ public class HostRequestPredicateFactory implements RequestPredicateFactory {
}
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
String pattern = args[0];
String pattern = args.getString(0);
return RequestPredicates.headers(headers -> {
String host = headers.asHttpHeaders().getFirst("Host");

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.http.HttpMethod;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -27,9 +28,9 @@ import org.springframework.web.reactive.function.server.RequestPredicates; @@ -27,9 +28,9 @@ import org.springframework.web.reactive.function.server.RequestPredicates;
public class MethodRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
String method = args[0];
String method = args.getString(0);
return RequestPredicates.method(HttpMethod.resolve(method));
}
}

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -26,9 +27,9 @@ import org.springframework.web.reactive.function.server.RequestPredicates; @@ -26,9 +27,9 @@ import org.springframework.web.reactive.function.server.RequestPredicates;
public class PathRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
String pattern = args[0];
String pattern = args.getString(0);
//TODO: support custom PathPatternParser
return RequestPredicates.path(pattern);

9
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.PublicDefaultServerRequest;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -27,11 +28,11 @@ import org.springframework.web.reactive.function.server.RequestPredicates; @@ -27,11 +28,11 @@ import org.springframework.web.reactive.function.server.RequestPredicates;
public class QueryRequestPredicateFactory implements RequestPredicateFactory {
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
String param = args[0];
String param = args.getString(0);
if (args.length < 2) {
if (args.size() < 2) {
return req -> {
//TODO: ServerRequest support for query params with no value
PublicDefaultServerRequest request = (PublicDefaultServerRequest) req;
@ -39,7 +40,7 @@ public class QueryRequestPredicateFactory implements RequestPredicateFactory { @@ -39,7 +40,7 @@ public class QueryRequestPredicateFactory implements RequestPredicateFactory {
};
}
String regexp = args[1];
String regexp = args.getString(1);
return RequestPredicates.queryParam(param, value -> value.matches(regexp));
}

7
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java

@ -25,6 +25,7 @@ import java.util.Optional; @@ -25,6 +25,7 @@ import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.gateway.support.SubnetUtils;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.PublicDefaultServerRequest;
import org.springframework.web.reactive.function.server.RequestPredicate;
@ -36,13 +37,13 @@ public class RemoteAddrRequestPredicateFactory implements RequestPredicateFactor @@ -36,13 +37,13 @@ public class RemoteAddrRequestPredicateFactory implements RequestPredicateFactor
private static final Log log = LogFactory.getLog(RemoteAddrRequestPredicateFactory.class);
@Override
public RequestPredicate apply(String... args) {
public RequestPredicate apply(Tuple args) {
validate(1, args);
List<SubnetUtils> sources = new ArrayList<>();
if (args != null) {
for (String arg : args) {
addSource(sources, arg);
for (Object arg : args.getValues()) {
addSource(sources, (String) arg);
}
}

8
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.tuple.Tuple;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.server.RequestPredicate;
@ -25,11 +26,10 @@ import org.springframework.web.reactive.function.server.RequestPredicate; @@ -25,11 +26,10 @@ import org.springframework.web.reactive.function.server.RequestPredicate;
*/
public interface RequestPredicateFactory {
//TODO: use tuple instead of String array
RequestPredicate apply(String... args);
RequestPredicate apply(Tuple args);
default void validate(int minimumSize, String... args) {
Assert.isTrue(args != null && args.length >= minimumSize,
default void validate(int minimumSize, Tuple args) {
Assert.isTrue(args != null && args.size() >= minimumSize,
"args must have at least "+ minimumSize +" entry(s)");
}
}

20
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java

@ -17,12 +17,15 @@ @@ -17,12 +17,15 @@
package org.springframework.cloud.gateway.model;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import javax.validation.ValidationException;
import javax.validation.constraints.NotNull;
import org.springframework.cloud.gateway.support.NameUtils;
import static org.springframework.util.StringUtils.tokenizeToStringArray;
/**
@ -31,7 +34,7 @@ import static org.springframework.util.StringUtils.tokenizeToStringArray; @@ -31,7 +34,7 @@ import static org.springframework.util.StringUtils.tokenizeToStringArray;
public class PredicateDefinition {
@NotNull
private String name;
private String[] args;
private Map<String, String> args = new LinkedHashMap<>();
public PredicateDefinition() {
}
@ -45,7 +48,10 @@ public class PredicateDefinition { @@ -45,7 +48,10 @@ public class PredicateDefinition {
setName(text.substring(0, eqIdx));
String[] args = tokenizeToStringArray(text.substring(eqIdx+1), ",");
setArgs(args);
for (int i=0; i < args.length; i++) {
this.args.put(NameUtils.generateName(i), args[i]);
}
}
public String getName() {
@ -56,11 +62,11 @@ public class PredicateDefinition { @@ -56,11 +62,11 @@ public class PredicateDefinition {
this.name = name;
}
public String[] getArgs() {
public Map<String, String> getArgs() {
return args;
}
public void setArgs(String... args) {
public void setArgs(Map<String, String> args) {
this.args = args;
}
@ -70,7 +76,7 @@ public class PredicateDefinition { @@ -70,7 +76,7 @@ public class PredicateDefinition {
if (o == null || getClass() != o.getClass()) return false;
PredicateDefinition that = (PredicateDefinition) o;
return Objects.equals(name, that.name) &&
Arrays.equals(args, that.args);
Objects.equals(args, that.args);
}
@Override
@ -82,7 +88,7 @@ public class PredicateDefinition { @@ -82,7 +88,7 @@ public class PredicateDefinition {
public String toString() {
final StringBuilder sb = new StringBuilder("PredicateDefinition{");
sb.append("name='").append(name).append('\'');
sb.append(", args=").append(Arrays.toString(args));
sb.append(", args=").append(args);
sb.append('}');
return sb.toString();
}

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java

@ -24,6 +24,11 @@ import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFacto @@ -24,6 +24,11 @@ import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFacto
* @author Spencer Gibb
*/
public class NameUtils {
public static final String GENERATED_NAME_PREFIX = "__:_._gen__+_";
public static String generateName(int i) {
return GENERATED_NAME_PREFIX + i;
}
public static String normalizePredicateName(Class<? extends RequestPredicateFactory> clazz) {
return clazz.getSimpleName().replace(RequestPredicateFactory.class.getSimpleName(), "");

3
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactoryTests.java

@ -25,6 +25,7 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest @@ -25,6 +25,7 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.minusHoursMillis;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.plusHours;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.plusHoursMillis;
import static org.springframework.tuple.TupleBuilder.tuple;
/**
* @author Spencer Gibb
@ -68,6 +69,6 @@ public class AfterRequestPredicateFactoryTests { @@ -68,6 +69,6 @@ public class AfterRequestPredicateFactoryTests {
}
private boolean runPredicate(String dateString) {
return new AfterRequestPredicateFactory().apply(dateString).test(getRequest());
return new AfterRequestPredicateFactory().apply(tuple().of("1", dateString)).test(getRequest());
}
}

3
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactoryTests.java

@ -25,6 +25,7 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest @@ -25,6 +25,7 @@ import static org.springframework.cloud.gateway.handler.predicate.BetweenRequest
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.minusHoursMillis;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.plusHours;
import static org.springframework.cloud.gateway.handler.predicate.BetweenRequestPredicateFactoryTests.plusHoursMillis;
import static org.springframework.tuple.TupleBuilder.tuple;
/**
* @author Spencer Gibb
@ -68,6 +69,6 @@ public class BeforeRequestPredicateFactoryTests { @@ -68,6 +69,6 @@ public class BeforeRequestPredicateFactoryTests {
}
private boolean runPredicate(String dateString) {
return new BeforeRequestPredicateFactory().apply(dateString).test(getRequest());
return new BeforeRequestPredicateFactory().apply(tuple().of("1", dateString)).test(getRequest());
}
}

3
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactoryTests.java

@ -28,6 +28,7 @@ import org.springframework.web.reactive.function.server.ServerRequest; @@ -28,6 +28,7 @@ import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tuple.TupleBuilder.tuple;
/**
* @author Spencer Gibb
@ -95,7 +96,7 @@ public class BetweenRequestPredicateFactoryTests { @@ -95,7 +96,7 @@ public class BetweenRequestPredicateFactoryTests {
}
boolean runPredicate(String dateString1, String dateString2) {
return new BetweenRequestPredicateFactory().apply(dateString1, dateString2).test(getRequest());
return new BetweenRequestPredicateFactory().apply(tuple().of("1", dateString1, "2", dateString2)).test(getRequest());
}
static String minusHoursMillis(int hours) {

3
spring-cloud-gateway-core/src/test/resources/application.yml

@ -179,7 +179,8 @@ spring: @@ -179,7 +179,8 @@ spring:
uri: ${test.uri}
predicates:
- name: Path
args: /**
args:
path: /**
#myservice:
# ribbon:

Loading…
Cancel
Save