Package org.apache.http

Examples of org.apache.http.HttpClientConnection


        // Expect zero connections in the pool
        Assert.assertEquals(0, this.mgr.getTotalStats().getAvailable());

        // Make sure one connection is available
        connreq = this.mgr.requestConnection(new HttpRoute(target), null);
        final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

        this.mgr.releaseConnection(conn, null, -1, null);
    }
View Full Code Here


        return expired;
    }

    @Override
    public boolean isClosed() {
        final HttpClientConnection conn = getConnection();
        return !conn.isOpen();
    }
View Full Code Here

        return !conn.isOpen();
    }

    @Override
    public void close() {
        final HttpClientConnection conn = getConnection();
        try {
            conn.close();
        } catch (final IOException ex) {
            this.log.debug("I/O error closing connection", ex);
        }
    }
View Full Code Here

            }
        }

        final RequestConfig config = context.getRequestConfig();

        HttpClientConnection managedConn;
        try {
            final int timeout = config.getConnectionRequestTimeout();
            managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
        } catch(final InterruptedException interrupted) {
            throw new RequestAbortedException("Request aborted", interrupted);
        }

        final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn);
        try {
            if (execAware != null) {
                if (execAware.isAborted()) {
                    releaseTrigger.abortConnection();
                    throw new RequestAbortedException("Request aborted");
                } else {
                    execAware.setCancellable(releaseTrigger);
                }
            }

            if (!managedConn.isOpen()) {
                final int timeout = config.getConnectTimeout();
                this.connManager.connect(
                    managedConn,
                    route.getTargetHost(), route.getLocalAddress(),
                    timeout > 0 ? timeout : 0,
                    context);
            } else {
                final int timeout = config.getSocketTimeout();
                if (timeout >= 0) {
                    managedConn.setSocketTimeout(timeout);
                }
            }

            HttpHost target = null;
            final HttpRequest original = request.getOriginal();
View Full Code Here

    }

    public void close() throws IOException {
        final CPoolEntry local = this.poolEntry;
        if (local != null) {
            final HttpClientConnection conn = local.getConnection();
            conn.close();
        }
    }
View Full Code Here

    }

    public void shutdown() throws IOException {
        final CPoolEntry local = this.poolEntry;
        if (local != null) {
            final HttpClientConnection conn = local.getConnection();
            conn.shutdown();
        }
    }
View Full Code Here

            conn.shutdown();
        }
    }

    public boolean isOpen() {
        final HttpClientConnection conn = getConnection();
        if (conn != null) {
            return conn.isOpen();
        } else {
            return false;
        }
    }
View Full Code Here

            return false;
        }
    }

    public boolean isStale() {
        final HttpClientConnection conn = getConnection();
        if (conn != null) {
            return conn.isStale();
        } else {
            return true;
        }
    }
View Full Code Here

        } else if (method.equals(IS_OPEN_METHOD)) {
            return Boolean.valueOf(isOpen());
        } else if (method.equals(IS_STALE_METHOD)) {
            return Boolean.valueOf(isStale());
        } else {
            final HttpClientConnection conn = getConnection();
            if (conn == null) {
                throw new ConnectionShutdownException();
            }
            try {
                return method.invoke(conn, args);
View Full Code Here

     * Tests that if a socket fails to connect, the allocated connection is
     * properly released back to the connection manager.
     */
    @Test
    public void testSocketConnectFailureReleasesConnection() throws Exception {
        final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
        final ConnectionRequest connrequest = Mockito.mock(ConnectionRequest.class);
        Mockito.when(connrequest.get(
                Mockito.anyInt(), Mockito.any(TimeUnit.class))).thenReturn(conn);
        final HttpClientConnectionManager connmgr = Mockito.mock(HttpClientConnectionManager.class);
        Mockito.doThrow(new ConnectException()).when(connmgr).connect(
View Full Code Here

TOP

Related Classes of org.apache.http.HttpClientConnection

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.