Package org.apache.http

Examples of org.apache.http.HttpConnection


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

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

        HttpEntity entity = response.getEntity();
        HttpVersion ver = response.getStatusLine().getHttpVersion();
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(HttpExecutionContext.HTTP_CONNECTION, mockonn);
        assertFalse("closed connection should not be kept alive",
                    reuseStrategy.keepAlive(response, context));
    }
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(true, true);
        context.setAttribute(HttpExecutionContext.HTTP_CONNECTION, mockonn);
        assertTrue("stale connection should not be detected",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

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

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

        HttpEntity entity = response.getEntity();
        HttpVersion ver = response.getStatusLine().getHttpVersion();
View Full Code Here

        public void abort() {
            request.abort();

            // try to close the connection? is this necessary? unclear based on preliminary debugging of HttpClient, but
            // it doesn't seem to hurt to try
            HttpConnection conn = (HttpConnection) ctx.getAttribute("http.connection");
            if (conn != null) {
                try {
                    conn.close();
                } catch (IOException e) {
                    // this is fine, we're shutting it down anyway
                }
            }
        }
View Full Code Here

        return new BasicPoolEntry(Long.toString(COUNTER.getAndIncrement()), host, conn);
    }

    @Override
    protected void closeEntry(final BasicPoolEntry entry) {
        HttpConnection conn = entry.getConnection();
        try {
            conn.close();
        } catch (IOException ignore) {
        }
    }
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

        // 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(true, true);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, mockonn);
        assertTrue("stale connection should not be detected",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

        }
    }

    @Test
    public void testLeaseRelease() throws Exception {
        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        HttpConnection conn2 = Mockito.mock(HttpConnection.class);

        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);
        Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn2);
View Full Code Here

    @Test
    public void testMaxLimits() throws Exception {
        HttpConnectionFactory connFactory = Mockito.mock(HttpConnectionFactory.class);

        HttpConnection conn1 = Mockito.mock(HttpConnection.class);
        Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn1);

        HttpConnection conn2 = Mockito.mock(HttpConnection.class);
        Mockito.when(connFactory.create(Mockito.eq("otherhost"))).thenReturn(conn2);

        LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
        pool.setMaxPerRoute("somehost", 2);
        pool.setMaxPerRoute("otherhost", 1);
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.