use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class WebDavBasicTest method propFindWebDavTest.
@Test(groups = "standalone")
public void propFindWebDavTest() throws InterruptedException, IOException, ExecutionException {
try (AsyncHttpClient c = asyncHttpClient()) {
Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build();
Response response = c.executeRequest(mkcolRequest).get();
assertEquals(response.getStatusCode(), 201);
Request putRequest = put(String.format("http://localhost:%s/folder1/Test.txt", port1)).setBody("this is a test").build();
response = c.executeRequest(putRequest).get();
assertEquals(response.getStatusCode(), 201);
Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(String.format("http://localhost:%s/folder1/Test.txt", port1)).build();
response = c.executeRequest(propFindRequest).get();
assertEquals(response.getStatusCode(), 207);
assertTrue(response.getResponseBody().contains("HTTP/1.1 200 OK"), "Got " + response.getResponseBody());
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class WebDavBasicTest method propFindCompletionHandlerWebDavTest.
@Test(groups = "standalone")
public void propFindCompletionHandlerWebDavTest() throws InterruptedException, IOException, ExecutionException {
try (AsyncHttpClient c = asyncHttpClient()) {
Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build();
Response response = c.executeRequest(mkcolRequest).get();
assertEquals(response.getStatusCode(), 201);
Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build();
WebDavResponse webDavResponse = c.executeRequest(propFindRequest, new WebDavCompletionHandlerBase<WebDavResponse>() {
/**
* {@inheritDoc}
*/
@Override
public void onThrowable(Throwable t) {
t.printStackTrace();
}
@Override
public WebDavResponse onCompleted(WebDavResponse response) throws Exception {
return response;
}
}).get();
assertEquals(webDavResponse.getStatusCode(), 207);
assertTrue(webDavResponse.getResponseBody().contains("HTTP/1.1 200 OK"), "Got " + response.getResponseBody());
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class AsyncHttpSingleTest method testAbort.
@Test(groups = "standalone")
public void testAbort() throws Exception {
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
try (AsyncHttpClient client = asyncHttpClient()) {
final Single<Response> underTest = AsyncHttpSingle.create(client.prepareGet("http://gatling.io"), () -> new AsyncCompletionHandlerBase() {
@Override
public State onStatusReceived(HttpResponseStatus status) {
return State.ABORT;
}
});
underTest.subscribe(subscriber);
subscriber.awaitTerminalEvent();
}
subscriber.assertTerminalEvent();
subscriber.assertNoErrors();
subscriber.assertCompleted();
subscriber.assertValue(null);
}
use of org.asynchttpclient.Response 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.Response in project async-http-client by AsyncHttpClient.
the class HttpsProxyTest method testConfigProxy.
@Test(groups = "standalone")
public void testConfigProxy() throws Exception {
AsyncHttpClientConfig config = //
config().setFollowRedirect(//
true).setProxyServer(//
proxyServer("localhost", port1).build()).setUseInsecureTrustManager(//
true).build();
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
Response r = asyncHttpClient.executeRequest(get(getTargetUrl2())).get();
assertEquals(r.getStatusCode(), 200);
}
}
Aggregations