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:
@@ -274,7 +274,7 @@ class DefaultWebTestClient implements WebTestClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> RequestHeadersSpec<?> body(BodyInserter<T, ? super ClientHttpRequest> inserter) {
|
public RequestHeadersSpec<?> body(BodyInserter<?, ? super ClientHttpRequest> inserter) {
|
||||||
this.bodySpec.body(inserter);
|
this.bodySpec.body(inserter);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -286,8 +286,8 @@ class DefaultWebTestClient implements WebTestClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> RequestHeadersSpec<?> body(T body) {
|
public RequestHeadersSpec<?> syncBody(Object body) {
|
||||||
this.bodySpec.body(body);
|
this.bodySpec.syncBody(body);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -458,14 +458,13 @@ public interface WebTestClient {
|
|||||||
/**
|
/**
|
||||||
* Set the body of the request to the given {@code BodyInserter}.
|
* Set the body of the request to the given {@code BodyInserter}.
|
||||||
* @param inserter the inserter
|
* @param inserter the inserter
|
||||||
* @param <T> the body type or the element type (for a stream)
|
|
||||||
* @return spec for decoding the response
|
* @return spec for decoding the response
|
||||||
* @see org.springframework.web.reactive.function.BodyInserters
|
* @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 publisher the request body data
|
||||||
* @param elementClass the class of elements contained in the publisher
|
* @param elementClass the class of elements contained in the publisher
|
||||||
* @param <T> the type of the 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);
|
<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.
|
* perform the request.
|
||||||
* @param body the {@code Object} to write to 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
|
* @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 org.junit.Test;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -64,7 +63,7 @@ public class JsonContentTests {
|
|||||||
public void postJsonContent() throws Exception {
|
public void postJsonContent() throws Exception {
|
||||||
this.client.post().uri("/persons")
|
this.client.post().uri("/persons")
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||||
.body("{\"name\":\"John\"}")
|
.syncBody("{\"name\":\"John\"}")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isCreated()
|
.expectStatus().isCreated()
|
||||||
.expectBody().isEmpty();
|
.expectBody().isEmpty();
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class ResponseEntityTests {
|
|||||||
@Test
|
@Test
|
||||||
public void postEntity() throws Exception {
|
public void postEntity() throws Exception {
|
||||||
this.client.post().uri("/persons")
|
this.client.post().uri("/persons")
|
||||||
.body(new Person("John"))
|
.syncBody(new Person("John"))
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isCreated()
|
.expectStatus().isCreated()
|
||||||
.expectHeader().valueEquals("location", "/persons/John")
|
.expectHeader().valueEquals("location", "/persons/John")
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ class DefaultWebClient implements WebClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestHeadersSpec<?> body(Object body) {
|
public RequestHeadersSpec<?> syncBody(Object body) {
|
||||||
Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by " +
|
Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by " +
|
||||||
"using body(Publisher, Class)");
|
"using body(Publisher, Class)");
|
||||||
|
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ public interface WebClient {
|
|||||||
RequestHeadersSpec<?> body(BodyInserter<?, ? 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}.
|
||||||
* <p>This method is a convenient shortcut for {@link #body(BodyInserter)} with a
|
* <p>This method is a convenient shortcut for {@link #body(BodyInserter)} with a
|
||||||
* {@linkplain org.springframework.web.reactive.function.BodyInserters#fromPublisher}
|
* {@linkplain org.springframework.web.reactive.function.BodyInserters#fromPublisher}
|
||||||
* Publisher body inserter}.
|
* Publisher body inserter}.
|
||||||
@@ -463,14 +463,14 @@ public interface WebClient {
|
|||||||
<T, P extends Publisher<T>> RequestHeadersSpec<?> body(P publisher, Class<T> elementClass);
|
<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
|
* <p>This method is a convenient shortcut for {@link #body(BodyInserter)} with a
|
||||||
* {@linkplain org.springframework.web.reactive.function.BodyInserters#fromObject
|
* {@linkplain org.springframework.web.reactive.function.BodyInserters#fromObject
|
||||||
* Object body inserter}.
|
* Object body inserter}.
|
||||||
* @param body the {@code Object} to write to the request
|
* @param body the {@code Object} to write to the request
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
RequestHeadersSpec<?> body(Object body);
|
RequestHeadersSpec<?> syncBody(Object body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ServerResponse> body(Object body) {
|
public Mono<ServerResponse> syncBody(Object body) {
|
||||||
Assert.notNull(body, "'body' must not be null");
|
Assert.notNull(body, "'body' must not be null");
|
||||||
Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by using " +
|
Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by using " +
|
||||||
"body(Publisher, Class)");
|
"body(Publisher, Class)");
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ public interface ServerResponse {
|
|||||||
BodyBuilder hint(String key, Object value);
|
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
|
* This convenience method combines {@link #body(BodyInserter)} and
|
||||||
* {@link BodyInserters#fromPublisher(Publisher, Class)}.
|
* {@link BodyInserters#fromPublisher(Publisher, Class)}.
|
||||||
* @param publisher the {@code Publisher} to write to the response
|
* @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);
|
<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
|
* This convenience method combines {@link #body(BodyInserter)} and
|
||||||
* {@link BodyInserters#fromObject(Object)}.
|
* {@link BodyInserters#fromObject(Object)}.
|
||||||
* @param body the body of the response
|
* @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
|
* @throws IllegalArgumentException if {@code body} is a {@link Publisher}, for which
|
||||||
* {@link #body(Publisher, Class)} should be used.
|
* {@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.
|
* 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();
|
Mono<Void> mono = Mono.empty();
|
||||||
WebClient client = builder().build();
|
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")
|
.uri("/pojo/capitalize")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(new Pojo("foofoo", "barbar"))
|
.syncBody(new Pojo("foofoo", "barbar"))
|
||||||
.exchange()
|
.exchange()
|
||||||
.flatMap(response -> response.bodyToMono(Pojo.class));
|
.flatMap(response -> response.bodyToMono(Pojo.class));
|
||||||
|
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ public class DefaultServerResponseBuilderTests {
|
|||||||
public void bodyObjectPublisher() throws Exception {
|
public void bodyObjectPublisher() throws Exception {
|
||||||
Mono<Void> mono = Mono.empty();
|
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 {
|
private static class NestedHandler {
|
||||||
|
|
||||||
public Mono<ServerResponse> bar(ServerRequest request) {
|
public Mono<ServerResponse> bar(ServerRequest request) {
|
||||||
return ServerResponse.ok().body("bar");
|
return ServerResponse.ok().syncBody("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<ServerResponse> baz(ServerRequest request) {
|
public Mono<ServerResponse> baz(ServerRequest request) {
|
||||||
return ServerResponse.ok().body("baz");
|
return ServerResponse.ok().syncBody("baz");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<ServerResponse> variables(ServerRequest request) {
|
public Mono<ServerResponse> variables(ServerRequest request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user