Package org.apache.http

Examples of org.apache.http.HttpConnection


    }

    @Test
    public void testLeaseReleaseStateful() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry1 = pool.add(conn1);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry2 = pool.add(conn2);
        HttpConnection conn3 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry3 = pool.add(conn3);

        Assert.assertNotNull(entry1);
        Assert.assertNotNull(entry2);
        Assert.assertNotNull(entry3);
View Full Code Here


    }

    @Test(expected=IllegalStateException.class)
    public void testReleaseInvalidEntry() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry = new LocalPoolEntry(ROUTE, conn);
        pool.free(entry, true);
    }
View Full Code Here

    }

    @Test
    public void testRemove() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry1 = pool.add(conn1);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry2 = pool.add(conn2);
        HttpConnection conn3 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry3 = pool.add(conn3);

        Assert.assertNotNull(entry1);
        Assert.assertNotNull(entry2);
        Assert.assertNotNull(entry3);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testShutdown() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry1 = pool.add(conn1);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        LocalPoolEntry entry2 = pool.add(conn2);

        PoolEntryFuture<LocalPoolEntry> future1 = Mockito.mock(PoolEntryFuture.class);
        pool.queue(future1);
View Full Code Here

            return new LocalPoolEntry(getRoute(), conn);
        }

        @Override
        protected void closeEntry(LocalPoolEntry entry) {
            HttpConnection conn = entry.getConnection();
            try {
                conn.close();
            } catch (IOException ignore) {
            }
        }
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Checking for connections, idle timeout: "  + idleTimeout);
        }

        for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
            HttpConnection conn = entry.getKey();
            TimeValues times = entry.getValue();
            long connectionTime = times.timeAdded;
            if (connectionTime <= idleTimeout) {
                if (log.isDebugEnabled()) {
                    log.debug("Closing idle connection, connection time: "  + connectionTime);
                }
                try {
                    conn.close();
                } catch (IOException ex) {
                    log.debug("I/O error closing connection", ex);
                }
            }
        }
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Checking for expired connections, now: "  + now);
        }

        for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
            HttpConnection conn = entry.getKey();
            TimeValues times = entry.getValue();
            if(times.timeExpires <= now) {
                if (log.isDebugEnabled()) {
                    log.debug("Closing connection, expired @: "  + times.timeExpires);
                }
                try {
                    conn.close();
                } catch (IOException ex) {
                    log.debug("I/O error closing connection", ex);
                }
            }
        }
View Full Code Here

       
        if (!request.containsHeader(HTTP.TARGET_HOST)) {
            HttpHost targethost = (HttpHost) context
                .getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (targethost == null) {
                HttpConnection conn = (HttpConnection) context
                    .getAttribute(ExecutionContext.HTTP_CONNECTION);
                if (conn instanceof HttpInetConnection) {
                    // Populate the context with a default HTTP host based on the
                    // inet address of the target host
                    InetAddress address = ((HttpInetConnection) conn).getRemoteAddress();
View Full Code Here

        if (context == null) {
            throw new IllegalArgumentException
                ("HTTP context may not be null.");
        }
       
        HttpConnection conn = (HttpConnection)
            context.getAttribute(ExecutionContext.HTTP_CONNECTION);

        if (conn != null && !conn.isOpen())
            return false;
        // do NOT check for stale connection, that is an expensive operation

        // Check for a self-terminating entity. If the end of the entity will
        // be indicated by closing the connection, there is no keep-alive.
View Full Code Here

        // based on testChunkedContent which is known to return true
        // the difference is in the mock connection passed here
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);

        HttpConnection mockonn = new MockConnection(false, false);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, mockonn);
        assertFalse("closed connection should not be kept alive",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpConnection

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.