Package org.apache.http.impl.nio.client

Examples of org.apache.http.impl.nio.client.DefaultHttpAsyncClient


                    e.printStackTrace();
                }
            }
            ctx.setAttribute(ClientContext.SCHEME_REGISTRY, reg);
            connectionFuture = new BasicFuture<Boolean>(callback);
            DefaultHttpAsyncClient c = getHttpAsyncClient();
            CredentialsProvider credProvider = c.getCredentialsProvider();
            Credentials creds = (Credentials)outMessage.getContextualProperty(Credentials.class.getName());
            if (creds != null && credProvider != null) {
                credProvider.setCredentials(AuthScope.ANY, creds);
            }
            if (credProvider != null && credProvider.getCredentials(AuthScope.ANY) != null) {
                ctx.setAttribute(ClientContext.USER_TOKEN,
                                 credProvider.getCredentials(AuthScope.ANY).getUserPrincipal());
            }
           
            c.execute(new CXFHttpAsyncRequestProducer(entity, outbuf),
                      new CXFHttpAsyncResponseConsumer(this, inbuf, responseCallback),
                      ctx,
                      callback);
        }
View Full Code Here


        this.asynchAsyncRevalidator = makeAsynchronousValidator(config);
    }

    public CachingHttpAsyncClient() throws IOReactorException {
        this(new DefaultHttpAsyncClient(),
                new BasicHttpCache(),
                new CacheConfig());
    }
View Full Code Here

                new BasicHttpCache(),
                new CacheConfig());
    }

    public CachingHttpAsyncClient(CacheConfig config) throws IOReactorException {
        this(new DefaultHttpAsyncClient(),
                new BasicHttpCache(config),
                config);
    }
View Full Code Here

    public void initClient() throws Exception {
        this.ioreactor = new DefaultConnectingIOReactor();
        AsyncSchemeRegistry schemeRegistry = new AsyncSchemeRegistry();
        schemeRegistry.register(new AsyncScheme("http", 80, null));
        this.connMgr = new PoolingClientAsyncConnectionManager(this.ioreactor, schemeRegistry);
        this.httpclient = new DefaultHttpAsyncClient(this.connMgr);
        this.httpclient.getParams()
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
View Full Code Here

                    e.printStackTrace();
                }
            }
            ctx.setAttribute(ClientContext.SCHEME_REGISTRY, reg);
            connectionFuture = new BasicFuture<Boolean>(callback);
            DefaultHttpAsyncClient c = getHttpAsyncClient();
            CredentialsProvider credProvider = c.getCredentialsProvider();
            Credentials creds = (Credentials)outMessage.getContextualProperty(Credentials.class.getName());
            if (creds != null && credProvider != null) {
                credProvider.setCredentials(AuthScope.ANY, creds);
            }
            if (credProvider != null && credProvider.getCredentials(AuthScope.ANY) != null) {
                ctx.setAttribute(ClientContext.USER_TOKEN,
                                 credProvider.getCredentials(AuthScope.ANY).getUserPrincipal());
            }
           
            c.execute(new CXFHttpAsyncRequestProducer(entity, outbuf),
                      new CXFHttpAsyncResponseConsumer(this, inbuf, responseCallback),
                      ctx,
                      callback);
        }
View Full Code Here

import org.apache.http.nio.client.HttpAsyncClient;

public class AsyncClientHttpExchange {

    public static void main(String[] args) throws Exception {
        HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
        httpclient.start();
        try {
            HttpGet request = new HttpGet("http://www.apache.org/");
            Future<HttpResponse> future = httpclient.execute(request, null);
            HttpResponse response = future.get();
            System.out.println("Response: " + response.getStatusLine());
            System.out.println("Shutting down");
        } finally {
            httpclient.shutdown();
        }
        System.out.println("Done");
    }
View Full Code Here

import org.apache.http.protocol.HttpContext;

public class AsyncClientHttpExchangeStreaming {

    public static void main(String[] args) throws Exception {
        HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
        httpclient.start();
        try {
            Future<Boolean> future = httpclient.execute(
                    HttpAsyncMethods.createGet("http://localhost:8080/"),
                    new MyResponseConsumer(), null);
            Boolean result = future.get();
            if (result != null && result.booleanValue()) {
                System.out.println("Request successfully executed");
            } else {
                System.out.println("Request failed");
            }
            System.out.println("Shutting down");
        } finally {
            httpclient.shutdown();
        }
        System.out.println("Done");
    }
View Full Code Here

import org.apache.http.nio.client.methods.ZeroCopyPost;

public class ZeroCopyHttpExchange {

    public static void main(String[] args) throws Exception {
        HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
        httpclient.start();
        try {
            File upload = new File(args[0]);
            File download = new File(args[1]);
            ZeroCopyPost httpost = new ZeroCopyPost("http://localhost:8080/", upload,
                    ContentType.create("text/plain"));
            ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {

                @Override
                protected File process(
                        final HttpResponse response,
                        final File file,
                        final ContentType contentType) throws Exception {
                    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                        throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
                    }
                    return file;
                }

            };
            Future<File> future = httpclient.execute(httpost, consumer, null);
            File result = future.get();
            System.out.println("Response file length: " + result.length());
            System.out.println("Shutting down");
        } finally {
            httpclient.shutdown();
        }
        System.out.println("Done");
    }
View Full Code Here

import org.apache.http.params.CoreConnectionPNames;

public class AsyncClientHttpExchangeFutureCallback {

    public static void main(String[] args) throws Exception {
        HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
        httpclient.getParams()
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 3000)
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

        httpclient.start();
        try {
            HttpGet[] requests = new HttpGet[] {
                    new HttpGet("http://www.apache.org/"),
                    new HttpGet("https://www.verisign.com/"),
                    new HttpGet("http://www.google.com/")
            };
            final CountDownLatch latch = new CountDownLatch(requests.length);
            for (final HttpGet request: requests) {
                httpclient.execute(request, new FutureCallback<HttpResponse>() {

                    public void completed(final HttpResponse response) {
                        latch.countDown();
                        System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
                    }

                    public void failed(final Exception ex) {
                        latch.countDown();
                        System.out.println(request.getRequestLine() + "->" + ex);
                    }

                    public void cancelled() {
                        latch.countDown();
                        System.out.println(request.getRequestLine() + " cancelled");
                    }

                });
            }
            latch.await();
            System.out.println("Shutting down");
        } finally {
            httpclient.shutdown();
        }
        System.out.println("Done");
    }
View Full Code Here

                    e.printStackTrace();
                }
            }
            ctx.setAttribute(ClientContext.SCHEME_REGISTRY, reg);
            connectionFuture = new BasicFuture<Boolean>(callback);
            DefaultHttpAsyncClient c = getHttpAsyncClient();
            CredentialsProvider credProvider = c.getCredentialsProvider();
            Credentials creds = (Credentials)outMessage.getContextualProperty(Credentials.class.getName());
            if (creds != null && credProvider != null) {
                credProvider.setCredentials(AuthScope.ANY, creds);
            }
            if (credProvider != null && credProvider.getCredentials(AuthScope.ANY) != null) {
                ctx.setAttribute(ClientContext.USER_TOKEN,
                                 credProvider.getCredentials(AuthScope.ANY).getUserPrincipal());
            }
           
            c.execute(new CXFHttpAsyncRequestProducer(entity, outbuf),
                      new CXFHttpAsyncResponseConsumer(this, inbuf, responseCallback),
                      ctx,
                      callback);
        }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.nio.client.DefaultHttpAsyncClient

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.