diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java index 81e3758b9b1f..b6307045b8c6 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java @@ -324,7 +324,7 @@ else if (actualType.equals(ResponseEntity.class)) { responseFunction = initBodyFunction(client, actualParam, reactiveAdapter); } - boolean blockForOptional = actualType.equals(Optional.class); + boolean blockForOptional = returnType.equals(Optional.class); return new ResponseFunction(responseFunction, reactiveAdapter, blockForOptional, blockTimeout); } diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java index f61bbbd82c45..2802a1ed01f7 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java @@ -16,6 +16,8 @@ package org.springframework.web.service.invoker; +import java.util.Optional; + import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; @@ -131,6 +133,9 @@ void blockingService() { String body = service.getBody(); assertThat(body).isEqualTo("requestToBody"); + Optional optional = service.getBodyOptional(); + assertThat(optional).isEqualTo(Optional.of("requestToBody")); + ResponseEntity entity = service.getEntity(); assertThat(entity.getBody()).isEqualTo("requestToEntity"); @@ -252,6 +257,9 @@ private interface BlockingService { @GetExchange String getBody(); + @GetExchange + Optional getBodyOptional(); + @GetExchange ResponseEntity getVoidEntity();