Advertisement
alexandrecoussy

Untitled

Aug 18th, 2022
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. public InstrumentDetailsDto getQuotations(final String instrument, ApiDetail api, String token) {
  2.  
  3.     Map<String, Object> vars = new HashMap<>();
  4.     vars.put("instrumentId", instrument);
  5.  
  6.     RequestHeadersSpec<?> request = mdiWebclient
  7.     .get()
  8.     .uri(mdiEndpointsGetQuotations, vars)
  9.     .header(HttpHeaders.AUTHORIZATION, token)
  10.     .accept(MediaType.APPLICATION_JSON);
  11.  
  12.     ResponseSpec response = request.retrieve();
  13.  
  14.     try {
  15.       InstrumentDetailsDto dto = response
  16.       .bodyToMono(InstrumentDetailsDto.class)
  17.       .onErrorResume(WebClientResponseException.class, ex -> Mono.error(ex))
  18.       .block(Duration.ofMinutes(5));
  19.       return dto;
  20.  
  21.     } catch (WebClientResponseException e) {
  22.  
  23.       if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
  24.         logger.error("reçu la réponse http HttpStatus.NOT_FOUND");
  25.         return null;
  26.       } else {
  27.         logger.error("le body retourné est : {}", e.getResponseBodyAsString());
  28.         return null;
  29.       }
  30.     }
  31.  
  32.   }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement