Search in sources :

Example 1 with Response

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());
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 2 with Response

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());
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) Request(org.asynchttpclient.Request) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 3 with Response

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);
}
Also used : Response(org.asynchttpclient.Response) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) TestSubscriber(rx.observers.TestSubscriber) AsyncCompletionHandlerBase(org.asynchttpclient.AsyncCompletionHandlerBase) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 4 with Response

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);
}
Also used : Response(org.asynchttpclient.Response) Request(org.asynchttpclient.Request)

Example 5 with Response

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);
    }
}
Also used : Response(org.asynchttpclient.Response) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Aggregations

Response (org.asynchttpclient.Response)142 Test (org.testng.annotations.Test)85 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)79 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)55 HttpServletResponse (javax.servlet.http.HttpServletResponse)42 BoundRequestBuilder (org.asynchttpclient.BoundRequestBuilder)32 Request (org.asynchttpclient.Request)29 IOException (java.io.IOException)21 Test (org.junit.Test)20 ExecutionException (java.util.concurrent.ExecutionException)16 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)14 RESTPubSubTest.getOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse)11 TimeoutException (java.util.concurrent.TimeoutException)11 RequestBuilder (org.asynchttpclient.RequestBuilder)11 UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)10 RESTPubSubTest.getNotOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Map (java.util.Map)9 AuthorizationException (org.apache.shiro.authz.AuthorizationException)9 TestUtils.createTempFile (org.asynchttpclient.test.TestUtils.createTempFile)9