use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class PutLargeFileTest method testPutLargeFile.
@Test(groups = "standalone")
public void testPutLargeFile() throws Exception {
File file = createTempFile(1024 * 1024);
int timeout = (int) file.length() / 1000;
try (AsyncHttpClient client = asyncHttpClient(config().setConnectTimeout(timeout))) {
Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get();
assertEquals(response.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ZeroCopyFileTest method zeroCopyFileTest.
@Test(groups = "standalone")
public void zeroCopyFileTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException {
File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt");
tmp.deleteOnExit();
try (AsyncHttpClient client = asyncHttpClient()) {
try (FileOutputStream stream = new FileOutputStream(tmp)) {
Response resp = client.preparePost("http://localhost:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler<Response>() {
public void onThrowable(Throwable t) {
}
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
stream.write(bodyPart.getBodyPartBytes());
return State.CONTINUE;
}
public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
return State.CONTINUE;
}
public State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
return State.CONTINUE;
}
public Response onCompleted() throws Exception {
return null;
}
}).get();
assertNull(resp);
assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length());
}
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ZeroCopyFileTest method zeroCopyPutTest.
@Test(groups = "standalone")
public void zeroCopyPutTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException {
try (AsyncHttpClient client = asyncHttpClient()) {
Future<Response> f = client.preparePut("http://localhost:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute();
Response resp = f.get();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ZeroCopyFileTest method zeroCopyFileWithBodyManipulationTest.
@Test(groups = "standalone")
public void zeroCopyFileWithBodyManipulationTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException {
File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt");
tmp.deleteOnExit();
try (AsyncHttpClient client = asyncHttpClient()) {
try (FileOutputStream stream = new FileOutputStream(tmp)) {
Response resp = client.preparePost("http://localhost:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler<Response>() {
public void onThrowable(Throwable t) {
}
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
stream.write(bodyPart.getBodyPartBytes());
if (bodyPart.getBodyPartBytes().length == 0) {
return State.ABORT;
}
return State.CONTINUE;
}
public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
return State.CONTINUE;
}
public State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
return State.CONTINUE;
}
public Response onCompleted() throws Exception {
return null;
}
}).get();
assertNull(resp);
assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length());
}
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsTest method testConnectionDoesNotGetClosed.
@Test(groups = "standalone")
public void testConnectionDoesNotGetClosed() throws Exception {
// test that we can stream the same request multiple times
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
BoundRequestBuilder requestBuilder = client.preparePut(getTargetUrl()).setBody(LARGE_IMAGE_PUBLISHER);
Response response = requestBuilder.execute().get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
response = requestBuilder.execute().get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
Aggregations