use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.
the class SimpleAsyncHttpClient method execute.
private Future<Response> execute(RequestBuilder rb, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException {
if (throwableHandler == null) {
throwableHandler = defaultThrowableHandler;
}
Request request = rb.build();
ProgressAsyncHandler<Response> handler = new BodyConsumerAsyncHandler(bodyConsumer, throwableHandler, errorDocumentBehaviour, request.getUri(), listener);
if (resumeEnabled && request.getMethod().equals("GET") && bodyConsumer != null && bodyConsumer instanceof ResumableBodyConsumer) {
ResumableBodyConsumer fileBodyConsumer = (ResumableBodyConsumer) bodyConsumer;
long length = fileBodyConsumer.getTransferredBytes();
fileBodyConsumer.resume();
handler = new ResumableBodyConsumerAsyncHandler(length, handler);
}
return getAsyncHttpClient().executeRequest(request, handler);
}
use of org.asynchttpclient.Request in project async-http-client by AsyncHttpClient.
the class HttpUtilsTest method testGetHostHeaderHasVirtualHost.
@Test
public void testGetHostHeaderHasVirtualHost() {
Request request = Dsl.get("http://stackoverflow.com/questions/1057564").setVirtualHost("example.com").build();
Uri uri = Uri.create("http://stackoverflow.com/questions/1057564/pretty-git-branch-graphs");
String hostHeader = HttpUtils.hostHeader(request, uri);
assertEquals(hostHeader, "example.com", "Incorrect hostHeader returned");
}
use of org.asynchttpclient.Request 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.Request in project camel by apache.
the class AhcProducer method process.
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
try {
// AHC supports async processing
Request request = getEndpoint().getBinding().prepareRequest(getEndpoint(), exchange);
log.debug("Executing request {} ", request);
client.prepareRequest(request).execute(new AhcAsyncHandler(exchange, callback, request.getUrl(), getEndpoint().getBufferSize()));
return false;
} catch (Exception e) {
exchange.setException(e);
callback.done(true);
return true;
}
}
use of org.asynchttpclient.Request in project tutorials by eugenp.
the class AsyncHttpClientTestCase method givenHttpClient_executeAsyncGetRequestWithListanableFuture.
@Test
public void givenHttpClient_executeAsyncGetRequestWithListanableFuture() {
// execute an unbound GET request
Request unboundGetRequest = Dsl.get("http://www.baeldung.com").build();
ListenableFuture<Response> listenableFuture = HTTP_CLIENT.executeRequest(unboundGetRequest);
listenableFuture.addListener(() -> {
Response response;
try {
response = listenableFuture.get(5000, TimeUnit.MILLISECONDS);
assertEquals(200, response.getStatusCode());
} catch (InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
}
}, Executors.newCachedThreadPool());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations