From b9dbac7b2cc09f086ce6256744a8a31e5d0fd90e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 24 Apr 2017 17:15:33 +0200 Subject: [PATCH] Rename ServerResponse.BodyBuilder.body to syncBody This commit renames the `body(Object)` on ServerResponse to `syncBody(Object)`. The reason for this is that the original method name clashed with the `body(Publisher)` method in the Kotlin extension. The new name nicely reflects the synchronous nature of the method, making it less appealing than the `Publisher`-based `body` method. Issue: SPR-15467 --- .../test/web/reactive/server/DefaultWebTestClient.java | 6 +++--- .../test/web/reactive/server/WebTestClient.java | 10 ++++------ .../web/reactive/server/samples/JsonContentTests.java | 3 +-- .../reactive/server/samples/ResponseEntityTests.java | 2 +- .../web/reactive/function/client/DefaultWebClient.java | 2 +- .../web/reactive/function/client/WebClient.java | 6 +++--- .../function/server/DefaultServerResponseBuilder.java | 2 +- .../web/reactive/function/server/ServerResponse.java | 6 +++--- .../function/client/DefaultWebClientTests.java | 2 +- .../function/client/WebClientIntegrationTests.java | 2 +- .../server/DefaultServerResponseBuilderTests.java | 2 +- .../function/server/NestedRouteIntegrationTests.java | 4 ++-- 12 files changed, 22 insertions(+), 25 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 894e1eb398..fb739feedf 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -274,7 +274,7 @@ class DefaultWebTestClient implements WebTestClient { } @Override - public RequestHeadersSpec body(BodyInserter inserter) { + public RequestHeadersSpec body(BodyInserter inserter) { this.bodySpec.body(inserter); return this; } @@ -286,8 +286,8 @@ class DefaultWebTestClient implements WebTestClient { } @Override - public RequestHeadersSpec body(T body) { - this.bodySpec.body(body); + public RequestHeadersSpec syncBody(Object body) { + this.bodySpec.syncBody(body); return this; } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 3b0de40985..22c9a87430 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -458,14 +458,13 @@ public interface WebTestClient { /** * Set the body of the request to the given {@code BodyInserter}. * @param inserter the inserter - * @param the body type or the element type (for a stream) * @return spec for decoding the response * @see org.springframework.web.reactive.function.BodyInserters */ - RequestHeadersSpec body(BodyInserter inserter); + RequestHeadersSpec body(BodyInserter inserter); /** - * Set the body of the request to the given {@code Publisher}. + * Set the body of the request to the given asynchronous {@code Publisher}. * @param publisher the request body data * @param elementClass the class of elements contained in the publisher * @param the type of the elements contained in the publisher @@ -475,13 +474,12 @@ public interface WebTestClient { > RequestHeadersSpec body(S publisher, Class elementClass); /** - * Set the body of the request to the given {@code Object} and + * Set the body of the request to the given synchronous {@code Object} and * perform the request. * @param body the {@code Object} to write to the request - * @param the type contained in the body * @return a {@code Mono} with the response */ - RequestHeadersSpec body(T body); + RequestHeadersSpec syncBody(Object body); } diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java index 184525ac69..f98e15414b 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java @@ -19,7 +19,6 @@ import java.net.URI; import org.junit.Test; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -64,7 +63,7 @@ public class JsonContentTests { public void postJsonContent() throws Exception { this.client.post().uri("/persons") .contentType(MediaType.APPLICATION_JSON_UTF8) - .body("{\"name\":\"John\"}") + .syncBody("{\"name\":\"John\"}") .exchange() .expectStatus().isCreated() .expectBody().isEmpty(); diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java index a8d4680927..9c8b6e5a31 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java @@ -123,7 +123,7 @@ public class ResponseEntityTests { @Test public void postEntity() throws Exception { this.client.post().uri("/persons") - .body(new Person("John")) + .syncBody(new Person("John")) .exchange() .expectStatus().isCreated() .expectHeader().valueEquals("location", "/persons/John") diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index d613988e5a..071df90393 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -271,7 +271,7 @@ class DefaultWebClient implements WebClient { } @Override - public RequestHeadersSpec body(Object body) { + public RequestHeadersSpec syncBody(Object body) { Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by " + "using body(Publisher, Class)"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index e6d94afcfc..20d5af15be 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -450,7 +450,7 @@ public interface WebClient { RequestHeadersSpec body(BodyInserter inserter); /** - * Set the body of the request to the given {@code Publisher}. + * Set the body of the request to the given asynchronous {@code Publisher}. *

This method is a convenient shortcut for {@link #body(BodyInserter)} with a * {@linkplain org.springframework.web.reactive.function.BodyInserters#fromPublisher} * Publisher body inserter}. @@ -463,14 +463,14 @@ public interface WebClient { > RequestHeadersSpec body(P publisher, Class elementClass); /** - * Set the body of the request to the given {@code Object}. + * Set the body of the request to the given synchronous {@code Object}. *

This method is a convenient shortcut for {@link #body(BodyInserter)} with a * {@linkplain org.springframework.web.reactive.function.BodyInserters#fromObject * Object body inserter}. * @param body the {@code Object} to write to the request * @return this builder */ - RequestHeadersSpec body(Object body); + RequestHeadersSpec syncBody(Object body); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java index a2debbc8b5..b0482d02d7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java @@ -189,7 +189,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { } @Override - public Mono body(Object body) { + public Mono syncBody(Object body) { Assert.notNull(body, "'body' must not be null"); Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by using " + "body(Publisher, Class)"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java index 3778e7ded9..1857eec636 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java @@ -334,7 +334,7 @@ public interface ServerResponse { BodyBuilder hint(String key, Object value); /** - * Set the body of the response to the given {@code Publisher} and return it. + * Set the body of the response to the given asynchronous {@code Publisher} and return it. * This convenience method combines {@link #body(BodyInserter)} and * {@link BodyInserters#fromPublisher(Publisher, Class)}. * @param publisher the {@code Publisher} to write to the response @@ -346,7 +346,7 @@ public interface ServerResponse { > Mono body(P publisher, Class elementClass); /** - * Set the body of the response to the given {@code Object} and return it. + * Set the body of the response to the given synchronous {@code Object} and return it. * This convenience method combines {@link #body(BodyInserter)} and * {@link BodyInserters#fromObject(Object)}. * @param body the body of the response @@ -354,7 +354,7 @@ public interface ServerResponse { * @throws IllegalArgumentException if {@code body} is a {@link Publisher}, for which * {@link #body(Publisher, Class)} should be used. */ - Mono body(Object body); + Mono syncBody(Object body); /** * Set the body of the response to the given {@code BodyInserter} and return it. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java index 5ec1377ea4..4fdaabe30b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java @@ -121,7 +121,7 @@ public class DefaultWebClientTests { Mono mono = Mono.empty(); WebClient client = builder().build(); - client.post().uri("http://example.com").body(mono); + client.post().uri("http://example.com").syncBody(mono); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 7d49dcdb42..6d6f2d8f16 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -294,7 +294,7 @@ public class WebClientIntegrationTests { .uri("/pojo/capitalize") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) - .body(new Pojo("foofoo", "barbar")) + .syncBody(new Pojo("foofoo", "barbar")) .exchange() .flatMap(response -> response.bodyToMono(Pojo.class)); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java index 1f7fc73fec..755b7a4cc5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java @@ -298,7 +298,7 @@ public class DefaultServerResponseBuilderTests { public void bodyObjectPublisher() throws Exception { Mono mono = Mono.empty(); - ServerResponse.ok().body(mono); + ServerResponse.ok().syncBody(mono); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java index 86a9278ae2..29e62edbcf 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java @@ -81,11 +81,11 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati private static class NestedHandler { public Mono bar(ServerRequest request) { - return ServerResponse.ok().body("bar"); + return ServerResponse.ok().syncBody("bar"); } public Mono baz(ServerRequest request) { - return ServerResponse.ok().body("baz"); + return ServerResponse.ok().syncBody("baz"); } public Mono variables(ServerRequest request) {