Support Void response body type in WebClient
This commit adds support for Void response body types in the WebClient, both when using `exchange` with a response.bodyToMono(Void.class), as well as using `retrieve` with `toEntity(Void.class)`. Issue: SPR-15679
This commit is contained in:
@@ -52,12 +52,10 @@ public class WebClientIntegrationTests {
|
||||
|
||||
private WebClient webClient;
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.server = new MockWebServer();
|
||||
baseUrl = this.server.url("/").toString();
|
||||
String baseUrl = this.server.url("/").toString();
|
||||
this.webClient = WebClient.create(baseUrl);
|
||||
}
|
||||
|
||||
@@ -468,6 +466,35 @@ public class WebClientIntegrationTests {
|
||||
Assert.assertEquals(2, server.getRequestCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchangeNoContent() throws Exception {
|
||||
this.server.enqueue(new MockResponse().setHeader("Content-Length", "0"));
|
||||
|
||||
Mono<ClientResponse> result = this.webClient.get()
|
||||
.uri("/noContent")
|
||||
.exchange();
|
||||
|
||||
StepVerifier.create(result).assertNext(r -> {
|
||||
assertTrue(r.statusCode().is2xxSuccessful());
|
||||
StepVerifier.create(r.bodyToMono(Void.class)).verifyComplete();
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveNoContent() throws Exception {
|
||||
this.server.enqueue(new MockResponse().setHeader("Content-Length", "0"));
|
||||
|
||||
Mono<ResponseEntity<Void>> result = this.webClient.get()
|
||||
.uri("/noContent")
|
||||
.retrieve()
|
||||
.toEntity(Void.class);
|
||||
|
||||
StepVerifier.create(result).assertNext(r -> {
|
||||
assertFalse(r.hasBody());
|
||||
assertTrue(r.getStatusCode().is2xxSuccessful());
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class MyException extends RuntimeException {
|
||||
|
||||
Reference in New Issue
Block a user