Package org.asynchttpclient

Examples of org.asynchttpclient.AsyncHttpClient.preparePost()


            assertNotNull(cause);

            trusted.set(true);

            // second request should succeed
            Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);

            assertEquals(response.getResponseBody(), body);
        } finally {
            c.close();
        }
View Full Code Here


    @Test(groups = { "standalone", "default_provider" })
    public void basicAuthInputStreamTest() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            Future<Response> f = client.preparePost(getTargetUrl())//
                    .setBody(new ByteArrayInputStream("test".getBytes()))//
                    .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())//
                    .execute();

            Response resp = f.get(30, TimeUnit.SECONDS);
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void basicAuthFileTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            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);
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void basicAuthAsyncConfigTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()).build());
        try {
            Future<Response> f = client.preparePost(getTargetUrl())//
                    .setBody(SIMPLE_TEXT_FILE_STRING)//
                    .execute();

            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void basicAuthFileNoKeepAliveTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnections(false).build());
        try {

            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);
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 {
View Full Code Here

        final AtomicReference<FluentCaseInsensitiveStringsMap> responseHeaders = new AtomicReference<FluentCaseInsensitiveStringsMap>();

        AsyncHttpClient c = getAsyncHttpClient(null);
        try {
            Future<String> f = c.preparePost(getTargetUrl())//
                    .setHeader("Content-Type", "application/x-www-form-urlencoded")//
                    .addFormParam("param_1", "value_1")//
                    .execute(new AsyncHandlerAdapter() {
                private StringBuilder builder = new StringBuilder();
View Full Code Here

       
        final AtomicReference<FluentCaseInsensitiveStringsMap> responseHeaders = new AtomicReference<FluentCaseInsensitiveStringsMap>();
        final AtomicBoolean bodyReceived = new AtomicBoolean(false);
        final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
        try {
            c.preparePost(getTargetUrl())//
            .setHeader("Content-Type", "application/x-www-form-urlencoded")//
            .addFormParam("param_1", "value_1")//
            .execute(new AsyncHandlerAdapter() {

                @Override
View Full Code Here

    public void asyncStreamFutureTest() throws Exception {
        AsyncHttpClient c = getAsyncHttpClient(null);
        final AtomicReference<FluentCaseInsensitiveStringsMap> responseHeaders = new AtomicReference<FluentCaseInsensitiveStringsMap>();
        final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
        try {
            Future<String> f = c.preparePost(getTargetUrl()).addFormParam("param_1", "value_1").execute(new AsyncHandlerAdapter() {
                private StringBuilder builder = new StringBuilder();

                @Override
                public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
                    responseHeaders.set(content.getHeaders());
View Full Code Here

    public void asyncStreamReusePOSTTest() throws Exception {

        AsyncHttpClient c = getAsyncHttpClient(null);
        final AtomicReference<FluentCaseInsensitiveStringsMap> responseHeaders = new AtomicReference<FluentCaseInsensitiveStringsMap>();
        try {
            BoundRequestBuilder rb = c.preparePost(getTargetUrl())//
                    .setHeader("Content-Type", "application/x-www-form-urlencoded")
                    .addFormParam("param_1", "value_1");
           
            Future<String> f = rb.execute(new AsyncHandlerAdapter() {
                private StringBuilder builder = new StringBuilder();
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.