Remove deprecated classes.

This commit is contained in:
Spencer Gibb
2017-12-19 12:46:51 -05:00
parent 0ce65bb230
commit 4b89ac1c69
13 changed files with 7 additions and 705 deletions

View File

@@ -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 {
}

View File

@@ -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);
}
}

View File

@@ -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<ServerWebExchange> after(ZonedDateTime datetime) {
return new AfterRoutePredicateFactory().apply(datetime);
}
public static Predicate<ServerWebExchange> before(ZonedDateTime datetime) {
return new BeforeRoutePredicateFactory().apply(datetime);
}
public static Predicate<ServerWebExchange> between(ZonedDateTime datetime1, ZonedDateTime datetime2) {
return new BetweenRoutePredicateFactory().apply(datetime1, datetime2);
}
public static Predicate<ServerWebExchange> cookie(String name, String regex) {
return new CookieRoutePredicateFactory().apply(name, regex);
}
public static Predicate<ServerWebExchange> header(String header, String regex) {
return new HeaderRoutePredicateFactory().apply(header, regex);
}
public static Predicate<ServerWebExchange> host(String pattern) {
return new HostRoutePredicateFactory().apply(pattern);
}
public static Predicate<ServerWebExchange> host(String pattern, PathMatcher pathMatcher) {
HostRoutePredicateFactory predicateFactory = new HostRoutePredicateFactory();
predicateFactory.setPathMatcher(pathMatcher);
return predicateFactory.apply(pattern);
}
public static Predicate<ServerWebExchange> method(String method) {
return new MethodRoutePredicateFactory().apply(method);
}
public static Predicate<ServerWebExchange> method(HttpMethod method) {
return new MethodRoutePredicateFactory().apply(method);
}
public static Predicate<ServerWebExchange> path(String pattern) {
return new PathRoutePredicateFactory().apply(pattern);
}
public static Predicate<ServerWebExchange> query(String param, String regex) {
return new QueryRoutePredicateFactory().apply(param, regex);
}
public static Predicate<ServerWebExchange> query(String param) {
return new QueryRoutePredicateFactory().apply(param, null);
}
public static Predicate<ServerWebExchange> remoteAddr(String... addrs) {
return new RemoteAddrRoutePredicateFactory().apply(addrs);
}
public static Predicate<ServerWebExchange> alwaysTrue() {
return exchange -> true;
}
}

View File

@@ -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<Route> 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<ServerWebExchange> predicate = RoutePredicates.host(pattern);
}*/
public PredicateSpec order(int order) {
this.builder.order(order);
return this;
}
public GatewayFilterSpec predicate(Predicate<ServerWebExchange> 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<GatewayFilter> 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<GatewayFilter> 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);
}
}
}

View File

@@ -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<Route>()
/**
* 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 <T> Predicate<T>.and(other: Predicate<T>) = this.and(other)
/**
* A helper to return a composed [Predicate] that tests against this [Predicate] OR the [other] predicate
*/
infix fun <T> Predicate<T>.or(other: Predicate<T>) = this.or(other)
/**
* A helper to return a composed [Predicate] that negates this [Predicate]
*/
fun <T> Predicate<T>.negate() = this.negate()
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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,

View File

@@ -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;

View File

@@ -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()
}
}

View File

@@ -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))