use of org.asynchttpclient.AsyncHttpClient 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.AsyncHttpClient 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.AsyncHttpClient 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.AsyncHttpClient 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);
}
}
use of org.asynchttpclient.AsyncHttpClient in project camel by apache.
the class WebsocketComponentRouteExampleTest method testWSHttpCall.
@Test
public void testWSHttpCall() throws Exception {
AsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://localhost:" + port + "/echo").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
received.add(message);
log.info("received --> " + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
websocket.sendMessage("Beer");
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(1, received.size());
assertEquals("BeerBeer", received.get(0));
websocket.close();
c.close();
}
Aggregations