Package org.asynchttpclient

Examples of org.asynchttpclient.AsyncHttpClient.executeRequest()


    public void asyncStatusHEADTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            final CountDownLatch l = new CountDownLatch(1);
            Request request = new RequestBuilder("HEAD").setUrl(getTargetUrl()).build();
            Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    try {
                        assertEquals(response.getStatusCode(), 200);
View Full Code Here


        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeout(120 * 1000).build());
        try {
            final CountDownLatch l = new CountDownLatch(1);
            Request request = new RequestBuilder("HEAD").setUrl(getTargetUrl()).build();

            client.executeRequest(request, new AsyncCompletionHandlerAdapter() {
                @Override
                public Response onCompleted(Response response) throws Exception {
                    fail();
                    return response;
                }
View Full Code Here

            for (int i = 0; i < 5; i++) {
                m.put("param_" + i, Arrays.asList("value_" + i));
            }
            Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setFormParams(m).setVirtualHost("localhost:" + port1).build();

            Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get();

            assertEquals(response.getStatusCode(), 200);
            if (response.getHeader("X-Host").startsWith("localhost")) {
                assertEquals(response.getHeader("X-Host"), "localhost:" + port1);
            } else {
View Full Code Here

                        generator.setMaxPendingBytes(10000);

                        RequestBuilder builder = new RequestBuilder("POST");
                        builder.setUrl(scheme + "://localhost:" + port + "/test");
                        builder.setBody(generator);
                        client.executeRequest(builder.build(), new AsyncCompletionHandler<org.asynchttpclient.Response>() {
                            @Override
                            public org.asynchttpclient.Response onCompleted(org.asynchttpclient.Response response) throws Exception {
                                try {
                                    totalsReceived[idx] = Integer.parseInt(response.getHeader("x-total"));
                                } catch (Exception e) {
View Full Code Here

                        generator.setMaxPendingBytes(10000);

                        RequestBuilder builder = new RequestBuilder("POST");
                        builder.setUrl(scheme + "://localhost:" + port + "/test");
                        builder.setBody(generator);
                        client.executeRequest(builder.build(), new AsyncCompletionHandler<org.asynchttpclient.Response>() {
                            @Override
                            public org.asynchttpclient.Response onCompleted(org.asynchttpclient.Response response) throws Exception {
                                try {
                                    totalsReceived[idx] = Integer.parseInt(response.getHeader("x-total"));
                                } catch (Exception e) {
View Full Code Here

            RequestBuilder requestBuilder = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeader("Content-Type", "message/rfc822");

            requestBuilder.setBody(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())));

            Future<Response> future = client.executeRequest(requestBuilder.build());

            System.out.println("waiting for response");
            Response response = future.get();
            assertEquals(response.getStatusCode(), 200);
            assertEquals(response.getResponseBody(), MY_MESSAGE);
View Full Code Here

            builder.addBodyPart(new ByteArrayPart("file4", expectedContents.getBytes(UTF_8), "text/plain", UTF_8, "bytearray.txt"));

            Request r = builder.build();

            Response res = c.executeRequest(r).get();

            assertEquals(res.getStatusCode(), 200);

            testSentFile(expected, testFiles, res, gzipped);
View Full Code Here

        AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRealm(realmBuilder.build()).build();

        AsyncHttpClient client = getAsyncHttpClient(config);
        try {
            Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build();
            Future<Response> responseFuture = client.executeRequest(request);
            int status = responseFuture.get().getStatusCode();
            Assert.assertEquals(status, 200);
        } finally {
            client.close();
        }
View Full Code Here

            final AtomicBoolean err = new AtomicBoolean(false);
            final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();
            final AtomicBoolean status = new AtomicBoolean(false);
            final AtomicInteger headers = new AtomicInteger(0);
            final CountDownLatch latch = new CountDownLatch(1);
            ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build(), new AsyncHandler<Object>() {
                public void onThrowable(Throwable t) {
                    fail("Got throwable.", t);
                    err.set(true);
                }
View Full Code Here

    // FIXME not sure that's threadsafe
    public void clean() throws InterruptedException, Exception {
        AsyncHttpClient c = getAsyncHttpClient(null);
        try {
            Request deleteRequest = new RequestBuilder("DELETE").setUrl(getTargetUrl()).build();
            c.executeRequest(deleteRequest).get();
        } finally {
            c.close();
        }
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.