use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class BodyChunkTest method negativeContentTypeTest.
@Test(groups = "standalone")
public void negativeContentTypeTest() throws Exception {
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
100).setMaxConnections(//
50).setRequestTimeout(// 5 minutes
5 * 60 * 1000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
RequestBuilder requestBuilder = //
post(getTargetUrl()).setHeader("Content-Type", //
"message/rfc822").setBody(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())));
Future<Response> future = client.executeRequest(requestBuilder.build());
System.out.println("waiting for response");
Response response = future.get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBody(), MY_MESSAGE);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ChunkingTest method doTestWithInputStreamBodyGenerator.
public void doTestWithInputStreamBodyGenerator(InputStream is) throws Throwable {
try (AsyncHttpClient c = asyncHttpClient(httpClientBuilder())) {
RequestBuilder builder = post(getTargetUrl()).setBody(new InputStreamBodyGenerator(is));
Request r = builder.build();
final ListenableFuture<Response> responseFuture = c.executeRequest(r);
waitForAndAssertResponse(responseFuture);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ChunkingTest method waitForAndAssertResponse.
private void waitForAndAssertResponse(ListenableFuture<Response> responseFuture) throws InterruptedException, java.util.concurrent.ExecutionException, IOException {
Response response = responseFuture.get();
if (500 == response.getStatusCode()) {
StringBuilder sb = new StringBuilder();
sb.append("==============\n");
sb.append("500 response from call\n");
sb.append("Headers:" + response.getHeaders() + "\n");
sb.append("==============\n");
logger.debug(sb.toString());
assertEquals(response.getStatusCode(), 500, "Should have 500 status code");
assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking");
fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception"));
} else {
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class EmptyBodyTest method testPutEmptyBody.
@Test(groups = "standalone")
public void testPutEmptyBody() throws Exception {
try (AsyncHttpClient ahc = asyncHttpClient()) {
Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get();
assertNotNull(response);
assertEquals(response.getStatusCode(), 204);
assertEquals(response.getResponseBody(), "");
assertTrue(response.getResponseBodyAsStream() instanceof InputStream);
assertEquals(response.getResponseBodyAsStream().read(), -1);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class FastUnauthorizedUploadTest method testUnauthorizedWhileUploading.
@Test(groups = "standalone")
public void testUnauthorizedWhileUploading() throws Exception {
File file = createTempFile(1024 * 1024);
try (AsyncHttpClient client = asyncHttpClient()) {
Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", UTF_8)).execute().get();
assertEquals(response.getStatusCode(), 401);
}
}
Aggregations