use of com.tvd12.ezyhttp.client.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToOutputStreamByRequestWithCancellationTokenTest.
@Test
public void downloadToOutputStreamByRequestWithCancellationTokenTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("hello", "world").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
File outFile = new File("test-output/no-commit/download-test.xml");
EzyFileUtil.createFileIfNotExists(outFile);
OutputStream outputStream = new FileOutputStream(outFile);
// when
sut.download(request, outputStream, new DownloadCancellationToken());
// then
Asserts.assertTrue(new File("test-output/no-commit/download-test.xml").exists());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToOutputStreamByRequestTest.
@Test
public void downloadToOutputStreamByRequestTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("hello", "world").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
File outFile = new File("test-output/no-commit/download-test.xml");
EzyFileUtil.createFileIfNotExists(outFile);
OutputStream outputStream = new FileOutputStream(outFile);
// when
sut.download(request, outputStream);
// then
Asserts.assertTrue(new File("test-output/no-commit/download-test.xml").exists());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class DownloadWithTokenTest method main.
public static void main(String[] args) throws Exception {
// given
String fileUrl = "http://localhost:8083/api/v1/files/ansible.jpg";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("token", "").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
String fileName = sut.download(request, new File("test-output/no-commit"));
System.out.println(fileName);
// then
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToFileByRequestTest.
@Test
public void downloadToFileByRequestTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("hello", "world").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
String fileName = sut.download(request, new File("test-output/no-commit"));
// then
Asserts.assertEquals(fileName, "ezy-settings-1.0.0.xsd");
Asserts.assertTrue(new File("test-output/no-commit/ezy-settings-1.0.0.xsd").exists());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class HttpClient method decorateConnection.
private void decorateConnection(HttpURLConnection connection, DownloadRequest request) {
int connectTimeout = request.getReadTimeout();
int readTimeout = request.getReadTimeout();
connection.setConnectTimeout(connectTimeout > 0 ? connectTimeout : defaultConnectTimeout);
connection.setReadTimeout(readTimeout > 0 ? readTimeout : defaultReadTimeout);
MultiValueMap requestHeaders = request.getHeaders();
if (requestHeaders != null) {
Map<String, String> encodedHeaders = requestHeaders.toMap();
for (Entry<String, String> requestHeader : encodedHeaders.entrySet()) {
connection.setRequestProperty(requestHeader.getKey(), requestHeader.getValue());
}
}
}
Aggregations