diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index e72b41aaf585..dcfb734e7da9 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -455,14 +455,18 @@ private void logBody(Object body, @Nullable MediaType mediaType, HttpMessageConv @Override public ResponseSpec retrieve() { - return exchangeInternal(DefaultResponseSpec::new, false); + ResponseSpec responseSpec = exchangeInternal(DefaultResponseSpec::new, false); + Assert.state(responseSpec != null, "No ResponseSpec"); + return responseSpec; } @Override + @Nullable public T exchange(ExchangeFunction exchangeFunction, boolean close) { return exchangeInternal(exchangeFunction, close); } + @Nullable private T exchangeInternal(ExchangeFunction exchangeFunction, boolean close) { Assert.notNull(exchangeFunction, "ExchangeFunction must not be null"); diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClient.java b/spring-web/src/main/java/org/springframework/web/client/RestClient.java index 5d304c4207d9..0a1e98304a6e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClient.java @@ -561,6 +561,7 @@ interface RequestHeadersSpec> { * @param the type the response will be transformed to * @return the value returned from the exchange function */ + @Nullable default T exchange(ExchangeFunction exchangeFunction) { return exchange(exchangeFunction, true); } @@ -592,6 +593,7 @@ default T exchange(ExchangeFunction exchangeFunction) { * @param the type the response will be transformed to * @return the value returned from the exchange function */ + @Nullable T exchange(ExchangeFunction exchangeFunction, boolean close); @@ -609,6 +611,7 @@ interface ExchangeFunction { * @return the exchanged type * @throws IOException in case of I/O errors */ + @Nullable T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException; }