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
This commit is contained in:
Arjen Poutsma
2017-04-24 17:15:33 +02:00
parent 6a1ce13ae2
commit b9dbac7b2c
12 changed files with 22 additions and 25 deletions

View File

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

View File

@@ -450,7 +450,7 @@ public interface WebClient {
RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> inserter);
/**
* Set the body of the request to the given {@code Publisher}.
* Set the body of the request to the given asynchronous {@code Publisher}.
* <p>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 {
<T, P extends Publisher<T>> RequestHeadersSpec<?> body(P publisher, Class<T> elementClass);
/**
* Set the body of the request to the given {@code Object}.
* Set the body of the request to the given synchronous {@code Object}.
* <p>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);
}

View File

@@ -189,7 +189,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
}
@Override
public Mono<ServerResponse> body(Object body) {
public Mono<ServerResponse> 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)");

View File

@@ -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 {
<T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher, Class<T> 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<ServerResponse> body(Object body);
Mono<ServerResponse> syncBody(Object body);
/**
* Set the body of the response to the given {@code BodyInserter} and return it.

View File

@@ -121,7 +121,7 @@ public class DefaultWebClientTests {
Mono<Void> mono = Mono.empty();
WebClient client = builder().build();
client.post().uri("http://example.com").body(mono);
client.post().uri("http://example.com").syncBody(mono);
}

View File

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

View File

@@ -298,7 +298,7 @@ public class DefaultServerResponseBuilderTests {
public void bodyObjectPublisher() throws Exception {
Mono<Void> mono = Mono.empty();
ServerResponse.ok().body(mono);
ServerResponse.ok().syncBody(mono);
}

View File

@@ -81,11 +81,11 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
private static class NestedHandler {
public Mono<ServerResponse> bar(ServerRequest request) {
return ServerResponse.ok().body("bar");
return ServerResponse.ok().syncBody("bar");
}
public Mono<ServerResponse> baz(ServerRequest request) {
return ServerResponse.ok().body("baz");
return ServerResponse.ok().syncBody("baz");
}
public Mono<ServerResponse> variables(ServerRequest request) {