use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class InputStreamPartLargeFileTest method testPutImageFileUnknownSize.
@Test
public void testPutImageFileUnknownSize() throws Exception {
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
InputStream inputStream = new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE));
Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, LARGE_IMAGE_FILE.getName(), -1, "application/octet-stream", UTF_8)).execute().get();
assertEquals(response.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class InputStreamPartLargeFileTest method testPutLargeTextFile.
@Test
public void testPutLargeTextFile() throws Exception {
File file = createTempFile(1024 * 1024);
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, file.getName(), file.length(), "application/octet-stream", UTF_8)).execute().get();
assertEquals(response.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class AsyncHttpTest method testPromiseAdapter.
public void testPromiseAdapter() throws IOException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger successCount = new AtomicInteger();
final AtomicInteger progressCount = new AtomicInteger();
try (AsyncHttpClient client = asyncHttpClient()) {
Promise<Response, Throwable, HttpProgress> p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://gatling.io"));
p1.done(new DoneCallback<Response>() {
@Override
public void onDone(Response response) {
try {
assertEquals(response.getStatusCode(), 200);
successCount.incrementAndGet();
} finally {
latch.countDown();
}
}
}).progress(new ProgressCallback<HttpProgress>() {
@Override
public void onProgress(HttpProgress progress) {
progressCount.incrementAndGet();
}
});
latch.await();
assertTrue(progressCount.get() > 0);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class AsyncHttpTest method testMultiplePromiseAdapter.
public void testMultiplePromiseAdapter() throws IOException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger successCount = new AtomicInteger();
try (AsyncHttpClient client = asyncHttpClient()) {
Promise<Response, Throwable, HttpProgress> p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://gatling.io"));
Promise<Response, Throwable, HttpProgress> p2 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.google.com"));
AsyncHttpDeferredObject deferredRequest = new AsyncHttpDeferredObject(client.prepareGet("http://jdeferred.org"));
deferredManager.when(p1, p2, deferredRequest).then(new DoneCallback<MultipleResults>() {
@Override
public void onDone(MultipleResults result) {
try {
assertEquals(result.size(), 3);
assertEquals(Response.class.cast(result.get(0).getResult()).getStatusCode(), 200);
assertEquals(Response.class.cast(result.get(1).getResult()).getStatusCode(), 200);
assertEquals(Response.class.cast(result.get(2).getResult()).getStatusCode(), 200);
successCount.incrementAndGet();
} finally {
latch.countDown();
}
}
});
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class InputStreamTest method testInvalidInputStream.
@Test
public void testInvalidInputStream() throws IOException, ExecutionException, InterruptedException {
try (AsyncHttpClient c = asyncHttpClient()) {
HttpHeaders h = new DefaultHttpHeaders().add(CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
InputStream is = new InputStream() {
int readAllowed;
@Override
public int available() {
// Fake
return 1;
}
@Override
public int read() {
int fakeCount = readAllowed++;
if (fakeCount == 0) {
return (int) 'a';
} else if (fakeCount == 1) {
return (int) 'b';
} else if (fakeCount == 2) {
return (int) 'c';
} else {
return -1;
}
}
};
Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("X-Param"), "abc");
}
}
Aggregations