SUPPORT-8660: Fix
This commit is contained in:
parent
4de1aa69d1
commit
d73fb2a7f0
1 changed files with 12 additions and 5 deletions
|
|
@ -60,7 +60,8 @@ public class WebDavClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Retryable(value = {IOException.class, InterruptedException.class}, backoff = @Backoff(delay = 500L))
|
||||
@Retryable(value = {IOException.class, InterruptedException.class},
|
||||
backoff = @Backoff(delay = 500L))
|
||||
public ResponseEntity<Resource> webDavDownloadFile(String url) {
|
||||
try {
|
||||
HttpClient httpClient = HttpClient.newBuilder()
|
||||
|
|
@ -74,20 +75,26 @@ public class WebDavClient {
|
|||
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create(url))
|
||||
.GET().build();
|
||||
|
||||
HttpResponse<InputStream> response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofInputStream());
|
||||
HttpResponse<InputStream> response = httpClient.send(httpRequest,
|
||||
HttpResponse.BodyHandlers.ofInputStream()
|
||||
);
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
InputStreamResource resource = new InputStreamResource(response.body());
|
||||
String encodedFilename = URLEncoder.encode(getFilenameFromUrl(url), StandardCharsets.UTF_8);
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFilename)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename*=UTF-8''" + encodedFilename
|
||||
)
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(resource);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
logger.error("Failed to download file: HTTP status code {}", response.statusCode());
|
||||
return ResponseEntity.status(response.statusCode()).build();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
}
|
||||
catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue