1

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 !!!

Naveen Kocherla
  • 399
  • 9
  • 27
  • Instead of blocking, you could return `Mono` - calling a blocking operation in the controller kind of defeats the purpose of doing reactive programming in Spring. See this [blog post](https://spring.io/blog/2016/07/20/notes-on-reactive-programming-part-iii-a-simple-http-server-application) for example. – thinkgruen May 13 '22 at 10:51

0 Answers0