empty().log("noroute"))
- .next()
- //TODO: error handling
- .map(route -> {
- if (logger.isDebugEnabled()) {
- logger.debug("RouteDefinition matched: " + route.getId());
- }
- validateRoute(route, exchange);
- return route;
- });
-
- /* TODO: trace logging
- if (logger.isTraceEnabled()) {
- logger.trace("RouteDefinition did not match: " + routeDefinition.getId());
- }*/
- }
-
- /**
- * Validate the given handler against the current request.
- * The default implementation is empty. Can be overridden in subclasses,
- * for example to enforce specific preconditions expressed in URL mappings.
- * @param route the Route object to validate
- * @param exchange current exchange
- * @throws Exception if validation failed
- */
- @SuppressWarnings("UnusedParameters")
- protected void validateRoute(Route route, ServerWebExchange exchange) {
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactory.java
deleted file mode 100644
index 091eabee..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.time.ZonedDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-import static org.springframework.cloud.gateway.handler.predicate.BetweenRoutePredicateFactory.parseZonedDateTime;
-
-/**
- * @author Spencer Gibb
- */
-public class AfterRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String DATETIME_KEY = "datetime";
-
- @Override
- public List argNames() {
- return Collections.singletonList(DATETIME_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- final ZonedDateTime dateTime = parseZonedDateTime(args.getString(DATETIME_KEY));
-
- return exchange -> {
- final ZonedDateTime now = ZonedDateTime.now();
- return now.isAfter(dateTime);
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactory.java
deleted file mode 100644
index a8345383..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.time.ZonedDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-import static org.springframework.cloud.gateway.handler.predicate.BetweenRoutePredicateFactory.parseZonedDateTime;
-
-/**
- * @author Spencer Gibb
- */
-public class BeforeRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String DATETIME_KEY = "datetime";
-
- @Override
- public List argNames() {
- return Collections.singletonList(DATETIME_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- final ZonedDateTime dateTime = parseZonedDateTime(args.getString(DATETIME_KEY));
-
- return exchange -> {
- final ZonedDateTime now = ZonedDateTime.now();
- return now.isBefore(dateTime);
- };
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactory.java
deleted file mode 100644
index 7aaa1b26..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactory.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.util.Assert;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class BetweenRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String DATETIME1_KEY = "datetime1";
- public static final String DATETIME2_KEY = "datetime2";
-
- @Override
- public Predicate apply(Tuple args) {
- //TODO: is ZonedDateTime the right thing to use?
- final ZonedDateTime dateTime1 = parseZonedDateTime(args.getString(DATETIME1_KEY));
- final ZonedDateTime dateTime2 = parseZonedDateTime(args.getString(DATETIME2_KEY));
- Assert.isTrue(dateTime1.isBefore(dateTime2), args.getString(DATETIME1_KEY) +
- " must be before " + args.getString(DATETIME2_KEY));
-
- return exchange -> {
- final ZonedDateTime now = ZonedDateTime.now();
- return now.isAfter(dateTime1) && now.isBefore(dateTime2);
- };
- }
-
- public static ZonedDateTime parseZonedDateTime(String dateString) {
- ZonedDateTime dateTime;
- try {
- long epoch = Long.parseLong(dateString);
-
- dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0))
- .toZonedDateTime();
- } catch (NumberFormatException e) {
- // try ZonedDateTime instead
- dateTime = ZonedDateTime.parse(dateString);
- }
-
- return dateTime;
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactory.java
deleted file mode 100644
index e6b63d4b..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.http.HttpCookie;
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class CookieRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String NAME_KEY = "name";
- public static final String REGEXP_KEY = "regexp";
-
- @Override
- public List argNames() {
- return Arrays.asList(NAME_KEY, REGEXP_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- String name = args.getString(NAME_KEY);
- String regexp = args.getString(REGEXP_KEY);
-
- return exchange -> {
- List cookies = exchange.getRequest().getCookies().get(name);
- for (HttpCookie cookie : cookies) {
- if (cookie.getValue().matches(regexp)) {
- return true;
- }
- }
- return false;
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactory.java
deleted file mode 100644
index 44fc4574..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactory.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class HeaderRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String HEADER_KEY = "header";
- public static final String REGEXP_KEY = "regexp";
-
- @Override
- public List argNames() {
- return Arrays.asList(HEADER_KEY, REGEXP_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- String header = args.getString(HEADER_KEY);
- String regexp = args.getString(REGEXP_KEY);
-
- return exchange -> {
- List values = exchange.getRequest().getHeaders().get(header);
- for (String value : values) {
- if (value.matches(regexp)) {
- return true;
- }
- }
- return false;
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactory.java
deleted file mode 100644
index e77a0df6..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactory.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.util.AntPathMatcher;
-import org.springframework.util.PathMatcher;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class HostRoutePredicateFactory implements RoutePredicateFactory {
-
- private PathMatcher pathMatcher = new AntPathMatcher(".");
-
- public void setPathMatcher(PathMatcher pathMatcher) {
- this.pathMatcher = pathMatcher;
- }
-
- @Override
- public List argNames() {
- return Collections.singletonList(PATTERN_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- String pattern = args.getString(PATTERN_KEY);
-
- return exchange -> {
- String host = exchange.getRequest().getHeaders().getFirst("Host");
- return this.pathMatcher.match(pattern, host);
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactory.java
deleted file mode 100644
index 116d645e..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.http.HttpMethod;
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class MethodRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String METHOD_KEY = "method";
-
- @Override
- public List argNames() {
- return Arrays.asList(METHOD_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- String method = args.getString(METHOD_KEY);
- return exchange -> {
- HttpMethod requestMethod = exchange.getRequest().getMethod();
- return requestMethod.matches(method);
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactory.java
deleted file mode 100644
index be0e45e1..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactory.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.util.pattern.PathPattern;
-import org.springframework.web.util.pattern.PathPatternParser;
-
-import static org.springframework.cloud.gateway.handler.support.RoutePredicateFactoryUtils.traceMatch;
-import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
-
-/**
- * @author Spencer Gibb
- */
-public class PathRoutePredicateFactory implements RoutePredicateFactory {
-
- private PathPatternParser pathPatternParser = new PathPatternParser();
-
- public void setPathPatternParser(PathPatternParser pathPatternParser) {
- this.pathPatternParser = pathPatternParser;
- }
-
- @Override
- public List argNames() {
- return Collections.singletonList(PATTERN_KEY);
- }
-
- @Override
- public Predicate apply(Tuple args) {
- String unparsedPattern = args.getString(PATTERN_KEY);
- PathPattern pattern;
- synchronized (this.pathPatternParser) {
- pattern = this.pathPatternParser.parse(unparsedPattern);
- }
-
- return exchange -> {
- String path = exchange.getRequest().getURI().getPath();
- boolean match = pattern.matches(path);
- traceMatch("Pattern", pattern.getPatternString(), path, match);
- if (match) {
- Map uriTemplateVariables = pattern.matchAndExtract(path);
- exchange.getAttributes().put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
- return true;
- }
- else {
- return false;
- }
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PredicateDefinition.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PredicateDefinition.java
deleted file mode 100644
index f202b9d4..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/PredicateDefinition.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-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 org.springframework.validation.annotation.Validated;
-
-import static org.springframework.util.StringUtils.tokenizeToStringArray;
-
-/**
- * @author Spencer Gibb
- */
-@Validated
-public class PredicateDefinition {
- @NotNull
- private String name;
- private Map args = new LinkedHashMap<>();
-
- public PredicateDefinition() {
- }
-
- public PredicateDefinition(String text) {
- int eqIdx = text.indexOf("=");
- if (eqIdx <= 0) {
- throw new ValidationException("Unable to parse PredicateDefinition text '" + text + "'" +
- ", must be of the form name=value");
- }
- setName(text.substring(0, eqIdx));
-
- String[] args = tokenizeToStringArray(text.substring(eqIdx+1), ",");
-
- for (int i=0; i < args.length; i++) {
- this.args.put(NameUtils.generateName(i), args[i]);
- }
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Map getArgs() {
- return args;
- }
-
- public void setArgs(Map args) {
- this.args = args;
- }
-
- public void addArg(String key, String value) {
- this.args.put(key, value);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- PredicateDefinition that = (PredicateDefinition) o;
- return Objects.equals(name, that.name) &&
- Objects.equals(args, that.args);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, args);
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("PredicateDefinition{");
- sb.append("name='").append(name).append('\'');
- sb.append(", args=").append(args);
- sb.append('}');
- return sb.toString();
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactory.java
deleted file mode 100644
index adb86ab8..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactory.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class QueryRoutePredicateFactory implements RoutePredicateFactory {
-
- public static final String PARAM_KEY = "param";
- public static final String REGEXP_KEY = "regexp";
-
- @Override
- public List argNames() {
- return Arrays.asList(PARAM_KEY, REGEXP_KEY);
- }
-
- @Override
- public boolean validateArgs() {
- return false;
- }
-
- @Override
- public Predicate apply(Tuple args) {
- validateMin(1, args);
- String param = args.getString(PARAM_KEY);
-
- return exchange -> {
- if (!args.hasFieldName(REGEXP_KEY)) {
- // check existence of header
- return exchange.getRequest().getQueryParams().containsKey(param);
- }
-
- String regexp = args.getString(REGEXP_KEY);
-
- List values = exchange.getRequest().getQueryParams().get(param);
- for (String value : values) {
- if (value.matches(regexp)) {
- return true;
- }
- }
- return false;
- };
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactory.java
deleted file mode 100644
index 591f8288..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactory.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Predicate;
-
-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.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class RemoteAddrRoutePredicateFactory implements RoutePredicateFactory {
-
- private static final Log log = LogFactory.getLog(RemoteAddrRoutePredicateFactory.class);
-
- @Override
- public Predicate apply(Tuple args) {
- validate(1, args);
-
- List sources = new ArrayList<>();
- if (args != null) {
- for (Object arg : args.getValues()) {
- addSource(sources, (String) arg);
- }
- }
-
- return exchange -> {
- InetSocketAddress remoteAddress = exchange.getRequest().getRemoteAddress();
- if (remoteAddress != null) {
- String hostAddress = remoteAddress.getAddress().getHostAddress();
- String host = exchange.getRequest().getURI().getHost();
-
- if (!hostAddress.equals(host)) {
- log.warn("Remote addresses didn't match " + hostAddress + " != " + host);
- }
-
- for (SubnetUtils source : sources) {
- if (source.getInfo().isInRange(hostAddress)) {
- return true;
- }
- }
- }
-
- return false;
- };
- }
-
- private void addSource(List sources, String source) {
- boolean inclusiveHostCount = false;
- if (!source.contains("/")) { // no netmask, add default
- source = source + "/32";
- }
- if (source.endsWith("/32")) {
- //http://stackoverflow.com/questions/2942299/converting-cidr-address-to-subnet-mask-and-network-address#answer-6858429
- inclusiveHostCount = true;
- }
- //TODO: howto support ipv6 as well?
- SubnetUtils subnetUtils = new SubnetUtils(source);
- subnetUtils.setInclusiveHostCount(inclusiveHostCount);
- sources.add(subnetUtils);
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicateFactory.java
deleted file mode 100644
index 7fc39888..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicateFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import java.util.function.Predicate;
-
-import org.springframework.cloud.gateway.support.ArgumentHints;
-import org.springframework.cloud.gateway.support.NameUtils;
-import org.springframework.tuple.Tuple;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-@FunctionalInterface
-public interface RoutePredicateFactory extends ArgumentHints {
- String PATTERN_KEY = "pattern";
-
- Predicate apply(Tuple args);
-
- default String name() {
- return NameUtils.normalizePredicateName(getClass());
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicates.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicates.java
deleted file mode 100644
index 8622a172..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicates.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.predicate;
-
-import org.springframework.web.server.ServerWebExchange;
-
-import java.util.function.Predicate;
-
-import static org.springframework.cloud.gateway.handler.predicate.MethodRoutePredicateFactory.METHOD_KEY;
-import static org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory.PATTERN_KEY;
-import static org.springframework.tuple.TupleBuilder.tuple;
-
-/**
- * @author Spencer Gibb
- */
-public class RoutePredicates {
-
- //TODO: add support for AfterRoutePredicateFactory
-
- //TODO: add support for BeforeRoutePredicateFactory
-
- //TODO: add support for BetweenRoutePredicateFactory
-
- //TODO: add support for CookieRoutePredicateFactory
-
- //TODO: add support for RoutePredicates
-
- //TODO: add support for HeaderRoutePredicateFactory
-
- public static Predicate host(String pattern) {
- return new HostRoutePredicateFactory().apply(tuple().of(PATTERN_KEY, pattern));
- }
-
- public static Predicate method(String method) {
- return new MethodRoutePredicateFactory().apply(tuple().of(METHOD_KEY, method));
- }
-
- public static Predicate path(String pattern) {
- return new PathRoutePredicateFactory().apply(tuple().of(PATTERN_KEY, pattern));
- }
-
- //TODO: add support for PredicateDefinition
-
- //TODO: add support for QueryRoutePredicateFactory
-
- //TODO: add support for RemoteAddrRoutePredicateFactory
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/support/RoutePredicateFactoryUtils.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/support/RoutePredicateFactoryUtils.java
deleted file mode 100644
index a63dc0db..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/support/RoutePredicateFactoryUtils.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.handler.support;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory;
-
-/**
- * @author Spencer Gibb
- */
-public class RoutePredicateFactoryUtils {
- private static final Log logger = LogFactory.getLog(RoutePredicateFactory.class);
-
- public static void traceMatch(String prefix, Object desired, Object actual, boolean match) {
- if (logger.isTraceEnabled()) {
- String message = String.format("%s \"%s\" %s against value \"%s\"",
- prefix, desired, match ? "matches" : "does not match", actual);
- logger.trace(message);
- }
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java
deleted file mode 100644
index dcbfcb27..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.springframework.context.event.EventListener;
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public class CachingRouteDefinitionLocator implements RouteDefinitionLocator {
-
- private final RouteDefinitionLocator delegate;
- private final AtomicReference> cachedRoutes = new AtomicReference<>();
-
- public CachingRouteDefinitionLocator(RouteDefinitionLocator delegate) {
- this.delegate = delegate;
- this.cachedRoutes.compareAndSet(null, collectRoutes());
- }
-
- @Override
- public Flux getRouteDefinitions() {
- return Flux.fromIterable(this.cachedRoutes.get());
- }
-
- /**
- * Sets the new routes
- * @return old routes
- */
- public Flux refresh() {
- return Flux.fromIterable(this.cachedRoutes.getAndUpdate(
- routes -> CachingRouteDefinitionLocator.this.collectRoutes()));
- }
-
- private List collectRoutes() {
- return this.delegate.getRouteDefinitions().collectList().block();
- }
-
- @EventListener(RefreshRoutesEvent.class)
- /* for testing */ void handleRefresh() {
- refresh();
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java
deleted file mode 100644
index 1d69cb25..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.springframework.context.event.EventListener;
-import org.springframework.core.annotation.AnnotationAwareOrderComparator;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public class CachingRouteLocator implements RouteLocator {
-
- private final RouteLocator delegate;
- private final AtomicReference> cachedRoutes = new AtomicReference<>();
-
- public CachingRouteLocator(RouteLocator delegate) {
- this.delegate = delegate;
- this.cachedRoutes.compareAndSet(null, collectRoutes());
- }
-
- @Override
- public Flux getRoutes() {
- return Flux.fromIterable(this.cachedRoutes.get());
- }
-
- /**
- * Sets the new routes
- * @return old routes
- */
- public Flux refresh() {
- return Flux.fromIterable(this.cachedRoutes.getAndUpdate(
- routes -> CachingRouteLocator.this.collectRoutes()));
- }
-
- private List collectRoutes() {
- List routes = this.delegate.getRoutes().collectList().block();
- AnnotationAwareOrderComparator.sort(routes);
- return routes;
- }
-
- @EventListener(RefreshRoutesEvent.class)
- /* for testing */ void handleRefresh() {
- refresh();
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java
deleted file mode 100644
index aefc17f4..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public class CompositeRouteDefinitionLocator implements RouteDefinitionLocator {
-
- private final Flux delegates;
-
- public CompositeRouteDefinitionLocator(Flux delegates) {
- this.delegates = delegates;
- }
-
- @Override
- public Flux getRouteDefinitions() {
- return this.delegates.flatMap(RouteDefinitionLocator::getRouteDefinitions);
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java
deleted file mode 100644
index c7aef785..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public class CompositeRouteLocator implements RouteLocator {
-
- private final Flux delegates;
-
- public CompositeRouteLocator(Flux delegates) {
- this.delegates = delegates;
- }
-
- @Override
- public Flux getRoutes() {
- return this.delegates.flatMap(RouteLocator::getRoutes);
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/InMemoryRouteDefinitionRepository.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/InMemoryRouteDefinitionRepository.java
deleted file mode 100644
index 8cb5c87d..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/InMemoryRouteDefinitionRepository.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.springframework.cloud.gateway.support.NotFoundException;
-
-import static java.util.Collections.synchronizedMap;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-/**
- * @author Spencer Gibb
- */
-public class InMemoryRouteDefinitionRepository implements RouteDefinitionRepository {
-
- private final Map routes = synchronizedMap(new LinkedHashMap());
-
- @Override
- public Mono save(Mono route) {
- return route.flatMap( r -> {
- routes.put(r.getId(), r);
- return Mono.empty();
- });
- }
-
- @Override
- public Mono delete(Mono routeId) {
- return routeId.flatMap(id -> {
- if (routes.containsKey(id)) {
- routes.remove(id);
- return Mono.empty();
- }
- return Mono.error(new NotFoundException("RouteDefinition not found: "+routeId));
- });
- }
-
- @Override
- public Flux getRouteDefinitions() {
- return Flux.fromIterable(routes.values());
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RefreshRoutesEvent.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RefreshRoutesEvent.java
deleted file mode 100644
index 1827f284..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RefreshRoutesEvent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import org.springframework.context.ApplicationEvent;
-
-/**
- * @author Spencer Gibb
- */
-public class RefreshRoutesEvent extends ApplicationEvent {
-
- /**
- * Create a new ApplicationEvent.
- *
- * @param source the object on which the event initially occurred (never {@code null})
- */
- public RefreshRoutesEvent(Object source) {
- super(source);
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Route.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Route.java
deleted file mode 100644
index e0c3fc32..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Route.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.function.Predicate;
-
-import org.springframework.core.Ordered;
-import org.springframework.util.Assert;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-
-/**
- * @author Spencer Gibb
- */
-public class Route implements Ordered {
-
- private final String id;
-
- private final URI uri;
-
- private final int order;
-
- private final Predicate predicate;
-
- private final List webFilters;
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static Builder builder(RouteDefinition routeDefinition) {
- return new Builder()
- .id(routeDefinition.getId())
- .uri(routeDefinition.getUri())
- .order(routeDefinition.getOrder());
- }
-
- public Route(String id, URI uri, int order, Predicate predicate, List webFilters) {
- this.id = id;
- this.uri = uri;
- this.order = order;
- this.predicate = predicate;
- this.webFilters = webFilters;
- }
-
- public static class Builder {
- private String id;
-
- private URI uri;
-
- private int order = 0;
-
- private Predicate predicate;
-
- private List webFilters = new ArrayList<>();
-
- private Builder() {}
-
- public Builder id(String id) {
- this.id = id;
- return this;
- }
-
- public Builder uri(String uri) {
- this.uri = URI.create(uri);
- return this;
- }
-
- public Builder order(int order) {
- this.order = order;
- return this;
- }
-
- public Builder uri(URI uri) {
- this.uri = uri;
- return this;
- }
-
- public Builder predicate(Predicate predicate) {
- this.predicate = predicate;
- return this;
- }
-
- public Builder webFilters(List webFilters) {
- this.webFilters = webFilters;
- return this;
- }
-
- public Builder add(WebFilter webFilter) {
- this.webFilters.add(webFilter);
- return this;
- }
-
- public Builder addAll(Collection webFilters) {
- this.webFilters.addAll(webFilters);
- return this;
- }
-
- public Route build() {
- Assert.notNull(this.id, "id can not be null");
- Assert.notNull(this.uri, "uri can not be null");
- //TODO: Assert.notNull(this.predicate, "predicate can not be null");
-
- return new Route(this.id, this.uri, this.order, this.predicate, this.webFilters);
- }
- }
-
- public String getId() {
- return this.id;
- }
-
- public URI getUri() {
- return this.uri;
- }
-
- public int getOrder() {
- return order;
- }
-
- public Predicate getPredicate() {
- return this.predicate;
- }
-
- public List getWebFilters() {
- return Collections.unmodifiableList(this.webFilters);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Route route = (Route) o;
- return Objects.equals(id, route.id) &&
- Objects.equals(uri, route.uri) &&
- Objects.equals(order, route.order) &&
- Objects.equals(predicate, route.predicate) &&
- Objects.equals(webFilters, route.webFilters);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, uri, predicate, webFilters);
- }
-
- @Override
- public String toString() {
- final StringBuffer sb = new StringBuffer("Route{");
- sb.append("id='").append(id).append('\'');
- sb.append(", uri=").append(uri);
- sb.append(", order=").append(order);
- sb.append(", predicate=").append(predicate);
- sb.append(", webFilters=").append(webFilters);
- sb.append('}');
- return sb.toString();
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinition.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinition.java
deleted file mode 100644
index 6fbece81..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinition.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import org.hibernate.validator.constraints.NotEmpty;
-import org.springframework.cloud.gateway.filter.FilterDefinition;
-import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
-import org.springframework.validation.annotation.Validated;
-
-import javax.validation.Valid;
-import javax.validation.ValidationException;
-import javax.validation.constraints.NotNull;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.UUID;
-
-import static org.springframework.util.StringUtils.tokenizeToStringArray;
-
-/**
- * @author Spencer Gibb
- */
-@Validated
-public class RouteDefinition {
- @NotEmpty
- private String id = UUID.randomUUID().toString();
-
- @NotEmpty
- @Valid
- private List predicates = new ArrayList<>();
-
- @Valid
- private List filters = new ArrayList<>();
-
- @NotNull
- private URI uri;
-
- private int order = 0;
-
- public RouteDefinition() {}
-
- public RouteDefinition(String text) {
- int eqIdx = text.indexOf("=");
- if (eqIdx <= 0) {
- throw new ValidationException("Unable to parse RouteDefinition text '" + text + "'" +
- ", must be of the form name=value");
- }
-
- setId(text.substring(0, eqIdx));
-
- String[] args = tokenizeToStringArray(text.substring(eqIdx+1), ",");
-
- setUri(URI.create(args[0]));
-
- for (int i=1; i < args.length; i++) {
- this.predicates.add(new PredicateDefinition(args[i]));
- }
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public List getPredicates() {
- return predicates;
- }
-
- public void setPredicates(List predicates) {
- this.predicates = predicates;
- }
-
- public List getFilters() {
- return filters;
- }
-
- public void setFilters(List filters) {
- this.filters = filters;
- }
-
- public URI getUri() {
- return uri;
- }
-
- public void setUri(URI uri) {
- this.uri = uri;
- }
-
- public int getOrder() {
- return order;
- }
-
- public void setOrder(int order) {
- this.order = order;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- RouteDefinition routeDefinition = (RouteDefinition) o;
- return Objects.equals(id, routeDefinition.id) &&
- Objects.equals(predicates, routeDefinition.predicates) &&
- Objects.equals(order, routeDefinition.order) &&
- Objects.equals(uri, routeDefinition.uri);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, predicates, uri);
- }
-
- @Override
- public String toString() {
- return "RouteDefinition{" +
- "id='" + id + '\'' +
- ", predicates=" + predicates +
- ", filters=" + filters +
- ", uri=" + uri +
- ", order=" + order +
- '}';
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionLocator.java
deleted file mode 100644
index e27dacd6..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionLocator.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public interface RouteDefinitionLocator {
-
- Flux getRouteDefinitions();
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRepository.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRepository.java
deleted file mode 100644
index 16b6cb3c..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRepository.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-/**
- * @author Spencer Gibb
- */
-public interface RouteDefinitionRepository extends RouteDefinitionLocator, RouteDefinitionWriter {
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java
deleted file mode 100644
index 6fbea4fc..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.cloud.gateway.config.GatewayProperties;
-import org.springframework.cloud.gateway.filter.FilterDefinition;
-import org.springframework.cloud.gateway.filter.OrderedWebFilter;
-import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
-import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
-import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory;
-import org.springframework.cloud.gateway.support.ArgumentHints;
-import org.springframework.cloud.gateway.support.NameUtils;
-import org.springframework.core.annotation.AnnotationAwareOrderComparator;
-import org.springframework.tuple.Tuple;
-import org.springframework.tuple.TupleBuilder;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-
-import reactor.core.publisher.Flux;
-
-/**
- * {@link RouteLocator} that loads routes from a {@link RouteDefinitionLocator}
- * @author Spencer Gibb
- */
-public class RouteDefinitionRouteLocator implements RouteLocator {
- protected final Log logger = LogFactory.getLog(getClass());
-
- private final RouteDefinitionLocator routeDefinitionLocator;
- private final Map predicates = new LinkedHashMap<>();
- private final Map webFilterFactories = new HashMap<>();
- private final GatewayProperties gatewayProperties;
-
- public RouteDefinitionRouteLocator(RouteDefinitionLocator routeDefinitionLocator,
- List predicates,
- List webFilterFactories,
- GatewayProperties gatewayProperties) {
- this.routeDefinitionLocator = routeDefinitionLocator;
- initFactories(predicates);
- webFilterFactories.forEach(factory -> this.webFilterFactories.put(factory.name(), factory));
- this.gatewayProperties = gatewayProperties;
- }
-
- private void initFactories(List predicates) {
- predicates.forEach(factory -> {
- String key = factory.name();
- if (this.predicates.containsKey(key)) {
- this.logger.warn("A RoutePredicateFactory named "+ key
- + " already exists, class: " + this.predicates.get(key)
- + ". It will be overwritten.");
- }
- this.predicates.put(key, factory);
- if (logger.isInfoEnabled()) {
- logger.info("Loaded RoutePredicateFactory [" + key + "]");
- }
- });
- }
-
- @Override
- public Flux getRoutes() {
- return this.routeDefinitionLocator.getRouteDefinitions()
- .map(this::convertToRoute)
- //TODO: error handling
- .map(route -> {
- if (logger.isDebugEnabled()) {
- logger.debug("RouteDefinition matched: " + route.getId());
- }
- return route;
- });
-
-
- /* TODO: trace logging
- if (logger.isTraceEnabled()) {
- logger.trace("RouteDefinition did not match: " + routeDefinition.getId());
- }*/
- }
-
- private Route convertToRoute(RouteDefinition routeDefinition) {
- Predicate predicate = combinePredicates(routeDefinition);
- List webFilters = getFilters(routeDefinition);
-
- return Route.builder(routeDefinition)
- .predicate(predicate)
- .webFilters(webFilters)
- .build();
- }
-
- private List loadWebFilters(String id, List filterDefinitions) {
- List filters = filterDefinitions.stream()
- .map(definition -> {
- WebFilterFactory filter = this.webFilterFactories.get(definition.getName());
- if (filter == null) {
- throw new IllegalArgumentException("Unable to find WebFilterFactory with name " + definition.getName());
- }
- Map args = definition.getArgs();
- if (logger.isDebugEnabled()) {
- logger.debug("RouteDefinition " + id + " applying filter " + args + " to " + definition.getName());
- }
-
- Tuple tuple = getTuple(filter, args);
-
- return filter.apply(tuple);
- })
- .collect(Collectors.toList());
-
- ArrayList ordered = new ArrayList<>(filters.size());
- for (int i = 0; i < filters.size(); i++) {
- ordered.add(new OrderedWebFilter(filters.get(i), i+1));
- }
-
- return ordered;
- }
-
- private Tuple getTuple(ArgumentHints hasArguments, Map args) {
- TupleBuilder builder = TupleBuilder.tuple();
-
- List argNames = hasArguments.argNames();
- if (!argNames.isEmpty()) {
- // ensure size is the same for key replacement later
- if (hasArguments.validateArgs() && args.size() != argNames.size()) {
- throw new IllegalArgumentException("Wrong number of arguments. Expected " + argNames
- + " " + argNames + ". Found " + args.size() + " " + args + "'");
- }
- }
-
- int entryIdx = 0;
- for (Map.Entry entry : args.entrySet()) {
- String key = entry.getKey();
-
- // RoutePredicateFactory has name hints and this has a fake key name
- // replace with the matching key hint
- if (key.startsWith(NameUtils.GENERATED_NAME_PREFIX) && !argNames.isEmpty()
- && entryIdx < args.size()) {
- key = argNames.get(entryIdx);
- }
-
- builder.put(key, entry.getValue());
- entryIdx++;
- }
-
- Tuple tuple = builder.build();
-
- if (hasArguments.validateArgs()) {
- for (String name : argNames) {
- if (!tuple.hasFieldName(name)) {
- throw new IllegalArgumentException("Missing argument '" + name + "'. Given " + tuple);
- }
- }
- }
- return tuple;
- }
-
- private List getFilters(RouteDefinition routeDefinition) {
- List filters = new ArrayList<>();
-
- //TODO: support option to apply defaults after route specific filters?
- if (!this.gatewayProperties.getDefaultFilters().isEmpty()) {
- filters.addAll(loadWebFilters("defaultFilters",
- this.gatewayProperties.getDefaultFilters()));
- }
-
- if (!routeDefinition.getFilters().isEmpty()) {
- filters.addAll(loadWebFilters(routeDefinition.getId(), routeDefinition.getFilters()));
- }
-
- AnnotationAwareOrderComparator.sort(filters);
- return filters;
- }
-
- private Predicate combinePredicates(RouteDefinition routeDefinition) {
- List predicates = routeDefinition.getPredicates();
- Predicate predicate = lookup(routeDefinition, predicates.get(0));
-
- for (PredicateDefinition andPredicate : predicates.subList(1, predicates.size())) {
- Predicate found = lookup(routeDefinition, andPredicate);
- predicate = predicate.and(found);
- }
-
- return predicate;
- }
-
- private Predicate lookup(RouteDefinition routeDefinition, PredicateDefinition predicate) {
- RoutePredicateFactory found = this.predicates.get(predicate.getName());
- if (found == null) {
- throw new IllegalArgumentException("Unable to find RoutePredicateFactory with name " + predicate.getName());
- }
- Map args = predicate.getArgs();
- if (logger.isDebugEnabled()) {
- logger.debug("RouteDefinition " + routeDefinition.getId() + " applying "
- + args + " to " + predicate.getName());
- }
-
- Tuple tuple = getTuple(found, args);
-
- return found.apply(tuple);
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionWriter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionWriter.java
deleted file mode 100644
index 225a541b..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionWriter.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import org.springframework.cloud.gateway.route.RouteDefinition;
-import reactor.core.publisher.Mono;
-
-/**
- * @author Spencer Gibb
- */
-public interface RouteDefinitionWriter {
-
- Mono save(Mono route);
-
- Mono delete(Mono routeId);
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteLocator.java
deleted file mode 100644
index a17936c4..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteLocator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-//TODO: rename to Routes?
-public interface RouteLocator {
-
- Flux getRoutes();
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Routes.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Routes.java
deleted file mode 100644
index 4f996069..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Routes.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.route;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.function.Predicate;
-
-import org.springframework.cloud.gateway.filter.factory.WebFilterFactories;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-
-import reactor.core.publisher.Flux;
-
-/**
- * @author Spencer Gibb
- */
-public class Routes {
-
- public static LocatorBuilder locator() {
- return new LocatorBuilder();
- }
-
- public static class LocatorBuilder {
-
- private List routes = new ArrayList<>();
-
- public RouteSpec route(String id) {
- return new RouteSpec(this).id(id);
- }
-
- private void add(Route route) {
- this.routes.add(route);
- }
-
- public RouteLocator build() {
- return () -> Flux.fromIterable(this.routes);
- }
-
- }
-
- public static class RouteSpec {
- private final Route.Builder builder = Route.builder();
- private final LocatorBuilder locatorBuilder;
-
- private RouteSpec(LocatorBuilder locatorBuilder) {
- this.locatorBuilder = locatorBuilder;
- }
-
- public RouteSpec id(String id) {
- this.builder.id(id);
- return this;
- }
-
- public RouteSpec order(int order) {
- this.builder.order(order);
- return this;
- }
-
- public PredicateSpec uri(String uri) {
- this.builder.uri(uri);
- return predicateBuilder();
- }
-
- public PredicateSpec uri(URI uri) {
- this.builder.uri(uri);
- return predicateBuilder();
- }
-
- private PredicateSpec predicateBuilder() {
- return new PredicateSpec(this.builder, this.locatorBuilder);
- }
-
- }
-
- public static class PredicateSpec {
-
- private final Route.Builder routeBuilder;
- private LocatorBuilder locatorBuilder;
-
- private PredicateSpec(Route.Builder routeBuilder, LocatorBuilder locatorBuilder) {
- this.routeBuilder = routeBuilder;
- this.locatorBuilder = locatorBuilder;
- }
-
- /* TODO: has and, or & negate of Predicate with terminal andFilters()?
- public RoutePredicateBuilder predicate() {
- }
- // this goes in new class
- public RoutePredicateBuilder host(String pattern) {
- Predicate predicate = RoutePredicates.host(pattern);
- }*/
-
- public WebFilterSpec predicate(Predicate predicate) {
- this.routeBuilder.predicate(predicate);
- return webFilterBuilder();
- }
-
- private WebFilterSpec webFilterBuilder() {
- return new WebFilterSpec(this.routeBuilder, this.locatorBuilder);
- }
-
- }
-
- public static class WebFilterSpec {
- private Route.Builder builder;
- private LocatorBuilder locatorBuilder;
-
- public WebFilterSpec(Route.Builder routeBuilder, LocatorBuilder locatorBuilder) {
- this.builder = routeBuilder;
- this.locatorBuilder = locatorBuilder;
- }
-
- public WebFilterSpec webFilters(List webFilters) {
- this.builder.webFilters(webFilters);
- return this;
- }
-
- public WebFilterSpec add(WebFilter webFilter) {
- this.builder.add(webFilter);
- return this;
- }
-
- public WebFilterSpec addAll(Collection webFilters) {
- this.builder.addAll(webFilters);
- return this;
- }
-
- public WebFilterSpec addResponseHeader(String headerName, String headerValue) {
- return add(WebFilterFactories.addResponseHeader(headerName, headerValue));
- }
-
- // TODO: build()?
- public LocatorBuilder and() {
- Route route = this.builder.build();
- this.locatorBuilder.add(route);
- return this.locatorBuilder;
- }
- }
-
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ArgumentHints.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ArgumentHints.java
deleted file mode 100644
index 852464c7..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ArgumentHints.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.support;
-
-import org.springframework.tuple.Tuple;
-import org.springframework.util.Assert;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Spencer Gibb
- */
-public interface ArgumentHints {
-
- /**
- * Returns hints about the number of args and the order for shortcut parsing.
- * @return
- */
- default List argNames() {
- return Collections.emptyList();
- }
-
- /**
- * Validate supplied argument size against {@see #argNames} size.
- * Useful for variable arg predicates.
- * @return
- */
- default boolean validateArgs() {
- return true;
- }
-
- default void validate(int requiredSize, Tuple args) {
- Assert.isTrue(args != null && args.size() == requiredSize,
- "args must have "+ requiredSize +" entry(s)");
- }
-
- default void validateMin(int minSize, Tuple args) {
- Assert.isTrue(args != null && args.size() >= minSize,
- "args must have at least "+ minSize +" entry(s)");
- }
-}
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
deleted file mode 100644
index 1f31e7fc..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NameUtils.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.support;
-
-import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
-import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory;
-
-/**
- * @author Spencer Gibb
- */
-public class NameUtils {
- public static final String GENERATED_NAME_PREFIX = "_genkey_";
-
- public static String generateName(int i) {
- return GENERATED_NAME_PREFIX + i;
- }
-
- public static String normalizePredicateName(Class extends RoutePredicateFactory> clazz) {
- return clazz.getSimpleName().replace(RoutePredicateFactory.class.getSimpleName(), "");
- }
-
- public static String normalizeFilterName(Class extends WebFilterFactory> clazz) {
- return clazz.getSimpleName().replace(WebFilterFactory.class.getSimpleName(), "");
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NotFoundException.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NotFoundException.java
deleted file mode 100644
index b8e83aae..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/NotFoundException.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.support;
-
-/**
- * @author Spencer Gibb
- */
-public class NotFoundException extends RuntimeException {
- public NotFoundException(String message) {
- super(message);
- }
-
- public NotFoundException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java
deleted file mode 100644
index 8ba59f5d..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.support;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.server.ServerWebExchange;
-
-/**
- * @author Spencer Gibb
- */
-public class ServerWebExchangeUtils {
-
- private static final Log logger = LogFactory.getLog(ServerWebExchangeUtils.class);
-
- public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = qualify("uriTemplateVariables");
-
- public static final String CLIENT_RESPONSE_ATTR = qualify("webHandlerClientResponse");
- public static final String GATEWAY_ROUTE_ATTR = qualify("gatewayRoute");
- public static final String GATEWAY_REQUEST_URL_ATTR = qualify("gatewayRequestUrl");
- public static final String GATEWAY_HANDLER_MAPPER_ATTR = qualify("gatewayHandlerMapper");
-
- private static String qualify(String attr) {
- return ServerWebExchangeUtils.class.getName() + "." + attr;
- }
-
- public static boolean setResponseStatus(ServerWebExchange exchange, HttpStatus httpStatus) {
- boolean response = exchange.getResponse().setStatusCode(httpStatus);
- if (!response && logger.isWarnEnabled()) {
- logger.warn("Unable to set status code to "+ httpStatus + ". Response already committed.");
- }
- return response;
- }
-
- public static HttpStatus parse(String statusString) {
- HttpStatus httpStatus;
-
- try {
- int status = Integer.parseInt(statusString);
- httpStatus = HttpStatus.valueOf(status);
- } catch (NumberFormatException e) {
- // try the enum string
- httpStatus = HttpStatus.valueOf(statusString.toUpperCase());
- }
- return httpStatus;
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/SubnetUtils.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/SubnetUtils.java
deleted file mode 100644
index fc7193c3..00000000
--- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/SubnetUtils.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.support;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * A class that performs some subnet calculations given a network address and a subnet mask.
- * See original from commons-net org.apache.commons.net.util.SubnetUtils
- * @see "http://www.faqs.org/rfcs/rfc1519.html"
- */
-@SuppressWarnings("unused")
-public class SubnetUtils {
-
- private static final String IP_ADDRESS = "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})";
- private static final String SLASH_FORMAT = IP_ADDRESS + "/(\\d{1,3})";
- private static final Pattern addressPattern = Pattern.compile(IP_ADDRESS);
- private static final Pattern cidrPattern = Pattern.compile(SLASH_FORMAT);
- private static final int NBITS = 32;
-
- private int netmask = 0;
- private int address = 0;
- private int network = 0;
- private int broadcast = 0;
-
- /** Whether the broadcast/network address are included in host count */
- private boolean inclusiveHostCount = false;
-
-
- /**
- * Constructor that takes a CIDR-notation string, e.g. "192.168.0.1/16"
- * @param cidrNotation A CIDR-notation string, e.g. "192.168.0.1/16"
- * @throws IllegalArgumentException if the parameter is invalid,
- * i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-3 decimal digits in range 1-32
- */
- public SubnetUtils(String cidrNotation) {
- calculate(cidrNotation);
- }
-
- /**
- * Constructor that takes a dotted decimal address and a dotted decimal mask.
- * @param address An IP address, e.g. "192.168.0.1"
- * @param mask A dotted decimal netmask e.g. "255.255.0.0"
- * @throws IllegalArgumentException if the address or mask is invalid,
- * i.e. does not match n.n.n.n where n=1-3 decimal digits and the mask is not all zeros
- */
- public SubnetUtils(String address, String mask) {
- calculate(toCidrNotation(address, mask));
- }
-
-
- /**
- * Returns true if the return value of {@link SubnetInfo#getAddressCount()}
- * includes the network and broadcast addresses.
- * @since 2.2
- * @return true if the hostcount includes the network and broadcast addresses
- */
- public boolean isInclusiveHostCount() {
- return inclusiveHostCount;
- }
-
- /**
- * Set to true if you want the return value of {@link SubnetInfo#getAddressCount()}
- * to include the network and broadcast addresses.
- * @param inclusiveHostCount true if network and broadcast addresses are to be included
- * @since 2.2
- */
- public void setInclusiveHostCount(boolean inclusiveHostCount) {
- this.inclusiveHostCount = inclusiveHostCount;
- }
-
-
-
- /**
- * Convenience container for subnet summary information.
- *
- */
- public final class SubnetInfo {
- /* Mask to convert unsigned int to a long (i.e. keep 32 bits) */
- private static final long UNSIGNED_INT_MASK = 0x0FFFFFFFFL;
-
- private SubnetInfo() {}
-
- private int netmask() { return netmask; }
- private int network() { return network; }
- private int address() { return address; }
- private int broadcast() { return broadcast; }
-
- // long versions of the values (as unsigned int) which are more suitable for range checking
- private long networkLong() { return network & UNSIGNED_INT_MASK; }
- private long broadcastLong(){ return broadcast & UNSIGNED_INT_MASK; }
-
- private int low() {
- return (isInclusiveHostCount() ? network() :
- broadcastLong() - networkLong() > 1 ? network() + 1 : 0);
- }
-
- private int high() {
- return (isInclusiveHostCount() ? broadcast() :
- broadcastLong() - networkLong() > 1 ? broadcast() -1 : 0);
- }
-
- /**
- * Returns true if the parameter address is in the
- * range of usable endpoint addresses for this subnet. This excludes the
- * network and broadcast adresses.
- * @param address A dot-delimited IPv4 address, e.g. "192.168.0.1"
- * @return True if in range, false otherwise
- */
- public boolean isInRange(String address) {
- return isInRange(toInteger(address));
- }
-
- /**
- *
- * @param address the address to check
- * @return true if it is in range
- * @since 3.4 (made public)
- */
- public boolean isInRange(int address) {
- long addLong = address & UNSIGNED_INT_MASK;
- long lowLong = low() & UNSIGNED_INT_MASK;
- long highLong = high() & UNSIGNED_INT_MASK;
- return addLong >= lowLong && addLong <= highLong;
- }
-
- public String getBroadcastAddress() {
- return format(toArray(broadcast()));
- }
-
- public String getNetworkAddress() {
- return format(toArray(network()));
- }
-
- public String getNetmask() {
- return format(toArray(netmask()));
- }
-
- public String getAddress() {
- return format(toArray(address()));
- }
-
- /**
- * Return the low address as a dotted IP address.
- * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
- *
- * @return the IP address in dotted format, may be "0.0.0.0" if there is no valid address
- */
- public String getLowAddress() {
- return format(toArray(low()));
- }
-
- /**
- * Return the high address as a dotted IP address.
- * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
- *
- * @return the IP address in dotted format, may be "0.0.0.0" if there is no valid address
- */
- public String getHighAddress() {
- return format(toArray(high()));
- }
-
- /**
- * Get the count of available addresses.
- * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
- * @return the count of addresses, may be zero.
- * @throws RuntimeException if the correct count is greater than {@code Integer.MAX_VALUE}
- * @deprecated (3.4) use {@link #getAddressCountLong()} instead
- */
- @Deprecated
- public int getAddressCount() {
- long countLong = getAddressCountLong();
- if (countLong > Integer.MAX_VALUE) {
- throw new RuntimeException("Count is larger than an integer: " + countLong);
- }
- // N.B. cannot be negative
- return (int)countLong;
- }
-
- /**
- * Get the count of available addresses.
- * Will be zero for CIDR/31 and CIDR/32 if the inclusive flag is false.
- * @return the count of addresses, may be zero.
- * @since 3.4
- */
- public long getAddressCountLong() {
- long b = broadcastLong();
- long n = networkLong();
- long count = b - n + (isInclusiveHostCount() ? 1 : -1);
- return count < 0 ? 0 : count;
- }
-
- public int asInteger(String address) {
- return toInteger(address);
- }
-
- public String getCidrSignature() {
- return toCidrNotation(
- format(toArray(address())),
- format(toArray(netmask()))
- );
- }
-
- public String[] getAllAddresses() {
- int ct = getAddressCount();
- String[] addresses = new String[ct];
- if (ct == 0) {
- return addresses;
- }
- for (int add = low(), j=0; add <= high(); ++add, ++j) {
- addresses[j] = format(toArray(add));
- }
- return addresses;
- }
-
- /**
- * {@inheritDoc}
- * @since 2.2
- */
- @Override
- public String toString() {
- final StringBuilder buf = new StringBuilder();
- buf.append("CIDR Signature:\t[").append(getCidrSignature()).append("]")
- .append(" Netmask: [").append(getNetmask()).append("]\n")
- .append("Network:\t[").append(getNetworkAddress()).append("]\n")
- .append("Broadcast:\t[").append(getBroadcastAddress()).append("]\n")
- .append("First Address:\t[").append(getLowAddress()).append("]\n")
- .append("Last Address:\t[").append(getHighAddress()).append("]\n")
- .append("# Addresses:\t[").append(getAddressCount()).append("]\n");
- return buf.toString();
- }
- }
-
- /**
- * Return a {@link SubnetInfo} instance that contains subnet-specific statistics
- * @return new instance
- */
- public final SubnetInfo getInfo() { return new SubnetInfo(); }
-
- /*
- * Initialize the internal fields from the supplied CIDR mask
- */
- private void calculate(String mask) {
- Matcher matcher = cidrPattern.matcher(mask);
-
- if (matcher.matches()) {
- address = matchAddress(matcher);
-
- /* Create a binary netmask from the number of bits specification /x */
- int cidrPart = rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
- for (int j = 0; j < cidrPart; ++j) {
- netmask |= (1 << 31 - j);
- }
-
- /* Calculate base network address */
- network = (address & netmask);
-
- /* Calculate broadcast address */
- broadcast = network | ~(netmask);
- } else {
- throw new IllegalArgumentException("Could not parse [" + mask + "]");
- }
- }
-
- /*
- * Convert a dotted decimal format address to a packed integer format
- */
- private int toInteger(String address) {
- Matcher matcher = addressPattern.matcher(address);
- if (matcher.matches()) {
- return matchAddress(matcher);
- } else {
- throw new IllegalArgumentException("Could not parse [" + address + "]");
- }
- }
-
- /*
- * Convenience method to extract the components of a dotted decimal address and
- * pack into an integer using a regex match
- */
- private int matchAddress(Matcher matcher) {
- int addr = 0;
- for (int i = 1; i <= 4; ++i) {
- int n = (rangeCheck(Integer.parseInt(matcher.group(i)), 0, 255));
- addr |= ((n & 0xff) << 8*(4-i));
- }
- return addr;
- }
-
- /*
- * Convert a packed integer address into a 4-element array
- */
- private int[] toArray(int val) {
- int ret[] = new int[4];
- for (int j = 3; j >= 0; --j) {
- ret[j] |= ((val >>> 8*(3-j)) & (0xff));
- }
- return ret;
- }
-
- /*
- * Convert a 4-element array into dotted decimal format
- */
- private String format(int[] octets) {
- StringBuilder str = new StringBuilder();
- for (int i =0; i < octets.length; ++i){
- str.append(octets[i]);
- if (i != octets.length - 1) {
- str.append(".");
- }
- }
- return str.toString();
- }
-
- /*
- * Convenience function to check integer boundaries.
- * Checks if a value x is in the range [begin,end].
- * Returns x if it is in range, throws an exception otherwise.
- */
- private int rangeCheck(int value, int begin, int end) {
- if (value >= begin && value <= end) { // (begin,end]
- return value;
- }
-
- throw new IllegalArgumentException("Value [" + value + "] not in range ["+begin+","+end+"]");
- }
-
- /*
- * Count the number of 1-bits in a 32-bit integer using a divide-and-conquer strategy
- * see Hacker's Delight section 5.1
- */
- int pop(int x) {
- x = x - ((x >>> 1) & 0x55555555);
- x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
- x = (x + (x >>> 4)) & 0x0F0F0F0F;
- x = x + (x >>> 8);
- x = x + (x >>> 16);
- return x & 0x0000003F;
- }
-
- /* Convert two dotted decimal addresses to a single xxx.xxx.xxx.xxx/yy format
- * by counting the 1-bit population in the mask address. (It may be better to count
- * NBITS-#trailing zeroes for this case)
- */
- private String toCidrNotation(String addr, String mask) {
- return addr + "/" + pop(toInteger(mask));
- }
-}
diff --git a/spring-cloud-gateway-core/src/main/resources/META-INF/scripts/request_rate_limiter.lua b/spring-cloud-gateway-core/src/main/resources/META-INF/scripts/request_rate_limiter.lua
deleted file mode 100644
index bfb7ebd9..00000000
--- a/spring-cloud-gateway-core/src/main/resources/META-INF/scripts/request_rate_limiter.lua
+++ /dev/null
@@ -1,34 +0,0 @@
-local tokens_key = KEYS[1]
-local timestamp_key = KEYS[2]
---redis.log(redis.LOG_WARNING, "tokens_key " .. tokens_key)
-
-local rate = tonumber(ARGV[1])
-local capacity = tonumber(ARGV[2])
-local now = tonumber(ARGV[3])
-local requested = tonumber(ARGV[4])
-
-local fill_time = capacity/rate
-local ttl = math.floor(fill_time*2)
-
-local last_tokens = tonumber(redis.call("get", tokens_key))
-if last_tokens == nil then
- last_tokens = capacity
-end
-
-local last_refreshed = tonumber(redis.call("get", timestamp_key))
-if last_refreshed == nil then
- last_refreshed = 0
-end
-
-local delta = math.max(0, now-last_refreshed)
-local filled_tokens = math.min(capacity, last_tokens+(delta*rate))
-local allowed = filled_tokens >= requested
-local new_tokens = filled_tokens
-if allowed then
- new_tokens = filled_tokens - requested
-end
-
-redis.call("setex", tokens_key, ttl, new_tokens)
-redis.call("setex", timestamp_key, ttl, now)
-
-return { allowed, new_tokens }
diff --git a/spring-cloud-gateway-core/src/main/resources/META-INF/spring.factories b/spring-cloud-gateway-core/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 1d13cae7..00000000
--- a/spring-cloud-gateway-core/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,4 +0,0 @@
-# Auto Configure
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.springframework.cloud.gateway.config.GatewayAutoConfiguration,\
-org.springframework.cloud.gateway.config.GatewayLoadBalancerClientAutoConfiguration
diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderWebFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderWebFilterFactoryTests.java
deleted file mode 100644
index 22eaa88f..00000000
--- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderWebFilterFactoryTests.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2013-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.springframework.cloud.gateway.filter.factory;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.SpringBootConfiguration;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.cloud.gateway.test.BaseWebClientTests;
-import org.springframework.context.annotation.Import;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.time.Duration;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-import static org.springframework.cloud.gateway.test.TestUtils.getMap;
-import static org.springframework.web.reactive.function.BodyExtractors.toMono;
-
-
-/**
- * @author Spencer Gibb
- * @author Biju Kunjummen
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = RANDOM_PORT)
-@DirtiesContext
-@ActiveProfiles(profiles = "request-header-web-filter")
-public class AddRequestHeaderWebFilterFactoryTests extends BaseWebClientTests {
-
- @Test
- public void addRequestHeaderFilterWorks() {
- Mono