'Spring Webclient block() method executing forever not returning value

I am working on oauth implementation, by following the https://developer.okta.com/blog/2021/05/05/client-credentials-spring-security

It's a test client, I am getting the access token, but after calling actual end point with access token not working block() method not at all giving value. It's executing forever. Actual backend return String as return type

This is my code snippet

@RestController
@RequestMapping("/locations")
public class LocationController {

    private Logger log = LoggerFactory.getLogger(LocationController.class);

    @Autowired
    private WebClient webClient;

    @GetMapping(value = "/location", produces = {MediaType.APPLICATION_PROBLEM_JSON_VALUE })
    public String getLocation() throws ValidationException {
        log.info("Inside get location method");
      
        String location = "";
        try{
            location = webClient.get()
                    .uri("https://locationservice/rest/v1/123")
                    .retrieve().bodyToMono(String.class).block();
            
        }catch (Exception r) {
            log.error(r.getLocalizedMessage());
            location = r.getMessage();
        }
        return location;

    }
}

Can somebody please help me Am I missing something? Thanks !!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source