diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.java deleted file mode 100644 index ae91c68a..00000000 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.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; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to activate Spring Cloud Gateway configuration {@link org.springframework.cloud.gateway.config.GatewayAutoConfiguration} - * - * @deprecated taken care of by auto-configuration now. To be removed in future milestone. - * @author Spencer Gibb - * - */ - -@Deprecated -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface EnableGateway { - -} diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilters.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilters.java deleted file mode 100644 index 66346688..00000000 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilters.java +++ /dev/null @@ -1,126 +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 java.net.URI; -import java.net.URL; -import java.util.Arrays; - -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.http.HttpStatus; -import org.springframework.tuple.Tuple; - -import com.netflix.hystrix.HystrixObservableCommand; - -import static org.springframework.tuple.TupleBuilder.tuple; - -/** - * @deprecated inject {@link org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder} bean instead - * @author Spencer Gibb - */ -@Deprecated -public class GatewayFilters { - - public static final Tuple EMPTY_TUPLE = tuple().build(); - - public static GatewayFilter addRequestHeader(String headerName, String headerValue) { - return new AddRequestHeaderGatewayFilterFactory().apply(headerName, headerValue); - } - - public static GatewayFilter addRequestParameter(String param, String value) { - return new AddRequestParameterGatewayFilterFactory().apply(param, value); - } - - public static GatewayFilter addResponseHeader(String headerName, String headerValue) { - return new AddResponseHeaderGatewayFilterFactory().apply(headerName, headerValue); - } - - public static GatewayFilter hystrix(String commandName) { - return new HystrixGatewayFilterFactory().apply(commandName); - } - - public static GatewayFilter hystrix(HystrixObservableCommand.Setter setter) { - return new HystrixGatewayFilterFactory().apply(setter); - } - - public static GatewayFilter prefixPath(String prefix) { - return new PrefixPathGatewayFilterFactory().apply(prefix); - } - - public static GatewayFilter redirect(int status, URI url) { - return redirect(String.valueOf(status), url.toString()); - } - - public static GatewayFilter redirect(int status, String url) { - return redirect(String.valueOf(status), url); - } - - public static GatewayFilter redirect(String status, URI url) { - return redirect(status, url.toString()); - } - - public static GatewayFilter redirect(String status, String url) { - return new RedirectToGatewayFilterFactory().apply(status, url); - } - - public static GatewayFilter redirect(HttpStatus status, URL url) { - return new RedirectToGatewayFilterFactory().apply(status, url); - } - - public static GatewayFilter removeNonProxyHeaders(String... headersToRemove) { - RemoveNonProxyHeadersGatewayFilterFactory filterFactory = new RemoveNonProxyHeadersGatewayFilterFactory(); - filterFactory.setHeaders(Arrays.asList(headersToRemove)); - return filterFactory.apply(EMPTY_TUPLE); - } - - public static GatewayFilter removeRequestHeader(String headerName) { - return new RemoveRequestHeaderGatewayFilterFactory().apply(headerName); - } - - public static GatewayFilter removeResponseHeader(String headerName) { - return new RemoveResponseHeaderGatewayFilterFactory().apply(headerName); - } - - public static GatewayFilter rewritePath(String regex, String replacement) { - return new RewritePathGatewayFilterFactory().apply(regex, replacement); - } - - public static GatewayFilter secureHeaders(SecureHeadersProperties properties) { - return new SecureHeadersGatewayFilterFactory(properties).apply(EMPTY_TUPLE); - } - - public static GatewayFilter setPath(String template) { - return new SetPathGatewayFilterFactory().apply(template); - } - - public static GatewayFilter setResponseHeader(String headerName, String headerValue) { - return new SetResponseHeaderGatewayFilterFactory().apply(headerName, headerValue); - } - - public static GatewayFilter setStatus(int status) { - return setStatus(String.valueOf(status)); - } - - public static GatewayFilter setStatus(String status) { - return new SetStatusGatewayFilterFactory().apply(status); - } - - public static GatewayFilter setStatus(HttpStatus status) { - return new SetStatusGatewayFilterFactory().apply(status); - } -} 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 8537804d..00000000 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicates.java +++ /dev/null @@ -1,91 +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.function.Predicate; - -import org.springframework.http.HttpMethod; -import org.springframework.util.PathMatcher; -import org.springframework.web.server.ServerWebExchange; - -/** - * @deprecated inject {@link org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder} bean instead - * @author Spencer Gibb - */ -@Deprecated -public class RoutePredicates { - - public static Predicate after(ZonedDateTime datetime) { - return new AfterRoutePredicateFactory().apply(datetime); - } - - public static Predicate before(ZonedDateTime datetime) { - return new BeforeRoutePredicateFactory().apply(datetime); - } - - public static Predicate between(ZonedDateTime datetime1, ZonedDateTime datetime2) { - return new BetweenRoutePredicateFactory().apply(datetime1, datetime2); - } - - public static Predicate cookie(String name, String regex) { - return new CookieRoutePredicateFactory().apply(name, regex); - } - - public static Predicate header(String header, String regex) { - return new HeaderRoutePredicateFactory().apply(header, regex); - } - - public static Predicate host(String pattern) { - return new HostRoutePredicateFactory().apply(pattern); - } - - public static Predicate host(String pattern, PathMatcher pathMatcher) { - HostRoutePredicateFactory predicateFactory = new HostRoutePredicateFactory(); - predicateFactory.setPathMatcher(pathMatcher); - return predicateFactory.apply(pattern); - } - - public static Predicate method(String method) { - return new MethodRoutePredicateFactory().apply(method); - } - - public static Predicate method(HttpMethod method) { - return new MethodRoutePredicateFactory().apply(method); - } - - public static Predicate path(String pattern) { - return new PathRoutePredicateFactory().apply(pattern); - } - - public static Predicate query(String param, String regex) { - return new QueryRoutePredicateFactory().apply(param, regex); - } - - public static Predicate query(String param) { - return new QueryRoutePredicateFactory().apply(param, null); - } - - public static Predicate remoteAddr(String... addrs) { - return new RemoteAddrRoutePredicateFactory().apply(addrs); - } - - public static Predicate alwaysTrue() { - return exchange -> true; - } -} 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 d6d861f7..00000000 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Routes.java +++ /dev/null @@ -1,179 +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.OrderedGatewayFilter; -import org.springframework.cloud.gateway.filter.factory.GatewayFilters; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.cloud.gateway.filter.GatewayFilter; - -import reactor.core.publisher.Flux; - -/** - * @deprecated inject {@link org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder} bean instead - * @author Spencer Gibb - */ -@Deprecated -public class Routes { - - public static LocatorBuilder locator() { - return new LocatorBuilder(); - } - - public static class LocatorBuilder { - - private List routes = new ArrayList<>(); - - public PredicateSpec route(String id) { - return new RouteSpec(this).id(id); - } - - private void add(Route route) { - this.routes.add(route); - } - - LocatorBuilder uri(Route.Builder builder, String uri) { - Route route = builder.uri(uri).build(); - routes.add(route); - return this; - } - - LocatorBuilder uri(Route.Builder builder, URI uri) { - Route route = builder.uri(uri).build(); - routes.add(route); - return this; - } - - 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 PredicateSpec id(String id) { - this.builder.id(id); - return predicateBuilder(); - } - - private PredicateSpec predicateBuilder() { - return new PredicateSpec(this.builder, this.locatorBuilder); - } - - } - - public static class PredicateSpec { - - private final Route.Builder builder; - private LocatorBuilder locatorBuilder; - - private PredicateSpec(Route.Builder builder, LocatorBuilder locatorBuilder) { - this.builder = builder; - 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 PredicateSpec order(int order) { - this.builder.order(order); - return this; - } - - public GatewayFilterSpec predicate(Predicate predicate) { - this.builder.predicate(predicate); - return gatewayFilterBuilder(); - } - - private GatewayFilterSpec gatewayFilterBuilder() { - return new GatewayFilterSpec(this.builder, this.locatorBuilder); - } - - public LocatorBuilder uri(String uri) { - return this.locatorBuilder.uri(this.builder, uri); - } - - public LocatorBuilder uri(URI uri) { - return this.locatorBuilder.uri(this.builder, uri); - } - } - - public static class GatewayFilterSpec { - private Route.Builder builder; - private LocatorBuilder locatorBuilder; - - public GatewayFilterSpec(Route.Builder routeBuilder, LocatorBuilder locatorBuilder) { - this.builder = routeBuilder; - this.locatorBuilder = locatorBuilder; - } - - public GatewayFilterSpec gatewayFilters(List gatewayFilters) { - this.addAll(gatewayFilters); - return this; - } - - public GatewayFilterSpec add(GatewayFilter gatewayFilter) { - return this.filter(gatewayFilter); - } - - public GatewayFilterSpec filter(GatewayFilter gatewayFilter) { - return this.filter(gatewayFilter, 0); - } - - public GatewayFilterSpec filter(GatewayFilter gatewayFilter, int order) { - this.builder.add(new OrderedGatewayFilter(gatewayFilter, order)); - return this; - } - - public GatewayFilterSpec addAll(Collection gatewayFilters) { - this.builder.addAll(gatewayFilters); - return this; - } - - public GatewayFilterSpec addResponseHeader(String headerName, String headerValue) { - return add(GatewayFilters.addResponseHeader(headerName, headerValue)); - } - - public LocatorBuilder uri(String uri) { - return this.locatorBuilder.uri(this.builder, uri); - } - - public LocatorBuilder uri(URI uri) { - return this.locatorBuilder.uri(this.builder, uri); - } - } - -} diff --git a/spring-cloud-gateway-core/src/main/kotlin/org/springframework/cloud/gateway/route/GatewayDsl.kt b/spring-cloud-gateway-core/src/main/kotlin/org/springframework/cloud/gateway/route/GatewayDsl.kt deleted file mode 100644 index 428a75f1..00000000 --- a/spring-cloud-gateway-core/src/main/kotlin/org/springframework/cloud/gateway/route/GatewayDsl.kt +++ /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.route - -import reactor.core.publisher.Flux -import java.util.function.Predicate - -/** - * A Kotlin based DSL to configure a [RouteLocator] - * - * Example: - * ``` - * val routeLocator = gateway { - * route(id = "test") { - * uri("http://httpbin.org:80") - * predicate(host("**.abc.org") and path("/image/png")) - * add(addResponseHeader("X-TestHeader", "foobar")) - * } - * } - * ``` - * - * @author Biju Kunjummen - * @deprecated see [org.springframework.cloud.gateway.route.builder.RouteDsl] - */ -@Deprecated("see RouteDsl") -fun gateway(routeLocator: RouteLocatorDsl.() -> Unit) = RouteLocatorDsl().apply(routeLocator).build() - - -/** - * Provider for [RouteLocator] DSL functionality - * @deprecated see [org.springframework.cloud.gateway.route.builder.RouteDsl] - */ -@Deprecated("see RouteDsl") -class RouteLocatorDsl { - private val routes = mutableListOf() - - /** - * DSL to add a route to the [RouteLocator] - * - * @see [Route.Builder] - */ - fun route(id: String? = null, order: Int = 0, uri: String? = null, init: Route.Builder.() -> Unit) { - val builder = Route.builder() - if (uri != null) { - builder.uri(uri) - } - routes += builder.id(id).order(order).apply(init).build() - } - - fun build(): RouteLocator { - return RouteLocator { Flux.fromIterable(this.routes) } - } - - /** - * A helper to return a composed [Predicate] that tests against this [Predicate] AND the [other] predicate - */ - infix fun Predicate.and(other: Predicate) = this.and(other) - - /** - * A helper to return a composed [Predicate] that tests against this [Predicate] OR the [other] predicate - */ - infix fun Predicate.or(other: Predicate) = this.or(other) - - /** - * A helper to return a composed [Predicate] that negates this [Predicate] - */ - fun Predicate.negate() = this.negate() -} - - diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactoryTests.java index c5efcb8a..0c29bf64 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/AfterRoutePredicateFactoryTests.java @@ -73,7 +73,7 @@ public class AfterRoutePredicateFactoryTests { @Test public void testPredicates() { - boolean result = RoutePredicates.after(ZonedDateTime.now().minusHours(2)).test(getExchange()); + boolean result = new AfterRoutePredicateFactory().apply(ZonedDateTime.now().minusHours(2)).test(getExchange()); assertThat(result).isTrue(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactoryTests.java index 1b752412..53ccba20 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BeforeRoutePredicateFactoryTests.java @@ -73,7 +73,7 @@ public class BeforeRoutePredicateFactoryTests { @Test public void testPredicates() { - boolean result = RoutePredicates.before(ZonedDateTime.now().minusHours(2)).test(getExchange()); + boolean result = new BeforeRoutePredicateFactory().apply(ZonedDateTime.now().minusHours(2)).test(getExchange()); assertThat(result).isFalse(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryTests.java index 51bd2325..a18c5d6b 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryTests.java @@ -97,8 +97,8 @@ public class BetweenRoutePredicateFactoryTests { @Test public void testPredicates() { - boolean result = RoutePredicates - .between(ZonedDateTime.now().minusHours(2), ZonedDateTime.now().plusHours(1)) + boolean result = new BetweenRoutePredicateFactory() + .apply(ZonedDateTime.now().minusHours(2), ZonedDateTime.now().plusHours(1)) .test(getExchange()); assertThat(result).isTrue(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicatesTest.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicatesTest.java deleted file mode 100644 index e89605d0..00000000 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/RoutePredicatesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 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.junit.Test; -import org.springframework.http.HttpMethod; -import org.springframework.mock.http.server.reactive.MockServerHttpRequest; -import org.springframework.mock.web.server.MockServerWebExchange; -import org.springframework.web.server.ServerWebExchange; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.method; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path; - -/** - * @author Biju Kunjummen - */ -public class RoutePredicatesTest { - - @Test - public void testHostPredicates() { - assertThat(host("**").test(mockHostExchange("test.abc.com"))).isTrue(); - assertThat(host("**.abc.**").test(mockHostExchange("test.abc.com"))).isTrue(); - assertThat(host("**.co?").test(mockHostExchange("test.abc.com"))).isTrue(); - assertThat(host("**.co").test(mockHostExchange("test.abc.com"))).isFalse(); - - } - - @Test - public void testPathPredicates() { - assertThat(path("/**").test(mockPathExchange("/path1/path2"))).isTrue(); - assertThat(path("/path1/*").test(mockPathExchange("/path1/path2"))).isTrue(); - assertThat(path("/path1/path?").test(mockPathExchange("/path1/path2"))).isTrue(); - } - - @Test - public void testMethodPredicates() { - assertThat(method("GET").test(mockMethodExchange("GET"))).isTrue(); - assertThat(method("POST").test(mockMethodExchange("POST"))).isTrue(); - assertThat(method("PUT").test(mockMethodExchange("PUT"))).isTrue(); - } - - private ServerWebExchange mockHostExchange(String host) { - MockServerHttpRequest mockRequest = MockServerHttpRequest.get("/") - .header("Host", host).build(); - return MockServerWebExchange.from(mockRequest); - } - - private ServerWebExchange mockPathExchange(String path) { - MockServerHttpRequest mockRequest = MockServerHttpRequest.get(path).build(); - return MockServerWebExchange.from(mockRequest); - } - - private ServerWebExchange mockMethodExchange(String method) { - MockServerHttpRequest mockRequest = MockServerHttpRequest - .method(HttpMethod.resolve(method), "/").build(); - return MockServerWebExchange.from(mockRequest); - } -} diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/AdhocTestSuite.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/AdhocTestSuite.java index 8941eee8..47e57670 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/AdhocTestSuite.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/AdhocTestSuite.java @@ -32,8 +32,8 @@ import org.springframework.cloud.gateway.filter.factory.RemoveNonProxyHeadersGat import org.springframework.cloud.gateway.filter.factory.RemoveRequestHeaderGatewayFilterFactoryTests; import org.springframework.cloud.gateway.filter.factory.RemoveResponseHeaderGatewayFilterFactoryTests; import org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactoryTests; -import org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactoryTests; import org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactoryIntegrationTests; +import org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactoryTests; import org.springframework.cloud.gateway.filter.factory.SecureHeadersGatewayFilterFactoryTests; import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactoryIntegrationTests; import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactoryTests; @@ -47,7 +47,6 @@ import org.springframework.cloud.gateway.handler.predicate.BetweenRoutePredicate import org.springframework.cloud.gateway.handler.predicate.HostRoutePredicateFactoryTests; import org.springframework.cloud.gateway.handler.predicate.MethodRoutePredicateFactoryTests; import org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactoryTests; -import org.springframework.cloud.gateway.handler.predicate.RoutePredicatesTest; import org.springframework.cloud.gateway.route.RouteDefinitionRouteLocatorTests; import org.springframework.cloud.gateway.test.websocket.WebSocketIntegrationTests; @@ -90,7 +89,6 @@ import static org.junit.Assume.assumeThat; // PredicateFactory Tests MethodRoutePredicateFactoryTests.class, HostRoutePredicateFactoryTests.class, - RoutePredicatesTest.class, AfterRoutePredicateFactoryTests.class, PathRoutePredicateFactoryTests.class, BetweenRoutePredicateFactoryTests.class, diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/websocket/WebSocketIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/websocket/WebSocketIntegrationTests.java index caec5e3f..b2d9b5c8 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/websocket/WebSocketIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/websocket/WebSocketIntegrationTests.java @@ -66,7 +66,6 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.alwaysTrue; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/spring-cloud-gateway-core/src/test/kotlin/org/springframework/cloud/gateway/route/GatewayDslTests.kt b/spring-cloud-gateway-core/src/test/kotlin/org/springframework/cloud/gateway/route/GatewayDslTests.kt deleted file mode 100644 index 956805f1..00000000 --- a/spring-cloud-gateway-core/src/test/kotlin/org/springframework/cloud/gateway/route/GatewayDslTests.kt +++ /dev/null @@ -1,96 +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.junit.Test -import org.springframework.cloud.gateway.filter.factory.GatewayFilters.addResponseHeader -import org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host -import org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path -import org.springframework.mock.http.server.reactive.MockServerHttpRequest -import org.springframework.mock.web.server.MockServerWebExchange -import org.springframework.web.server.ServerWebExchange -import reactor.test.StepVerifier -import java.net.URI - -class GatewayDslTests { - - @Test - fun sampleRouteDsl() { - val routeLocator = gateway { - route { - id("test") - uri("http://httpbin.org:80") - predicate(host("**.abc.org") and path("/image/png")) - add(addResponseHeader("X-TestHeader", "foobar")) - } - - route { - id("test2") - uri("http://httpbin.org:80") - predicate(path("/image/webp") or path("/image/anotherone")) - add(addResponseHeader("X-AnotherHeader", "baz")) - add(addResponseHeader("X-AnotherHeader-2", "baz-2")) - } - } - - StepVerifier - .create(routeLocator.routes) - .expectNextMatches({ r -> - r.id == "test" && r.filters.size == 1 && r.uri == URI.create("http://httpbin.org:80") - }) - .expectNextMatches({ r -> - r.id == "test2" && r.filters.size == 2 && r.uri == URI.create("http://httpbin.org:80") - }) - .expectComplete() - .verify() - - val sampleExchange: ServerWebExchange = MockServerWebExchange.from(MockServerHttpRequest.get("/image/webp") - .header("Host", "test.abc.org").build()) - - val filteredRoutes = routeLocator.routes.filter({ r -> r.predicate.test(sampleExchange) }) - - StepVerifier.create(filteredRoutes) - .expectNextMatches({ r -> - r.id == "test2" && r.filters.size == 2 && r.uri == URI.create("http://httpbin.org:80") - }) - .expectComplete() - .verify() - } - - @Test - fun dslWithFunctionParameters() { - val routerLocator = gateway { - route(id = "test", order = 10, uri = "http://httpbin.org") { - predicate(host("**.abc.org")) - } - } - - StepVerifier.create(routerLocator.routes) - .expectNextMatches({ r -> - r.id == "test" && - r.uri == URI.create("http://httpbin.org") && - r.order == 10 && - r.order == 10 && - r.predicate.test(MockServerWebExchange - .from(MockServerHttpRequest - .get("/someuri").header("Host", "test.abc.org"))) - }) - .expectComplete() - .verify() - } -} \ No newline at end of file diff --git a/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java b/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java index 5bfb7fb6..fed60f45 100644 --- a/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java +++ b/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java @@ -32,9 +32,6 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host; -import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path; - /** * @author Spencer Gibb */ @@ -56,8 +53,8 @@ public class GatewaySampleApplication { .uri("http://httpbin.org:80") ) .route(r -> r.order(-1) - .predicate(host("**.throttle.org").and(path("/get"))) - .add(throttle.apply(1, + .host("**.throttle.org").and().path("/get") + .filter(throttle.apply(1, 1, 10, TimeUnit.SECONDS))