Package org.asynchttpclient

Examples of org.asynchttpclient.Response


            Future<Response> f = client.preparePost(getTargetUrl())//
                    .setBody(SIMPLE_TEXT_FILE)//
                    .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())//
                    .execute();

            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertNotNull(resp.getHeader("X-Auth"));
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
        } finally {
            client.close();
        }
    }
View Full Code Here


                .setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build();
        try {
            StringBuilder s = new StringBuilder();
            Future<Response> future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s));

            Response response = future.get();
            assertEquals(response.getStatusCode(), 200);
            assertEquals(s.toString(), MY_MESSAGE);
            assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
            assertNotNull(response.getHeader("X-Auth"));
        } finally {
            client.close();
        }
    }
View Full Code Here

        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build());

            Future<Response> f = r.execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertNotNull(resp.getHeader("X-Auth"));
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
        } finally {
            client.close();
        }
    }
View Full Code Here

    protected void execute(String body) throws IOException, InterruptedException, ExecutionException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(body).setBodyEncoding(UTF_8.name());
            Future<Response> f = r.execute();
            Response resp = f.get();
            assertEquals(resp.getStatusCode(), 200);
            assertEquals(body, resp.getResponseBody(UTF_8.name()));
        } finally {
            client.close();
        }
    }
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);

            c.close();
        } catch (Exception e) {
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void Expect100Continue() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Future<Response> f = client.preparePut("http://127.0.0.1:" + port1 + "/").setHeader("Expect", "100-continue").setBody(SIMPLE_TEXT_FILE).execute();
            Response resp = f.get();
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
        } finally {
            client.close();
        }
    }
View Full Code Here

            for (String url : urls) {
                final String thisUrl = url;
                client.prepareGet(url).execute(new AsyncCompletionHandlerBase() {
                    @Override
                    public Response onCompleted(Response response) throws Exception {
                        Response r = super.onCompleted(response);
                        latch.countDown();
                        return r;
                    }

                    @Override
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void closeConnectionTest() throws Exception {
        AsyncHttpClient c = getAsyncHttpClient(null);
        try {
            Response r = c.prepareGet(getTargetUrl()).execute(new AsyncHandler<Response>() {

                private Response.ResponseBuilder builder = new Response.ResponseBuilder();

                public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
                    builder.accumulate(content);
                    return STATE.CONTINUE;
                }

                public void onThrowable(Throwable t) {
                }

                public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
                    builder.accumulate(content);

                    if (content.isLast()) {
                        content.markUnderlyingConnectionAsToBeClosed();
                    }
                    return STATE.CONTINUE;
                }

                public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
                    builder.accumulate(responseStatus);

                    return STATE.CONTINUE;
                }

                public Response onCompleted() throws Exception {
                    return builder.build();
                }
            }).get();

            assertNotNull(r);
            assertEquals(r.getStatusCode(), 200);
        } finally {
            c.close();
        }
    }
View Full Code Here

        AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder();
        b.addRequestFilter(new ThrottleRequestFilter(100));

        AsyncHttpClient c = getAsyncHttpClient(b.build());
        try {
            Response response = c.preparePost(getTargetUrl()).execute().get();
            assertNotNull(response);
            assertEquals(response.getStatusCode(), 200);
        } finally {
            c.close();
        }
    }
View Full Code Here

            for (int i = 0; i < 200; i++) {
                futures.add(c.preparePost(getTargetUrl()).execute());
            }

            for (Future<Response> f : futures) {
                Response r = f.get();
                assertNotNull(f.get());
                assertEquals(r.getStatusCode(), 200);
            }
        } 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.