EntryDownloader - files via RestTemplate
This commit is contained in:
@@ -2,12 +2,12 @@ package com.bayer.edam.migration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -18,6 +18,8 @@ import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.mam.Entry;
|
||||
@@ -115,7 +117,14 @@ public class EntryDownloader implements CommandLineRunner {
|
||||
else
|
||||
filenameToUse = download.fileName;
|
||||
|
||||
FileUtils.copyURLToFile(new URL(download.href), new File("E:\\" + entry.id + "\\" + filenameToUse), 4000, 240000);
|
||||
ResponseEntity<byte[]> response = restTemplate.exchange(download.href, HttpMethod.GET, entity, byte[].class);
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
Files.write(Paths.get("E:\\" + entry.id + "\\" + filenameToUse), response.getBody());
|
||||
}
|
||||
else {
|
||||
log.error(entry.id + ", " + response.getStatusCodeValue() + ", " + download.href);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
|
||||
Reference in New Issue
Block a user