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:
parent
6a1ce13ae2
commit
b9dbac7b2c
|
@ -274,7 +274,7 @@ class DefaultWebTestClient implements WebTestClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> RequestHeadersSpec<?> body(BodyInserter<T, ? super ClientHttpRequest> inserter) {
|
||||
public RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> inserter) {
|
||||
this.bodySpec.body(inserter);
|
||||
return this;
|
||||
}
|
||||
|
@ -286,8 +286,8 @@ class DefaultWebTestClient implements WebTestClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> RequestHeadersSpec<?> body(T body) {
|
||||
this.bodySpec.body(body);
|
||||
public RequestHeadersSpec<?> syncBody(Object body) {
|
||||
this.bodySpec.syncBody(body);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -458,14 +458,13 @@ public interface WebTestClient {
|
|||
/**
|
||||
* Set the body of the request to the given {@code BodyInserter}.
|
||||
* @param inserter the inserter
|
||||
* @param <T> the body type or the element type (for a stream)
|
||||
* @return spec for decoding the response
|
||||
* @see org.springframework.web.reactive.function.BodyInserters
|
||||
*/
|
||||
<T> RequestHeadersSpec<?> body(BodyInserter<T, ? super ClientHttpRequest> inserter);
|
||||
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}.
|
||||
* @param publisher the request body data
|
||||
* @param elementClass the class of elements contained in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
|
@ -475,13 +474,12 @@ public interface WebTestClient {
|
|||
<T, S extends Publisher<T>> RequestHeadersSpec<?> body(S publisher, Class<T> 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 <T> the type contained in the body
|
||||
* @return a {@code Mono} with the response
|
||||
*/
|
||||
<T> RequestHeadersSpec<?> body(T body);
|
||||
RequestHeadersSpec<?> syncBody(Object body);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)");
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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)");
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue