Package org.asynchttpclient

Examples of org.asynchttpclient.Response


                    }
                    return super.onStatusReceived(status);
                }

            });
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        } finally {
            client.close();
        }
    }
View Full Code Here


                    }
                    return super.onStatusReceived(status);
                }

            });
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        } finally {
            client.close();
        }
    }
View Full Code Here

        try {
            ByteArrayOutputStream o = new ByteArrayOutputStream(10);
            Future<Response> future = client.get(new OutputStreamBodyConsumer(o));

            System.out.println("waiting for response");
            Response response = future.get();
            assertEquals(response.getStatusCode(), 404);
            assertEquals(o.toString(), "");
            assertTrue(response.getResponseBody().startsWith("<html>"));
        } finally {
            client.close();
        }
    }
View Full Code Here

        try {
            ByteArrayOutputStream o = new ByteArrayOutputStream(10);
            Future<Response> future = client.get(new OutputStreamBodyConsumer(o));

            System.out.println("waiting for response");
            Response response = future.get();
            assertEquals(response.getStatusCode(), 404);
            assertEquals(o.toString(), "");
            assertEquals(response.getResponseBody(), "");
        } finally {
            client.close();
        }
    }
View Full Code Here

    public void testUnauthorizedWhileUploading() throws Exception {
        File file = createTempFile(1024 * 1024);

        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", UTF_8)).execute()
                    .get();
            assertEquals(response.getStatusCode(), 401);
        } finally {
            client.close();
        }
    }
View Full Code Here

    public void testRequestLevelProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            String target = "http://127.0.0.1:1234/";
            Future<Response> f = client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1)).execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getHeader("target"), "/");
        } finally {
            client.close();
        }
    }
View Full Code Here

        isSet.getAndSet(false);
        AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
        AsyncHttpClient c = getAsyncHttpClient(cg);

        try {
            Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get();

            assertNotNull(response);
            assertEquals(response.getStatusCode(), 200);

            String baseUrl = getBaseUrl(response.getUri());

            assertTrue(baseUrl.startsWith("http://www.google."), "response does not show redirection to a google subdomain, got " + baseUrl);
        } finally {
            c.close();
        }
View Full Code Here

        AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
        AsyncHttpClient c = getAsyncHttpClient(cg);

        // If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned.
        try {
            Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get();

            assertNotNull(response);
            assertEquals(response.getStatusCode(), 404);
        } catch (ExecutionException ex) {
            assertEquals(ex.getCause().getClass(), ConnectException.class);
        } finally {
            c.close();
        }
View Full Code Here

        AsyncHttpClient c = getAsyncHttpClient(cg);
        try {
            String redirectTarget = "/bar/test";
            String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();

            Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
            assertNotNull(response);
            assertEquals(response.getStatusCode(), 200);
            assertEquals(response.getUri().toString(), destinationUrl);

            logger.debug("{} was redirected to {}", redirectTarget, destinationUrl);
        } finally {
            c.close();
        }
View Full Code Here

        AsyncHttpClient c = getAsyncHttpClient(cg);
        try {
            String redirectTarget = "bar/test1";
            String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();

            Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
            assertNotNull(response);
            assertEquals(response.getStatusCode(), 200);
            assertEquals(response.getUri().toString(), destinationUrl);

            logger.debug("{} was redirected to {}", redirectTarget, destinationUrl);
        } finally {
            c.close();
        }
View Full Code Here

TOP

Related Classes of org.asynchttpclient.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.