Package org.asynchttpclient

Examples of org.asynchttpclient.AsyncHttpClient


        }
    }

    @Test(groups = { "online", "default_provider", "async" })
    public void asyncDoGetStreamAndBodyTest() throws Exception {
        final AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Response response = client.prepareGet("http://www.lemonde.fr").execute().get();
            assertEquals(response.getStatusCode(), 200);
        } finally {
            client.close();
        }
    }
View Full Code Here


        }
    }

    @Test(groups = { "online", "default_provider", "async" })
    public void asyncUrlWithoutPathTest() throws Exception {
        final AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Response response = client.prepareGet("http://www.lemonde.fr").execute().get();
            assertEquals(response.getStatusCode(), 200);
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "default_provider", "async" })
    public void optionsTest() throws Exception {
        final AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Response response = client.prepareOptions(getTargetUrl()).execute().get();

            assertEquals(response.getStatusCode(), 200);
            assertEquals(response.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE");
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "online", "default_provider" })
    public void testAwsS3() throws Exception {
        final AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get();
            if (response.getResponseBody() == null || response.getResponseBody().equals("")) {
                fail("No response Body");
            } else {
                assertEquals(response.getStatusCode(), 403);
            }
        } finally {
            client.close();
        }
    }
View Full Code Here

    }

    @Test(groups = { "online", "default_provider" })
    public void testAsyncHttpProviderConfig() throws Exception {

        final AsyncHttpClient client = getAsyncHttpClient(new Builder().setAsyncHttpClientProviderConfig(getProviderConfig()).build());
        try {
            Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get();
            if (response.getResponseBody() == null || response.getResponseBody().equals("")) {
                fail("No response Body");
            } else {
                assertEquals(response.getStatusCode(), 403);
            }
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void idleRequestTimeoutTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setPooledConnectionIdleTimeout(5000).setRequestTimeout(10000).build());
        try {
            FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap();
            h.add("Content-Type", "application/x-www-form-urlencoded");
            h.add("LockThread", "true");

            long t1 = millisTime();
            try {
                client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get();
                fail();
            } catch (Throwable ex) {
                final long elapsedTime = millisTime() - t1;
                System.out.println("EXPIRED: " + (elapsedTime));
                assertNotNull(ex.getCause());
                assertTrue(elapsedTime >= 10000 && elapsedTime <= 25000);
            }
        } finally {
            client.close();
        }
    }
View Full Code Here

    }

    @Test(groups = { "standalone", "default_provider", "async" })
    public void asyncDoPostCancelTest() throws Exception {

        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap();
            h.add("Content-Type", "application/x-www-form-urlencoded");
            h.add("LockThread", "true");
            StringBuilder sb = new StringBuilder();
            sb.append("LockThread=true");

            final AtomicReference<CancellationException> ex = new AtomicReference<CancellationException>();
            ex.set(null);
            try {
                Future<Response> future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() {

                    @Override
                    public void onThrowable(Throwable t) {
                        if (t instanceof CancellationException) {
                            ex.set((CancellationException) t);
                        }
                        t.printStackTrace();
                    }

                });

                future.cancel(true);
            } catch (IllegalStateException ise) {
                fail();
            }
            assertNotNull(ex.get());
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void getShouldAllowBody() throws IOException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            client.prepareGet(getTargetUrl()).setBody("Boo!").execute();
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" }, expectedExceptions = { NullPointerException.class })
    public void invalidUri() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build();
        } finally {
            client.close();
        }
    }
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void asyncHttpClientConfigBeanTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test"));
        try {
            Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get();
            assertEquals(200, response.getStatusCode());
        } finally {
            client.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.asynchttpclient.AsyncHttpClient

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.