Search in sources :

Example 41 with AsyncHttpClient

use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.

the class ReactiveStreamsDownLoadTest method streamedResponseLargeFileTest.

@Test(groups = "standalone")
public void streamedResponseLargeFileTest() throws Throwable {
    try (AsyncHttpClient c = asyncHttpClient()) {
        String largeFileName = "http://localhost:" + serverPort + "/" + largeFile.getName();
        ListenableFuture<SimpleStreamedAsyncHandler> future = c.prepareGet(largeFileName).execute(new SimpleStreamedAsyncHandler());
        byte[] result = future.get().getBytes();
        assertEquals(result.length, largeFile.length());
    }
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 42 with AsyncHttpClient

use of org.asynchttpclient.AsyncHttpClient 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)

Example 43 with AsyncHttpClient

use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.

the class NTLMProxyTest method ntlmProxyTest.

@Test(groups = "standalone")
public void ntlmProxyTest() throws IOException, InterruptedException, ExecutionException {
    try (AsyncHttpClient client = asyncHttpClient()) {
        Request request = get("http://localhost").setProxyServer(ntlmProxy()).build();
        Future<Response> responseFuture = client.executeRequest(request);
        int status = responseFuture.get().getStatusCode();
        Assert.assertEquals(status, 200);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) Request(org.asynchttpclient.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 44 with AsyncHttpClient

use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.

the class ProxyTest method testRequestNonProxyHost.

@Test(groups = "standalone")
public void testRequestNonProxyHost() throws IOException, ExecutionException, TimeoutException, InterruptedException {
    ProxyServer proxy = proxyServer("localhost", port1 - 1).setNonProxyHost("localhost").build();
    try (AsyncHttpClient client = asyncHttpClient()) {
        String target = "http://localhost:" + port1 + "/";
        Future<Response> f = client.prepareGet(target).setProxyServer(proxy).execute();
        Response resp = f.get(3, TimeUnit.SECONDS);
        assertNotNull(resp);
        assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        assertEquals(resp.getHeader("target"), "/");
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 45 with AsyncHttpClient

use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.

the class ProxyTest method testRequestLevelProxy.

// @Test
// public void asyncDoPostProxyTest() throws Throwable {
// try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port2).build()))) {
// HttpHeaders h = new DefaultHttpHeaders();
// h.add(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED);
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < 5; i++) {
// sb.append("param_").append(i).append("=value_").append(i).append("&");
// }
// sb.setLength(sb.length() - 1);
//
// Response response = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandler<Response>() {
// @Override
// public Response onCompleted(Response response) throws Throwable {
// return response;
// }
//
// @Override
// public void onThrowable(Throwable t) {
// }
// }).get();
//
// assertEquals(response.getStatusCode(), 200);
// assertEquals(response.getHeader("X-" + CONTENT_TYPE), APPLICATION_X_WWW_FORM_URLENCODED);
// }
// }
@Test(groups = "standalone")
public void testRequestLevelProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
    try (AsyncHttpClient client = asyncHttpClient()) {
        String target = "http://localhost:1234/";
        Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
        Response resp = f.get(3, TimeUnit.SECONDS);
        assertNotNull(resp);
        assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        assertEquals(resp.getHeader("target"), "/");
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Aggregations

AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)146 Test (org.testng.annotations.Test)119 Response (org.asynchttpclient.Response)71 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)66 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 CountDownLatch (java.util.concurrent.CountDownLatch)31 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)26 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 RequestBuilder (org.asynchttpclient.RequestBuilder)16 IOException (java.io.IOException)14 RouteBuilder (org.apache.camel.builder.RouteBuilder)14 ExecutionException (java.util.concurrent.ExecutionException)13 Request (org.asynchttpclient.Request)13 WebSocket (org.asynchttpclient.ws.WebSocket)12 Test (org.junit.Test)11 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)10 File (java.io.File)9 WebSocketTextListener (org.asynchttpclient.ws.WebSocketTextListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7