0

Folks,

My http endpoint returns CompletableFuture

@HttpEndpoint
public CompletableFuture<Student> processStudent(Request request){
       return CompletableFuture.supplyAsync(()->saveStudent(request));
}

My http client is

 studentCompletableFuture = restTemplate.postForObject(URL, request, CompletableFuture.class);
 Student student = studentCompletableFuture .get();

I am not able to get student back to the client .

I searched in google and stackoverflow and found that once we get CompletableFuture with placeholder (empty response) as response from server, http connection will be closed and we cannot apply get() to get the student data.

My rest endpoint should be async, how to get the actual student response back to client ?

Manoj Kalluri
  • 1,384
  • 2
  • 14
  • 27
  • I might be wrong, but I think `RestTemplate` was for synchronous calls only. You should use the newer `WebClient`. – Seelenvirtuose Dec 04 '20 at 15:23
  • go for spring reactive https://spring.io/reactive – Ryuzaki L Dec 04 '20 at 15:46
  • A bit late but I think this might be helpful as it explains how Spring deals with endpoints returning completablefuture. https://stackoverflow.com/questions/58505549/how-does-spring-get-the-result-from-an-endpoint-that-returns-completablefuture-o – cicada_ Aug 24 '22 at 10:51

0 Answers0