Search in sources :

Example 16 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)

Example 17 with Response

use of org.asynchttpclient.Response 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 18 with Response

use of org.asynchttpclient.Response 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 19 with Response

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

Example 20 with Response

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

the class ProxyTest method testBothProxies.

@Test(groups = "standalone")
public void testBothProxies() throws IOException, ExecutionException, TimeoutException, InterruptedException {
    try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1 - 1)))) {
        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

Response (org.asynchttpclient.Response)90 Test (org.testng.annotations.Test)78 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)71 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)69 HttpServletResponse (javax.servlet.http.HttpServletResponse)42 Request (org.asynchttpclient.Request)14 RequestBuilder (org.asynchttpclient.RequestBuilder)14 IOException (java.io.IOException)12 ExecutionException (java.util.concurrent.ExecutionException)12 File (java.io.File)10 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 InputStreamBodyGenerator (org.asynchttpclient.request.body.generator.InputStreamBodyGenerator)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TestSubscriber (rx.observers.TestSubscriber)6 ArrayList (java.util.ArrayList)5