From 7eb929a7c1f5ac0119097f88e868b37c6c8faa33 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 3 Mar 2020 14:56:24 -0500 Subject: [PATCH] Removes deprecations. Fixes gh-698 --- .../gateway/config/HttpClientProperties.java | 37 ------ ...DiscoveryClientRouteDefinitionLocator.java | 18 --- ...tewayDiscoveryClientAutoConfiguration.java | 19 --- .../filter/AdaptCachedBodyGlobalFilter.java | 6 - .../gateway/filter/GatewayMetricsFilter.java | 9 -- .../filter/WeightCalculatorWebFilter.java | 19 --- .../filter/factory/GatewayFilterFactory.java | 6 - .../RequestSizeGatewayFilterFactory.java | 6 - .../factory/RetryGatewayFilterFactory.java | 6 - .../rewrite/CachedBodyOutputMessage.java | 6 - .../rewrite/HttpMessageWriterResponse.java | 113 ------------------ ...ModifyRequestBodyGatewayFilterFactory.java | 35 ------ ...odifyResponseBodyGatewayFilterFactory.java | 82 ------------- .../filter/ratelimit/AbstractRateLimiter.java | 25 ---- .../gateway/filter/ratelimit/RateLimiter.java | 12 -- .../filter/ratelimit/RedisRateLimiter.java | 22 ---- .../predicate/HostRoutePredicateFactory.java | 16 --- .../MethodRoutePredicateFactory.java | 19 --- .../predicate/PathRoutePredicateFactory.java | 16 --- .../route/CachingRouteDefinitionLocator.java | 5 - .../gateway/route/CachingRouteLocator.java | 5 - .../cloud/gateway/route/Route.java | 7 -- .../route/RouteDefinitionRouteLocator.java | 49 +------- .../gateway/route/builder/PredicateSpec.java | 15 --- .../gateway/support/ConfigurationService.java | 59 ++------- ...DiscoveryClientAutoConfigurationTests.java | 89 -------------- .../WeightCalculatorWebFilterTests.java | 14 ++- ...ResponseBodyGatewayFilterFactoryTests.java | 4 +- .../BetweenRoutePredicateFactoryTests.java | 2 +- .../MethodRoutePredicateFactoryTests.java | 2 +- .../RouteDefinitionRouteLocatorTests.java | 4 +- .../route/builder/GatewayFilterSpecTests.java | 19 ++- .../cloud/gateway/test/AdhocTestSuite.java | 2 - .../gateway/test/GatewayTestApplication.java | 5 +- .../RouteConstructionIntegrationTests.java | 13 +- .../SSLHandshakeTimeoutDeprecatedTests.java | 51 -------- 36 files changed, 54 insertions(+), 763 deletions(-) delete mode 100644 spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/HttpMessageWriterResponse.java delete mode 100644 spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/discovery/BlockingGatewayDiscoveryClientAutoConfigurationTests.java delete mode 100644 spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutDeprecatedTests.java diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java index b97d6ffa..75aa9f98 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/HttpClientProperties.java @@ -37,7 +37,6 @@ import reactor.netty.resources.ConnectionProvider; import reactor.netty.tcp.SslProvider; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.boot.web.server.WebServerException; import org.springframework.core.style.ToStringCreator; import org.springframework.util.ResourceUtils; @@ -539,42 +538,6 @@ public class HttpClientProperties { this.closeNotifyReadTimeout = closeNotifyReadTimeout; } - @DeprecatedConfigurationProperty( - replacement = "spring.cloud.gateway.httpclient.ssl.handshake-timeout") - @Deprecated - public long getHandshakeTimeoutMillis() { - return getHandshakeTimeout().toMillis(); - } - - @Deprecated - public void setHandshakeTimeoutMillis(long handshakeTimeoutMillis) { - setHandshakeTimeout(Duration.ofMillis(handshakeTimeoutMillis)); - } - - @DeprecatedConfigurationProperty( - replacement = "spring.cloud.gateway.httpclient.ssl.close-notify-flush-timeout") - @Deprecated - public long getCloseNotifyFlushTimeoutMillis() { - return getCloseNotifyFlushTimeout().toMillis(); - } - - @Deprecated - public void setCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis) { - setCloseNotifyFlushTimeout(Duration.ofMillis(closeNotifyFlushTimeoutMillis)); - } - - @DeprecatedConfigurationProperty( - replacement = "spring.cloud.gateway.httpclient.ssl.close-notify-read-timeout") - @Deprecated - public long getCloseNotifyReadTimeoutMillis() { - return getCloseNotifyReadTimeout().toMillis(); - } - - @Deprecated - public void setCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis) { - setCloseNotifyFlushTimeout(Duration.ofMillis(closeNotifyReadTimeoutMillis)); - } - public SslProvider.DefaultConfigurationType getDefaultConfigurationType() { return defaultConfigurationType; } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteDefinitionLocator.java index 0ad99d41..51efe653 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteDefinitionLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteDefinitionLocator.java @@ -25,10 +25,8 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; -import reactor.core.scheduler.Schedulers; import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.gateway.filter.FilterDefinition; import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; @@ -60,22 +58,6 @@ public class DiscoveryClientRouteDefinitionLocator implements RouteDefinitionLoc private Flux> serviceInstances; - /** - * Kept for backwards compatibility. You should use the reactive discovery client. - * @param discoveryClient the blocking discovery client - * @param properties the configuration properties - * @deprecated kept for backwards compatibility - */ - @Deprecated - public DiscoveryClientRouteDefinitionLocator(DiscoveryClient discoveryClient, - DiscoveryLocatorProperties properties) { - this(discoveryClient.getClass().getSimpleName(), properties); - serviceInstances = Flux - .defer(() -> Flux.fromIterable(discoveryClient.getServices())) - .map(discoveryClient::getInstances) - .subscribeOn(Schedulers.boundedElastic()); - } - public DiscoveryClientRouteDefinitionLocator(ReactiveDiscoveryClient discoveryClient, DiscoveryLocatorProperties properties) { this(discoveryClient.getClass().getSimpleName(), properties); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration.java index da70da1e..acace208 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/discovery/GatewayDiscoveryClientAutoConfiguration.java @@ -24,7 +24,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration; import org.springframework.cloud.gateway.config.GatewayAutoConfiguration; @@ -103,22 +102,4 @@ public class GatewayDiscoveryClientAutoConfiguration { } - /** - * @deprecated In favor of the native reactive service discovery capability. - */ - @Configuration(proxyBeanMethods = false) - @Deprecated - @ConditionalOnProperty(value = "spring.cloud.discovery.reactive.enabled", - havingValue = "false") - public static class BlockingDiscoveryClientRouteDefinitionLocatorConfiguration { - - @Bean - @ConditionalOnProperty(name = "spring.cloud.gateway.discovery.locator.enabled") - public DiscoveryClientRouteDefinitionLocator discoveryClientRouteDefinitionLocator( - DiscoveryClient discoveryClient, DiscoveryLocatorProperties properties) { - return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties); - } - - } - } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/AdaptCachedBodyGlobalFilter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/AdaptCachedBodyGlobalFilter.java index 08ec58a7..fef3b357 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/AdaptCachedBodyGlobalFilter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/AdaptCachedBodyGlobalFilter.java @@ -39,12 +39,6 @@ public class AdaptCachedBodyGlobalFilter private ConcurrentMap routesToCache = new ConcurrentHashMap<>(); - /** - * Cached request body key. - */ - @Deprecated - public static final String CACHED_REQUEST_BODY_KEY = CACHED_REQUEST_BODY_ATTR; - @Override public void onApplicationEvent(EnableBodyCachingEvent event) { this.routesToCache.putIfAbsent(event.getRouteId(), true); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilter.java index 5a6da70a..10076afc 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilter.java @@ -16,7 +16,6 @@ package org.springframework.cloud.gateway.filter; -import java.util.Arrays; import java.util.List; import io.micrometer.core.instrument.MeterRegistry; @@ -27,8 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Mono; -import org.springframework.cloud.gateway.support.tagsprovider.GatewayHttpTagsProvider; -import org.springframework.cloud.gateway.support.tagsprovider.GatewayRouteTagsProvider; import org.springframework.cloud.gateway.support.tagsprovider.GatewayTagsProvider; import org.springframework.core.Ordered; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -53,12 +50,6 @@ public class GatewayMetricsFilter implements GlobalFilter, Ordered { .reduce(exchange -> Tags.empty(), GatewayTagsProvider::and); } - @Deprecated - public GatewayMetricsFilter(MeterRegistry meterRegistry) { - this(meterRegistry, Arrays.asList(new GatewayHttpTagsProvider(), - new GatewayRouteTagsProvider())); - } - @Override public int getOrder() { // start the timer as soon as possible and report the metric event before we write diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java index ccce58e3..c86e4ec1 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilter.java @@ -39,7 +39,6 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.style.ToStringCreator; -import org.springframework.validation.Validator; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; @@ -70,24 +69,6 @@ public class WeightCalculatorWebFilter private Map groupWeights = new ConcurrentHashMap<>(); - /* for testing */ WeightCalculatorWebFilter() { - this.routeLocator = null; - this.configurationService = new ConfigurationService(); - } - - @Deprecated - public WeightCalculatorWebFilter(Validator validator) { - this(validator, null); - } - - @Deprecated - public WeightCalculatorWebFilter(Validator validator, - ObjectProvider routeLocator) { - this.routeLocator = routeLocator; - this.configurationService = new ConfigurationService(); - this.configurationService.setValidator(validator); - } - public WeightCalculatorWebFilter(ObjectProvider routeLocator, ConfigurationService configurationService) { this.routeLocator = routeLocator; diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java index 2635f4e3..f7c87ca0 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java @@ -23,7 +23,6 @@ import org.springframework.cloud.gateway.support.Configurable; import org.springframework.cloud.gateway.support.HasRouteId; import org.springframework.cloud.gateway.support.NameUtils; import org.springframework.cloud.gateway.support.ShortcutConfigurable; -import org.springframework.http.server.reactive.ServerHttpRequest; /** * @author Spencer Gibb @@ -78,9 +77,4 @@ public interface GatewayFilterFactory extends ShortcutConfigurable, Configura return NameUtils.normalizeFilterFactoryName(getClass()); } - @Deprecated - default ServerHttpRequest.Builder mutate(ServerHttpRequest request) { - return request.mutate(); - } - } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactory.java index 30362a64..075df71c 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactory.java @@ -105,12 +105,6 @@ public class RequestSizeGatewayFilterFactory extends return maxSize; } - @Deprecated - public RequestSizeGatewayFilterFactory.RequestSizeConfig setMaxSize( - Long maxSize) { - return this.setMaxSize(DataSize.ofBytes(maxSize)); - } - public RequestSizeGatewayFilterFactory.RequestSizeConfig setMaxSize( DataSize maxSize) { this.maxSize = maxSize; diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java index 68161d2b..01a8d022 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java @@ -220,12 +220,6 @@ public class RetryGatewayFilterFactory removeAlreadyRouted(exchange); } - @Deprecated - public GatewayFilter apply(Repeat repeat, - Retry retry) { - return apply(null, repeat, retry); - } - public GatewayFilter apply(String routeId, Repeat repeat, Retry retry) { if (routeId != null && getPublisher() != null) { diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java index 872a2764..beb489b4 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java @@ -16,7 +16,6 @@ package org.springframework.cloud.gateway.filter.factory.rewrite; -import java.util.function.Function; import java.util.function.Supplier; import org.reactivestreams.Publisher; @@ -75,11 +74,6 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage { return this.body; } - @Deprecated - public void setWriteHandler(Function, Mono> writeHandler) { - - } - public Mono writeWith(Publisher body) { this.body = Flux.from(body); return Mono.empty(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/HttpMessageWriterResponse.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/HttpMessageWriterResponse.java deleted file mode 100644 index 5f07e597..00000000 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/HttpMessageWriterResponse.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.rewrite; - -import java.util.function.Supplier; - -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseCookie; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.util.MultiValueMap; - -/** - * This class is BETA and may be subject to change in a future release. Response who's job - * it is to gather the Publisher<DataBuffer> from the writeWith message during a - * call to HttpMessageWriter.write. Also gathers any headers set there. - */ -@Deprecated -public class HttpMessageWriterResponse implements ServerHttpResponse { - - private final HttpHeaders headers = new HttpHeaders(); - - private final DataBufferFactory dataBufferFactory; - - private Publisher body; - - public HttpMessageWriterResponse(DataBufferFactory dataBufferFactory) { - this.dataBufferFactory = dataBufferFactory; - } - - @Override - public HttpHeaders getHeaders() { - return this.headers; - } - - @Override - public Mono writeWith(Publisher body) { - this.body = body; - return Mono.empty(); - } - - @Override - public Mono writeAndFlushWith( - Publisher> body) { - // TODO: is this kosher? - return writeWith(Flux.from(body).flatMapSequential(p -> p)); - } - - public Publisher getBody() { - return body; - } - - @Override - public boolean setStatusCode(HttpStatus status) { - return false; - } - - @Override - public HttpStatus getStatusCode() { - return null; - } - - @Override - public MultiValueMap getCookies() { - return null; - } - - @Override - public void addCookie(ResponseCookie cookie) { - - } - - @Override - public DataBufferFactory bufferFactory() { - return this.dataBufferFactory; - } - - @Override - public void beforeCommit(Supplier> action) { - - } - - @Override - public boolean isCommitted() { - return false; - } - - @Override - public Mono setComplete() { - return null; - } - -} diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java index 3c4b2dfc..64310dcb 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java @@ -17,7 +17,6 @@ package org.springframework.cloud.gateway.filter.factory.rewrite; import java.util.List; -import java.util.Map; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -29,7 +28,6 @@ import org.springframework.cloud.gateway.support.BodyInserterContext; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.HttpHeaders; import org.springframework.http.codec.HttpMessageReader; -import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.web.reactive.function.BodyInserter; @@ -59,11 +57,6 @@ public class ModifyRequestBodyGatewayFilterFactory extends this.messageReaders = messageReaders; } - @Deprecated - public ModifyRequestBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) { - this(codecConfigurer.getReaders()); - } - @Override @SuppressWarnings("unchecked") public GatewayFilter apply(Config config) { @@ -152,12 +145,6 @@ public class ModifyRequestBodyGatewayFilterFactory extends private String contentType; - @Deprecated - private Map inHints; - - @Deprecated - private Map outHints; - private RewriteFunction rewriteFunction; public Class getInClass() { @@ -178,28 +165,6 @@ public class ModifyRequestBodyGatewayFilterFactory extends return this; } - @Deprecated - public Map getInHints() { - return inHints; - } - - @Deprecated - public Config setInHints(Map inHints) { - this.inHints = inHints; - return this; - } - - @Deprecated - public Map getOutHints() { - return outHints; - } - - @Deprecated - public Config setOutHints(Map outHints) { - this.outHints = outHints; - return this; - } - public RewriteFunction getRewriteFunction() { return rewriteFunction; } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java index 2830c0e1..76936b50 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java @@ -16,7 +16,6 @@ package org.springframework.cloud.gateway.filter.factory.rewrite; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -38,19 +37,12 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseCookie; -import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.codec.HttpMessageReader; -import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; -import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.server.HandlerStrategies; import org.springframework.web.server.ServerWebExchange; import static java.util.function.Function.identity; @@ -69,22 +61,6 @@ public class ModifyResponseBodyGatewayFilterFactory extends private final List> messageReaders; - @Deprecated - public ModifyResponseBodyGatewayFilterFactory() { - super(Config.class); - messageReaders = HandlerStrategies.withDefaults().messageReaders(); - messageBodyDecoders = Collections.emptyMap(); - messageBodyEncoders = Collections.emptyMap(); - } - - @Deprecated - public ModifyResponseBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) { - super(Config.class); - this.messageReaders = codecConfigurer.getReaders(); - messageBodyDecoders = Collections.emptyMap(); - messageBodyEncoders = Collections.emptyMap(); - } - public ModifyResponseBodyGatewayFilterFactory( List> messageReaders, Set messageBodyDecoders, @@ -190,12 +166,6 @@ public class ModifyResponseBodyGatewayFilterFactory extends private GatewayFilterFactory gatewayFilterFactory; public ModifyResponseGatewayFilter(Config config) { - this(config, null); - } - - @Deprecated - public ModifyResponseGatewayFilter(Config config, - @Nullable ServerCodecConfigurer codecConfigurer) { this.config = config; } @@ -205,12 +175,6 @@ public class ModifyResponseBodyGatewayFilterFactory extends .response(new ModifiedServerHttpResponse(exchange, config)).build()); } - @SuppressWarnings("unchecked") - @Deprecated - ServerHttpResponse decorate(ServerWebExchange exchange) { - return new ModifiedServerHttpResponse(exchange, config); - } - @Override public int getOrder() { return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER - 1; @@ -353,50 +317,4 @@ public class ModifyResponseBodyGatewayFilterFactory extends } - @Deprecated - @SuppressWarnings("unchecked") - public class ResponseAdapter implements ClientHttpResponse { - - private final Flux flux; - - private final HttpHeaders headers; - - public ResponseAdapter(Publisher body, - HttpHeaders headers) { - this.headers = headers; - if (body instanceof Flux) { - flux = (Flux) body; - } - else { - flux = ((Mono) body).flux(); - } - } - - @Override - public Flux getBody() { - return flux; - } - - @Override - public HttpHeaders getHeaders() { - return headers; - } - - @Override - public HttpStatus getStatusCode() { - return null; - } - - @Override - public int getRawStatusCode() { - return 0; - } - - @Override - public MultiValueMap getCookies() { - return null; - } - - } - } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/AbstractRateLimiter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/AbstractRateLimiter.java index ca48a979..97720e69 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/AbstractRateLimiter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/AbstractRateLimiter.java @@ -23,7 +23,6 @@ import org.springframework.cloud.gateway.support.AbstractStatefulConfigurable; import org.springframework.cloud.gateway.support.ConfigurationService; import org.springframework.context.ApplicationListener; import org.springframework.core.style.ToStringCreator; -import org.springframework.validation.Validator; public abstract class AbstractRateLimiter extends AbstractStatefulConfigurable implements RateLimiter, ApplicationListener { @@ -32,15 +31,6 @@ public abstract class AbstractRateLimiter extends AbstractStatefulConfigurabl private ConfigurationService configurationService; - @Deprecated - protected AbstractRateLimiter(Class configClass, String configurationPropertyName, - Validator validator) { - super(configClass); - this.configurationPropertyName = configurationPropertyName; - this.configurationService = new ConfigurationService(); - this.configurationService.setValidator(validator); - } - protected AbstractRateLimiter(Class configClass, String configurationPropertyName, ConfigurationService configurationService) { super(configClass); @@ -52,21 +42,6 @@ public abstract class AbstractRateLimiter extends AbstractStatefulConfigurabl return configurationPropertyName; } - @Deprecated - protected Validator getValidator() { - if (this.configurationService != null) { - return this.configurationService.getValidator(); - } - return null; - } - - @Deprecated - public void setValidator(Validator validator) { - if (this.configurationService != null) { - this.configurationService.setValidator(validator); - } - } - protected void setConfigurationService(ConfigurationService configurationService) { this.configurationService = configurationService; } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RateLimiter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RateLimiter.java index a15c1e74..697c2a9b 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RateLimiter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RateLimiter.java @@ -46,22 +46,10 @@ public interface RateLimiter extends StatefulConfigurable { this.headers = headers; } - @Deprecated - public Response(boolean allowed, long tokensRemaining) { - this.allowed = allowed; - this.tokensRemaining = tokensRemaining; - this.headers = Collections.emptyMap(); - } - public boolean isAllowed() { return allowed; } - @Deprecated - public long getTokensRemaining() { - return tokensRemaining; - } - public Map getHeaders() { return Collections.unmodifiableMap(headers); } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java index 85b4a623..e670a648 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java @@ -41,7 +41,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.core.style.ToStringCreator; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.data.redis.core.script.RedisScript; -import org.springframework.validation.Validator; import org.springframework.validation.annotation.Validated; /** @@ -56,18 +55,6 @@ import org.springframework.validation.annotation.Validated; public class RedisRateLimiter extends AbstractRateLimiter implements ApplicationContextAware { - /** - * @deprecated use {@link Config#replenishRate} - */ - @Deprecated - public static final String REPLENISH_RATE_KEY = "replenishRate"; - - /** - * @deprecated use {@link Config#burstCapacity} - */ - @Deprecated - public static final String BURST_CAPACITY_KEY = "burstCapacity"; - /** * Redis Rate Limiter property name. */ @@ -138,15 +125,6 @@ public class RedisRateLimiter extends AbstractRateLimiter> script, Validator validator) { - super(Config.class, CONFIGURATION_PROPERTY_NAME, validator); - this.redisTemplate = redisTemplate; - this.script = script; - this.initialized.compareAndSet(false, true); - } - /** * This creates an instance with default static configuration, useful in Java DSL. * @param defaultReplenishRate how many tokens per second in token-bucket algorithm. 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 index 101db352..2829465e 100644 --- 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 @@ -26,7 +26,6 @@ import java.util.function.Predicate; import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; import org.springframework.core.style.ToStringCreator; import org.springframework.util.AntPathMatcher; -import org.springframework.util.CollectionUtils; import org.springframework.util.PathMatcher; import org.springframework.validation.annotation.Validated; import org.springframework.web.server.ServerWebExchange; @@ -88,21 +87,6 @@ public class HostRoutePredicateFactory private List patterns = new ArrayList<>(); - @Deprecated - public String getPattern() { - if (!CollectionUtils.isEmpty(this.patterns)) { - return patterns.get(0); - } - return null; - } - - @Deprecated - public Config setPattern(String pattern) { - this.patterns = new ArrayList<>(); - this.patterns.add(pattern); - return this; - } - public List getPatterns() { return patterns; } 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 index b1cb3ab3..aba08dde 100644 --- 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 @@ -33,12 +33,6 @@ import static java.util.Arrays.stream; public class MethodRoutePredicateFactory extends AbstractRoutePredicateFactory { - /** - * Method key. - */ - @Deprecated - public static final String METHOD_KEY = "method"; - /** * Methods key. */ @@ -80,19 +74,6 @@ public class MethodRoutePredicateFactory private HttpMethod[] methods; - @Deprecated - public HttpMethod getMethod() { - if (methods != null && methods.length > 0) { - return methods[0]; - } - return null; - } - - @Deprecated - public void setMethod(HttpMethod method) { - this.methods = new HttpMethod[] { method }; - } - public HttpMethod[] getMethods() { return methods; } 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 index 2a1e8d12..2d23d2c5 100644 --- 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 @@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.style.ToStringCreator; import org.springframework.http.server.PathContainer; -import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.util.pattern.PathPattern; @@ -124,21 +123,6 @@ public class PathRoutePredicateFactory private boolean matchOptionalTrailingSeparator = true; - @Deprecated - public String getPattern() { - if (!CollectionUtils.isEmpty(this.patterns)) { - return patterns.get(0); - } - return null; - } - - @Deprecated - public Config setPattern(String pattern) { - this.patterns = new ArrayList<>(); - this.patterns.add(pattern); - return this; - } - public List getPatterns() { return patterns; } 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 index e1eef815..4c99cce3 100644 --- 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 @@ -71,9 +71,4 @@ public class CachingRouteDefinitionLocator .doOnNext(routes -> cache.put(CACHE_KEY, routes)).subscribe(); } - @Deprecated - /* 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 index f5c8d636..88c592c6 100644 --- 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 @@ -73,11 +73,6 @@ public class CachingRouteLocator .doOnNext(routes -> cache.put(CACHE_KEY, routes)).subscribe(); } - @Deprecated - /* for testing */ void handleRefresh() { - refresh(); - } - @Override public int getOrder() { return 0; 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 index ce360026..cabe2dcd 100644 --- 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 @@ -54,13 +54,6 @@ public class Route implements Ordered { private final Map metadata; - @Deprecated - private Route(String id, URI uri, int order, - AsyncPredicate predicate, - List gatewayFilters) { - this(id, uri, order, predicate, gatewayFilters, new HashMap<>()); - } - private Route(String id, URI uri, int order, AsyncPredicate predicate, List gatewayFilters, Map metadata) { 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 index f7ab0183..1cd7ca8c 100644 --- 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 @@ -26,10 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.config.GatewayProperties; import org.springframework.cloud.gateway.event.FilterArgsEvent; import org.springframework.cloud.gateway.event.PredicateArgsEvent; @@ -42,12 +38,8 @@ import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory; import org.springframework.cloud.gateway.support.ConfigurationService; import org.springframework.cloud.gateway.support.HasRouteId; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.core.convert.ConversionService; -import org.springframework.validation.Validator; import org.springframework.web.server.ServerWebExchange; /** @@ -55,8 +47,7 @@ import org.springframework.web.server.ServerWebExchange; * * @author Spencer Gibb */ -public class RouteDefinitionRouteLocator - implements RouteLocator, BeanFactoryAware, ApplicationEventPublisherAware { +public class RouteDefinitionRouteLocator implements RouteLocator { /** * Default filters name. @@ -75,20 +66,6 @@ public class RouteDefinitionRouteLocator private final GatewayProperties gatewayProperties; - @Deprecated - public RouteDefinitionRouteLocator(RouteDefinitionLocator routeDefinitionLocator, - List predicates, - List gatewayFilterFactories, - GatewayProperties gatewayProperties, ConversionService conversionService) { - this.routeDefinitionLocator = routeDefinitionLocator; - this.configurationService = new ConfigurationService(); - this.configurationService.setConversionService(conversionService); - initFactories(predicates); - gatewayFilterFactories.forEach( - factory -> this.gatewayFilterFactories.put(factory.name(), factory)); - this.gatewayProperties = gatewayProperties; - } - public RouteDefinitionRouteLocator(RouteDefinitionLocator routeDefinitionLocator, List predicates, List gatewayFilterFactories, @@ -102,30 +79,6 @@ public class RouteDefinitionRouteLocator this.gatewayProperties = gatewayProperties; } - @Override - @Deprecated - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (this.configurationService.getBeanFactory() == null) { - this.configurationService.setBeanFactory(beanFactory); - } - } - - @Autowired - @Deprecated - public void setValidator(Validator validator) { - if (this.configurationService.getValidator() == null) { - this.configurationService.setValidator(validator); - } - } - - @Override - @Deprecated - public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { - if (this.configurationService.getPublisher() == null) { - this.configurationService.setApplicationEventPublisher(publisher); - } - } - private void initFactories(List predicates) { predicates.forEach(factory -> { String key = factory.name(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/PredicateSpec.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/PredicateSpec.java index ce3bb54b..67780bce 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/PredicateSpec.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/PredicateSpec.java @@ -181,21 +181,6 @@ public class PredicateSpec extends UriSpec { .applyAsync(c -> c.setPatterns(Arrays.asList(patterns)))); } - /** - * A predicate that checks if the path of the request matches the given pattern - * @param pattern the pattern to check the path against. The pattern is a - * {@link org.springframework.util.PathMatcher} pattern - * @param matchOptionalTrailingSeparator set to false if you do not want this path to - * match when there is a trailing / - * @return a {@link BooleanSpec} to be used to add logical operators - */ - @Deprecated - public BooleanSpec path(String pattern, boolean matchOptionalTrailingSeparator) { - return asyncPredicate(getBean(PathRoutePredicateFactory.class).applyAsync(c -> c - .setPatterns(Collections.singletonList(pattern)) - .setMatchOptionalTrailingSeparator(matchOptionalTrailingSeparator))); - } - /** * A predicate that checks if the path of the request matches the given pattern * @param patterns the pattern to check the path against. The pattern is a diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ConfigurationService.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ConfigurationService.java index 3c6a012c..23550b53 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ConfigurationService.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ConfigurationService.java @@ -54,20 +54,6 @@ public class ConfigurationService implements ApplicationEventPublisherAware { private Supplier validator; - @Deprecated - public ConfigurationService() { - this.conversionService = () -> null; - this.validator = () -> null; - } - - @Deprecated - public ConfigurationService(BeanFactory beanFactory, - ConversionService conversionService, Validator validator) { - this.beanFactory = beanFactory; - this.conversionService = () -> conversionService; - this.validator = () -> validator; - } - public ConfigurationService(BeanFactory beanFactory, ObjectProvider conversionService, ObjectProvider validator) { @@ -76,6 +62,14 @@ public class ConfigurationService implements ApplicationEventPublisherAware { this.validator = validator::getIfAvailable; } + public ConfigurationService(BeanFactory beanFactory, + Supplier conversionService, + Supplier validator) { + this.beanFactory = beanFactory; + this.conversionService = conversionService; + this.validator = validator; + } + public ApplicationEventPublisher getPublisher() { return this.publisher; } @@ -85,33 +79,6 @@ public class ConfigurationService implements ApplicationEventPublisherAware { this.publisher = publisher; } - public BeanFactory getBeanFactory() { - return this.beanFactory; - } - - @Deprecated - public void setBeanFactory(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - @Deprecated - public void setConversionService(ConversionService conversionService) { - this.conversionService = () -> conversionService; - } - - public void setParser(SpelExpressionParser parser) { - this.parser = parser; - } - - public Validator getValidator() { - return this.validator.get(); - } - - @Deprecated - public void setValidator(Validator validator) { - this.validator = () -> validator; - } - public & ShortcutConfigurable> ConfigurableBuilder with( C configurable) { return new ConfigurableBuilder(this, configurable); @@ -121,10 +88,9 @@ public class ConfigurationService implements ApplicationEventPublisherAware { return new InstanceBuilder(this, instance); } - @Deprecated - public static T bindOrCreate(Bindable bindable, Map properties, - String configurationPropertyName, Validator validator, - ConversionService conversionService) { + /* for testing */ static T bindOrCreate(Bindable bindable, + Map properties, String configurationPropertyName, + Validator validator, ConversionService conversionService) { // see ConfigurationPropertiesBinder from spring boot for this definition. BindHandler handler = new IgnoreTopLevelConverterNotFoundBindHandler(); @@ -139,9 +105,8 @@ public class ConfigurationService implements ApplicationEventPublisherAware { .bindOrCreate(configurationPropertyName, bindable, handler); } - @Deprecated @SuppressWarnings("unchecked") - public static T getTargetObject(Object candidate) { + /* for testing */ static T getTargetObject(Object candidate) { try { if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { return (T) ((Advised) candidate).getTargetSource().getTarget(); diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/discovery/BlockingGatewayDiscoveryClientAutoConfigurationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/discovery/BlockingGatewayDiscoveryClientAutoConfigurationTests.java deleted file mode 100644 index eedb05df..00000000 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/discovery/BlockingGatewayDiscoveryClientAutoConfigurationTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.discovery; - -import java.util.List; - -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.gateway.config.LoadBalancerProperties; -import org.springframework.cloud.gateway.route.RouteDefinition; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(Enclosed.class) -public class BlockingGatewayDiscoveryClientAutoConfigurationTests { - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = Config.class, properties = { - "spring.cloud.gateway.discovery.locator.enabled=true", - "spring.cloud.discovery.reactive.enabled=false", - "spring.cloud.gateway.loadbalancer.use404=true", - "spring.cloud.discovery.client.simple.instances.service[0].uri=https://service1:443" }) - public static class EnabledByProperty { - - @Autowired(required = false) - private DiscoveryClientRouteDefinitionLocator locator; - - @Autowired(required = false) - private LoadBalancerProperties properties; - - @Test - public void routeLocatorBeanExists() { - assertThat(locator).as("DiscoveryClientRouteDefinitionLocator was null") - .isNotNull(); - List definitions = locator.getRouteDefinitions() - .collectList().block(); - assertThat(definitions).hasSize(1); - } - - @Test - public void use404() { - assertThat(properties.isUse404()).isTrue(); - } - - } - - @RunWith(SpringRunner.class) - @SpringBootTest(classes = Config.class) - public static class DisabledByDefault { - - @Autowired(required = false) - private DiscoveryClientRouteDefinitionLocator locator; - - @Test - public void routeLocatorBeanMissing() { - assertThat(locator).as("DiscoveryClientRouteDefinitionLocator exists") - .isNull(); - } - - } - - @SpringBootConfiguration - @EnableAutoConfiguration - protected static class Config { - - } - -} diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java index f9beb04d..d3ae845b 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.springframework.cloud.gateway.event.PredicateArgsEvent; import org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig; +import org.springframework.cloud.gateway.support.ConfigurationService; import org.springframework.cloud.gateway.support.WeightConfig; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; @@ -40,7 +41,7 @@ public class WeightCalculatorWebFilterTests { @Test public void testWeightCalculation() { - WeightCalculatorWebFilter filter = new WeightCalculatorWebFilter(); + WeightCalculatorWebFilter filter = createFilter(); String grp1 = "group1"; String grp2 = "group2"; @@ -59,6 +60,11 @@ public class WeightCalculatorWebFilterTests { asList(0.125, 0.125, 0.25, 0.5), 0.125, 0.25, 0.5); } + private WeightCalculatorWebFilter createFilter() { + return new WeightCalculatorWebFilter(null, + new ConfigurationService(null, () -> null, () -> null)); + } + private void assertWeightCalculation(WeightCalculatorWebFilter filter, String group, int item, int weight, List normalized, Double... middleRanges) { String routeId = route(item); @@ -96,7 +102,7 @@ public class WeightCalculatorWebFilterTests { @Test public void testChooseRouteWithRandom() { - WeightCalculatorWebFilter filter = new WeightCalculatorWebFilter(); + WeightCalculatorWebFilter filter = createFilter(); filter.addWeightConfig(new WeightConfig("groupa", "route1", 1)); filter.addWeightConfig(new WeightConfig("groupa", "route2", 3)); filter.addWeightConfig(new WeightConfig("groupa", "route3", 6)); @@ -144,6 +150,10 @@ public class WeightCalculatorWebFilterTests { private WeightConfig weightConfig; + TestWeightCalculatorWebFilter() { + super(null, new ConfigurationService(null, () -> null, () -> null)); + } + @Override void addWeightConfig(WeightConfig weightConfig) { this.weightConfig = weightConfig; diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index 5c1d351f..f6e3e164 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -102,8 +102,8 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe return Mono.just(modifiedResponse); })) .uri(uri)) - .route("modify_response_java_test_to_large", - r -> r.path("/").and().host("www.modifyresponsebodyjavatoolarge.org") + .route("modify_response_java_test_to_large", r -> r.path("/").and() + .host("www.modifyresponsebodyjavatoolarge.org") .filters(f -> f.prefixPath("/httpbin").modifyResponseBody( String.class, String.class, (webExchange, originalResponse) -> { 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 9de8a61a..551e98be 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 @@ -44,7 +44,7 @@ public class BetweenRoutePredicateFactoryTests { ApplicationConversionService conversionService = new ApplicationConversionService(); conversionService.addConverter(new StringToZonedDateTimeConverter()); // @formatter:off - T config = new ConfigurationService(null, conversionService, null) + T config = new ConfigurationService(null, () -> conversionService, () -> null) .with(factory) .name("myname") .normalizedProperties(properties) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java index 7b84074a..9c323f48 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java @@ -88,7 +88,7 @@ public class MethodRoutePredicateFactoryTests extends BaseWebClientTests { @Test public void toStringFormatSingleMethod() { Config config = new Config(); - config.setMethod(HttpMethod.GET); + config.setMethods(HttpMethod.GET); Predicate predicate = new MethodRoutePredicateFactory().apply(config); assertThat(predicate.toString()).contains("Methods: [GET]"); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocatorTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocatorTests.java index 504128cb..17f4836a 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocatorTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocatorTests.java @@ -74,7 +74,7 @@ public class RouteDefinitionRouteLocatorTests { RouteDefinitionRouteLocator routeDefinitionRouteLocator = new RouteDefinitionRouteLocator( new CompositeRouteDefinitionLocator(Flux.just(routeDefinitionLocator)), predicates, gatewayFilterFactories, gatewayProperties, - new ConfigurationService()); + new ConfigurationService(null, () -> null, () -> null)); StepVerifier.create(routeDefinitionRouteLocator.getRoutes()).assertNext(route -> { List filters = route.getFilters(); @@ -105,7 +105,7 @@ public class RouteDefinitionRouteLocatorTests { RouteDefinitionRouteLocator routeDefinitionRouteLocator = new RouteDefinitionRouteLocator( new CompositeRouteDefinitionLocator(Flux.just(routeDefinitionLocator)), predicates, gatewayFilterFactories, gatewayProperties, - new ConfigurationService()); + new ConfigurationService(null, () -> null, () -> null)); StepVerifier.create(routeDefinitionRouteLocator.getRoutes()).assertNext(route -> { List filters = route.getFilters(); diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpecTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpecTests.java index 871d7834..2b688dab 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpecTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpecTests.java @@ -16,6 +16,8 @@ package org.springframework.cloud.gateway.route.builder; +import java.util.Collections; + import org.junit.Test; import reactor.core.publisher.Mono; @@ -28,6 +30,7 @@ import org.springframework.cloud.gateway.route.Route; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.Ordered; import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.server.HandlerStrategies; import org.springframework.web.server.ServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; @@ -93,7 +96,9 @@ public class GatewayFilterSpecTests { .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) - .thenReturn(new ModifyResponseBodyGatewayFilterFactory()); + .thenReturn(new ModifyResponseBodyGatewayFilterFactory( + HandlerStrategies.withDefaults().messageReaders(), + Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); @@ -116,7 +121,9 @@ public class GatewayFilterSpecTests { .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) - .thenReturn(new ModifyResponseBodyGatewayFilterFactory()); + .thenReturn(new ModifyResponseBodyGatewayFilterFactory( + HandlerStrategies.withDefaults().messageReaders(), + Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); @@ -139,7 +146,9 @@ public class GatewayFilterSpecTests { .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) - .thenReturn(new ModifyResponseBodyGatewayFilterFactory()); + .thenReturn(new ModifyResponseBodyGatewayFilterFactory( + HandlerStrategies.withDefaults().messageReaders(), + Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); @@ -162,7 +171,9 @@ public class GatewayFilterSpecTests { .predicate(exchange -> true); when(context.getBean(ModifyResponseBodyGatewayFilterFactory.class)) - .thenReturn(new ModifyResponseBodyGatewayFilterFactory()); + .thenReturn(new ModifyResponseBodyGatewayFilterFactory( + HandlerStrategies.withDefaults().messageReaders(), + Collections.emptySet(), Collections.emptySet())); RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes(); GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes); 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 d3ee5678..a1d270f9 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 @@ -109,7 +109,6 @@ import static org.junit.Assume.assumeThat; org.springframework.cloud.gateway.actuate.GatewayControllerEndpointTests.class, org.springframework.cloud.gateway.config.GatewayAutoConfigurationTests.class, org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocatorTests.class, - org.springframework.cloud.gateway.discovery.BlockingGatewayDiscoveryClientAutoConfigurationTests.class, org.springframework.cloud.gateway.discovery.ReactiveGatewayDiscoveryClientAutoConfigurationTests.class, org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocatorIntegrationTests.class, org.springframework.cloud.gateway.support.ShortcutConfigurableTests.class, @@ -119,7 +118,6 @@ import static org.junit.Assume.assumeThat; org.springframework.cloud.gateway.test.ForwardTests.class, org.springframework.cloud.gateway.test.PostTests.class, org.springframework.cloud.gateway.test.ssl.SingleCertSSLTests.class, - org.springframework.cloud.gateway.test.ssl.SSLHandshakeTimeoutDeprecatedTests.class, org.springframework.cloud.gateway.test.ssl.MultiCertSSLTests.class, org.springframework.cloud.gateway.test.ssl.SSLHandshakeTimeoutTests.class, org.springframework.cloud.gateway.test.websocket.WebSocketIntegrationTests.class, diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/GatewayTestApplication.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/GatewayTestApplication.java index 9a3769f2..0b458275 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/GatewayTestApplication.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/GatewayTestApplication.java @@ -19,8 +19,8 @@ package org.springframework.cloud.gateway.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator; import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties; import org.springframework.context.annotation.Bean; @@ -49,7 +49,8 @@ public class GatewayTestApplication { @Bean public DiscoveryClientRouteDefinitionLocator discoveryClientRouteLocator( - DiscoveryClient discoveryClient, DiscoveryLocatorProperties properties) { + ReactiveDiscoveryClient discoveryClient, + DiscoveryLocatorProperties properties) { return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/RouteConstructionIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/RouteConstructionIntegrationTests.java index ffa9fe08..59646b61 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/RouteConstructionIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/RouteConstructionIntegrationTests.java @@ -16,9 +16,8 @@ package org.springframework.cloud.gateway.test; -import org.junit.Rule; +import org.junit.Assert; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -29,14 +28,12 @@ import org.springframework.context.annotation.Bean; public class RouteConstructionIntegrationTests { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void routesWithVerificationShouldFail() { - exception.expect(Throwable.class); - new SpringApplicationBuilder(TestConfig.class).profiles("verification-route") - .run(); + Assert.assertThrows(Throwable.class, () -> { + new SpringApplicationBuilder(TestConfig.class).profiles("verification-route") + .run(); + }); } @EnableAutoConfiguration diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutDeprecatedTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutDeprecatedTests.java deleted file mode 100644 index 937daa69..00000000 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutDeprecatedTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.test.ssl; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.JsonPathAssertions; -import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -// this test works because it assumes TLS hand shake cannot be done in 1ms. It takes -// closer to 80ms -@SpringBootTest(webEnvironment = RANDOM_PORT, - properties = { "spring.cloud.gateway.httpclient.ssl.handshake-timeout-millis=1" }) -@DirtiesContext -@ActiveProfiles("ssl") -// this is testing that the deprecated handshake-timeout-millis property still works -@Deprecated -public class SSLHandshakeTimeoutDeprecatedTests extends SingleCertSSLTests { - - @Test - @Override // here we validate that it the handshake times out - public void testSslTrust() { - ResponseSpec responseSpec = testClient.get().uri("/ssltrust").exchange(); - responseSpec.expectStatus().is5xxServerError(); - JsonPathAssertions jsonPath = responseSpec.expectBody().jsonPath("message"); - jsonPath.isEqualTo("handshake timed out"); - } - -}