0

I am able to convert WebClient response to Response Entity with exchange() method which is deprecated now.

Please suggest other way of achieving the same result. Below is my code.

public ResponseEntity<TestClass> getTestDetails() {
            ClientResponse clientResponse = webClientBuilder.build()
                    .get()
                    .uri("http://localhost:9090/test")
                    .headers(httpHeaders -> {
                        httpHeaders.add(Constants.ACCEPT, Constants.APPLICATION_JSON);
                        })
                    .exchange()
                    .block();
            
            return clientResponse.toEntity(TestClass.class).block();
}
Ash
  • 137
  • 1
  • 3
  • 12
  • its in the documentation https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client-exchange – Toerktumlare Jun 14 '21 at 19:27
  • Does this answer your question? [Spring WebFlux 5.3.0 - WebClient.exchangeToMono()](https://stackoverflow.com/questions/64650820/spring-webflux-5-3-0-webclient-exchangetomono) – Toerktumlare Jun 14 '21 at 19:28

1 Answers1

5

I did it in the following way:

   public ResponseEntity<TestClass> getTestDetails() {
        return webClientBuilder.build()
                .get()
                .uri("http://localhost:9090/test")
                .headers(httpHeaders -> {
                    httpHeaders.add(Constants.ACCEPT, Constants.APPLICATION_JSON);
                    })
                .retrieve()
                .toEntity(TestClass.class)
                .block();
    }
Ash
  • 137
  • 1
  • 3
  • 12