Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Created November 24, 2022 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/91edf0a6030b0d6292827d0f7b7f1112 to your computer and use it in GitHub Desktop.
Save eliasnogueira/91edf0a6030b0d6292827d0f7b7f1112 to your computer and use it in GitHub Desktop.
[JavaAdvent] Method that connects to the Restriction API and return the appropriate result
private void checkForRestriction(String cpf) throws SimulationException {
RestTemplate template = new RestTemplateBuilder().errorHandler(new RestTemplateErrorHandler()).build();
String restrictionsEndpoint = String.format("%s:%s%s", env.getProperty("restrictions.host"),
env.getProperty("restrictions.port"), env.getProperty("restrictions.path"));
var response = template.getForObject(restrictionsEndpoint, MessageDto.class, cpf);
if (response != null) throw new ResponseStatusException(HttpStatus.FORBIDDEN, response.message());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment