diff --git a/pom.xml b/pom.xml
index dd0e3135..df11631b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,7 @@
2.0.0.BUILD-SNAPSHOT
1.2.0.BUILD-SNAPSHOT
1.3.0.BUILD-SNAPSHOT
+ 1.0.0.RELEASE
@@ -135,6 +136,21 @@
spring-boot-devtools
${spring-boot.version}
+
+ org.springframework
+ spring-tuple
+ ${spring-tuple.version}
+
+
+ org.springframework
+ spring-core
+
+
+ org.springframework
+ spring-context
+
+
+
diff --git a/spring-cloud-gateway-core/pom.xml b/spring-cloud-gateway-core/pom.xml
index 519e642e..39232497 100644
--- a/spring-cloud-gateway-core/pom.xml
+++ b/spring-cloud-gateway-core/pom.xml
@@ -18,6 +18,10 @@
+
+ org.springframework.boot
+ spring-boot-starter
+
org.springframework.boot
spring-boot-starter-actuator
@@ -54,6 +58,10 @@
spring-boot-devtools
true
+
+ org.springframework
+ spring-tuple
+
org.springframework.cloud
spring-cloud-starter-eureka
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java
index 69526c52..e0abc069 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteLocator.java
@@ -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 {
// 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
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java
index 868266ed..f2f5ee58 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RequestPredicateHandlerMapping.java
@@ -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;
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 {
throw new IllegalArgumentException("Unable to find RequestPredicateFactory with name " + predicate.getName());
}
if (logger.isDebugEnabled()) {
- List 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 entry : predicate.getArgs().entrySet()) {
+ builder.put(entry.getKey(), entry.getValue());
+ }
+
+ Tuple tuple = builder.build();
+ return found.apply(tuple);
}
/**
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactory.java
index a870664c..ea75dfce 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactory.java
+++ b/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;
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
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();
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactory.java
index f5cdf203..3057fe62 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactory.java
+++ b/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;
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
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();
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java
index e7affec1..a4a376b7 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactory.java
@@ -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;
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();
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java
index 397b3bc8..ca4b5683 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java
+++ b/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;
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;
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?
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRequestPredicateFactory.java
index 25558191..99a878aa 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRequestPredicateFactory.java
+++ b/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;
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;
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 values = headers.asHttpHeaders().get(header);
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java
index 4757df42..24542137 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRequestPredicateFactory.java
@@ -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 {
}
@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");
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java
index 51d20de1..9be5d35a 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRequestPredicateFactory.java
@@ -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;
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));
}
}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java
index ffb2e62d..e56130f0 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRequestPredicateFactory.java
@@ -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;
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);
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java
index a9b46003..ff3d2dc3 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java
@@ -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;
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 {
};
}
- String regexp = args[1];
+ String regexp = args.getString(1);
return RequestPredicates.queryParam(param, value -> value.matches(regexp));
}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java
index 493ec30f..28226a00 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java
@@ -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
private static final Log log = LogFactory.getLog(RemoteAddrRequestPredicateFactory.class);
@Override
- public RequestPredicate apply(String... args) {
+ public RequestPredicate apply(Tuple args) {
validate(1, args);
List sources = new ArrayList<>();
if (args != null) {
- for (String arg : args) {
- addSource(sources, arg);
+ for (Object arg : args.getValues()) {
+ addSource(sources, (String) arg);
}
}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java
index a3f72580..453b5682 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RequestPredicateFactory.java
@@ -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;
*/
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)");
}
}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java
index 4e9e69cf..9c95c4c2 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java
+++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/model/PredicateDefinition.java
@@ -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;
public class PredicateDefinition {
@NotNull
private String name;
- private String[] args;
+ private Map args = new LinkedHashMap<>();
public 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 {
this.name = name;
}
- public String[] getArgs() {
+ public Map getArgs() {
return args;
}
- public void setArgs(String... args) {
+ public void setArgs(Map args) {
this.args = args;
}
@@ -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 {
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();
}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java
index 07f2e6bb..102a9ced 100644
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java
+++ b/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
* @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(), "");
diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactoryTests.java
index 0ab273b4..94ce3a82 100644
--- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRequestPredicateFactoryTests.java
+++ b/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
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 {
}
private boolean runPredicate(String dateString) {
- return new AfterRequestPredicateFactory().apply(dateString).test(getRequest());
+ return new AfterRequestPredicateFactory().apply(tuple().of("1", dateString)).test(getRequest());
}
}
diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactoryTests.java
index 992b0c89..ac7109b1 100644
--- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRequestPredicateFactoryTests.java
+++ b/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
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 {
}
private boolean runPredicate(String dateString) {
- return new BeforeRequestPredicateFactory().apply(dateString).test(getRequest());
+ return new BeforeRequestPredicateFactory().apply(tuple().of("1", dateString)).test(getRequest());
}
}
diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactoryTests.java
index 0377fce4..f4a20256 100644
--- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRequestPredicateFactoryTests.java
+++ b/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;
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 {
}
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) {
diff --git a/spring-cloud-gateway-core/src/test/resources/application.yml b/spring-cloud-gateway-core/src/test/resources/application.yml
index 6e46b5dc..d23f0f0b 100644
--- a/spring-cloud-gateway-core/src/test/resources/application.yml
+++ b/spring-cloud-gateway-core/src/test/resources/application.yml
@@ -179,7 +179,8 @@ spring:
uri: ${test.uri}
predicates:
- name: Path
- args: /**
+ args:
+ path: /**
#myservice:
# ribbon: