Package org.apache.http.nio

Examples of org.apache.http.nio.NHttpClientConnection


            }
            HttpHost httpHost = new HttpHost(url.getHost(), port, url.getProtocol());

            Axis2HttpRequest axis2Req = new Axis2HttpRequest(epr, httpHost, msgContext);

            NHttpClientConnection conn = ConnectionPool.getConnection(url.getHost(), port);

            if (conn == null) {
                ioReactor.connect(new InetSocketAddress(url.getHost(), port),
                    null, axis2Req, sessionRequestCallback);
                log.debug("A new connection established");
View Full Code Here


                log.debug("No connections available for reuse");
            }
            return null;

        } else {
            NHttpClientConnection conn = null;

            synchronized (connections) {
                while (!connections.isEmpty()) {
                    conn = (NHttpClientConnection) connections.remove(0);

                    if (conn.isOpen()) {
                        if (log.isDebugEnabled()) {
                            log.debug("A connection to host : " + host + " on port : " +
                                port + " is available in the pool, and will be reused");
                        }
                        return conn;
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("closing stale connection");
                        }
                        try {
                            conn.close();
                        } catch (IOException ignore) {
                        }
                    }
                }
            }
View Full Code Here

        // Submit 50 requests using maximum 5 concurrent connections
        Queue<RequestHandle> queue = new LinkedList<RequestHandle>();
        for (int i = 0; i < 50; i++) {
            AsyncConnectionRequest connRequest = connMgr.requestConnection();
            connRequest.waitFor();
            NHttpClientConnection conn = connRequest.getConnection();
            if (conn == null) {
                System.err.println("Failed to obtain connection");
                break;
            }
           
            HttpContext context = conn.getContext();
            BasicHttpRequest httpget = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
            RequestHandle handle = new RequestHandle(connMgr, conn);
           
            context.setAttribute("request", httpget);
            context.setAttribute("request-handle", handle);
           
            queue.add(handle);           
            conn.requestOutput();
        }
       
        // Wait until all requests have been completed
        while (!queue.isEmpty()) {
            RequestHandle handle = queue.remove();
View Full Code Here

                throw new IllegalStateException("Connection manager has been shut down");
            }
            AsyncConnectionRequest request = new AsyncConnectionRequest();
            synchronized (this.lock) {
                while (!this.availableConns.isEmpty()) {
                    NHttpClientConnection conn = this.availableConns.remove();
                    if (conn.isOpen()) {
                        System.out.println("Re-using persistent connection");
                        request.setConnection(conn);
                        break;
                    } else {
                        this.allConns.remove(conn);
View Full Code Here

        }

        @Override
        public Void answer(final InvocationOnMock invocation) throws Throwable {
            final Object[] args = invocation.getArguments();
            final NHttpClientConnection conn = (NHttpClientConnection) args[0];
            conn.submitRequest(request);
            return null;
        }
View Full Code Here

        Args.notNull(responseConsumer, "HTTP response consumer");
        Args.notNull(connPool, "HTTP connection pool");
        Args.notNull(poolEntry, "Pool entry");
        Args.notNull(context, "HTTP context");
        final BasicFuture<T> future = new BasicFuture<T>(callback);
        final NHttpClientConnection conn = poolEntry.getConnection();
        final BasicAsyncClientExchangeHandler<T> handler = new BasicAsyncClientExchangeHandler<T>(
                requestProducer, responseConsumer,
                new RequestExecutionCallback<T, E>(future, poolEntry, connPool),
                context, conn,
                this.httpprocessor, this.connReuseStrategy);
View Full Code Here

        Args.notEmpty(responseConsumers, "Response consumer list");
        Args.notNull(connPool, "HTTP connection pool");
        Args.notNull(poolEntry, "Pool entry");
        Args.notNull(context, "HTTP context");
        final BasicFuture<List<T>> future = new BasicFuture<List<T>>(callback);
        final NHttpClientConnection conn = poolEntry.getConnection();
        final PipeliningClientExchangeHandler<T> handler = new PipeliningClientExchangeHandler<T>(
                requestProducers, responseConsumers,
                new RequestExecutionCallback<List<T>, E>(future, poolEntry, connPool),
                context, conn,
                this.httpprocessor, this.connReuseStrategy);
View Full Code Here

        public void completed(final E result) {
            if (this.requestFuture.isDone()) {
                this.connPool.release(result, true);
                return;
            }
            final NHttpClientConnection conn = result.getConnection();
            final BasicAsyncClientExchangeHandler<T> handler = new BasicAsyncClientExchangeHandler<T>(
                    this.requestProducer, this.responseConsumer,
                    new RequestExecutionCallback<T, E>(this.requestFuture, result, this.connPool),
                    this.context, conn, httpprocessor, connReuseStrategy);
            initExection(handler, conn);
View Full Code Here

        public void completed(final E result) {
            if (this.requestFuture.isDone()) {
                this.connPool.release(result, true);
                return;
            }
            final NHttpClientConnection conn = result.getConnection();
            final PipeliningClientExchangeHandler<T> handler = new PipeliningClientExchangeHandler<T>(
                    this.requestProducers, this.responseConsumers,
                    new RequestExecutionCallback<List<T>, E>(this.requestFuture, result, this.connPool),
                    this.context, conn, httpprocessor, connReuseStrategy);
            initExection(handler, conn);
View Full Code Here

        this(new DefaultNHttpClientConnectionFactory(config), null);
    }

    @Override
    public NHttpClientConnection create(final HttpHost route, final IOSession session) throws IOException {
        final NHttpClientConnection conn;
        if (route.getSchemeName().equalsIgnoreCase("https")) {
            if (this.sslFactory == null) {
                throw new IOException("SSL not supported");
            }
            conn = this.sslFactory.createConnection(session);
View Full Code Here

TOP

Related Classes of org.apache.http.nio.NHttpClientConnection

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.