diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java index 7a6ba84c8..e9002d53d 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java @@ -70,7 +70,7 @@ public class AddRequestParameterGatewayFilterFactory implements GatewayFilterFac .build(true) .toUri(); - ServerHttpRequest request = mutate(exchange.getRequest()).uri(newUri).build(); + ServerHttpRequest request = exchange.getRequest().mutate().uri(newUri).build(); return chain.filter(exchange.mutate().request(request).build()); } catch (RuntimeException ex) { 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 160caf8b8..734426455 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 @@ -19,7 +19,6 @@ package org.springframework.cloud.gateway.filter.factory; import org.springframework.cloud.gateway.filter.GatewayFilter; import org.springframework.cloud.gateway.support.ArgumentHints; -import org.springframework.cloud.gateway.support.GatewayServerHttpRequestBuilder; import org.springframework.cloud.gateway.support.NameUtils; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.tuple.Tuple; @@ -39,8 +38,8 @@ public interface GatewayFilterFactory extends ArgumentHints { return NameUtils.normalizeFilterName(getClass()); } - + @Deprecated default ServerHttpRequest.Builder mutate(ServerHttpRequest request) { - return new GatewayServerHttpRequestBuilder(request); + return request.mutate(); } } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java index 03d2a929e..7351824cb 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java @@ -158,7 +158,7 @@ public class HystrixGatewayFilterFactory implements GatewayFilterFactory { .toUri(); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl); - ServerHttpRequest request = mutate(this.exchange.getRequest()).uri(requestUrl).build(); + ServerHttpRequest request = this.exchange.getRequest().mutate().uri(requestUrl).build(); ServerWebExchange mutated = exchange.mutate().request(request).build(); return RxReactiveStreams.toObservable(HystrixGatewayFilterFactory.this.dispatcherHandler.handle(mutated)); } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java index 3817219bf..3045677f1 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java @@ -55,7 +55,7 @@ public class PrefixPathGatewayFilterFactory implements GatewayFilterFactory { addOriginalRequestUrl(exchange, req.getURI()); String newPath = prefix + req.getURI().getPath(); - ServerHttpRequest request = mutate(req) + ServerHttpRequest request = req.mutate() .path(newPath) .build(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java index 3fd797ede..5d79bd0f5 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java @@ -54,7 +54,7 @@ public class RewritePathGatewayFilterFactory implements GatewayFilterFactory { String path = req.getURI().getPath(); String newPath = path.replaceAll(regex, replacement); - ServerHttpRequest request = mutate(req) + ServerHttpRequest request = req.mutate() .path(newPath) .build(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java index 2477c7045..0d5a8adb0 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java @@ -73,7 +73,7 @@ public class SetPathGatewayFilterFactory implements GatewayFilterFactory { exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri); - ServerHttpRequest request = mutate(req) + ServerHttpRequest request = req.mutate() .path(newPath) .build(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java index 9c85fdb79..ae8cee3ca 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java @@ -29,6 +29,7 @@ import reactor.core.publisher.Flux; * @author Sebastien Deleuze * @since 5.0 */ +@Deprecated public class GatewayServerHttpRequestBuilder implements ServerHttpRequest.Builder { private boolean encoded; diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java index 126de12e6..562d46221 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java @@ -27,16 +27,12 @@ import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; -import java.time.Duration; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -import static org.springframework.web.reactive.function.BodyExtractors.toMono; /** @@ -51,20 +47,15 @@ public class AddRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest @Test public void addRequestHeaderFilterWorks() { - Mono result = webClient.get() + testClient.get() .uri("/headers") .header("Host", "www.addrequestheader.org") .exchange() - .flatMap(response -> response.body(toMono(Map.class))); - - StepVerifier.create(result) - .consumeNextWith( - response -> { - Map headers = getMap(response, "headers"); - assertThat(headers).containsEntry("X-Request-Foo", "Bar"); - }) - .expectComplete() - .verify(Duration.ofMinutes(10)); + .expectBody(Map.class) + .consumeWith(result -> { + Map headers = getMap(result.getResponseBody(), "headers"); + assertThat(headers).containsEntry("X-Request-Foo", "Bar"); + }); } @EnableAutoConfiguration diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java index d8e1b9720..8f9c7e487 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java @@ -38,10 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedQuery; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -import static org.springframework.web.reactive.function.BodyExtractors.toMono; - -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @@ -73,31 +69,26 @@ public class AddRequestParameterGatewayFilterFactoryTests extends BaseWebClientT } URI uri = UriComponentsBuilder.fromUriString(this.baseUri+"/get" + query).build(true).toUri(); boolean checkForEncodedValue = containsEncodedQuery(uri); - Mono result = webClient.get() + testClient.get() .uri(uri) .header("Host", "www.addrequestparameter.org") .exchange() - .flatMap(response -> response.body(toMono(Map.class))); - - StepVerifier.create(result) - .consumeNextWith( - response -> { - Map args = getMap(response, "args"); - assertThat(args).containsEntry("foo", "bar"); - if (name != null) { - if (checkForEncodedValue) { - try { - assertThat(args).containsEntry(name, URLDecoder.decode(value, "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } else { - assertThat(args).containsEntry(name, value); - } - } - }) - .expectComplete() - .verify(DURATION); + .expectBody(Map.class) + .consumeWith(response -> { + Map args = getMap(response.getResponseBody(), "args"); + assertThat(args).containsEntry("foo", "bar"); + if (name != null) { + if (checkForEncodedValue) { + try { + assertThat(args).containsEntry(name, URLDecoder.decode(value, "UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } else { + assertThat(args).containsEntry(name, value); + } + } + }); } @EnableAutoConfiguration