Advertisement
alexandrecoussy

Untitled

Aug 18th, 2022
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1.     try {
  2.       Map<String, String> vars = new HashMap<>();
  3.       vars.put("uuid", attachment.getUuid().toString());
  4.       final ResponseSpec response = getWebClient().get().uri(endpoint, vars).header(HttpHeaders.AUTHORIZATION, jsonWebToken).retrieve();
  5.       try (
  6.         WritableByteChannel channel = Channels.newChannel(new FileOutputStream(localFile));) {
  7.         Mono<Void> writeOperation = DataBufferUtils.write(response.bodyToFlux(DataBuffer.class), channel).map(DataBufferUtils::release).then();
  8.         writeOperation.block();
  9.       }
  10.     } catch (WebClientResponseException e) {
  11.       logger.warn("Download attachment returned with status code {}", e.getStatusCode());
  12.       logger.debug("Call failed with exception : ", e);
  13.       if (logger.isDebugEnabled()) {
  14.         logger.debug("Response was [{}]", e.getResponseBodyAsString());
  15.       }
  16.       throw new IOException("Failed to download attachment : " + e.getMessage());
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement