Package org.apache.http.conn

Examples of org.apache.http.conn.ConnectionRequest


                final HttpRoute route,
                final Object state) {

            final Thread currentThread = Thread.currentThread();

            return new ConnectionRequest() {

                public boolean cancel() {
                    currentThread.interrupt();
                    return true;
                }
View Full Code Here


    private static HttpClientConnection getConnection(
            final HttpClientConnectionManager mgr,
            final HttpRoute route,
            final long timeout,
            final TimeUnit unit) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
        final ConnectionRequest connRequest = mgr.requestConnection(route, null);
        return connRequest.get(timeout, unit);
    }
View Full Code Here

    }

    private static HttpClientConnection getConnection(
            final HttpClientConnectionManager mgr,
            final HttpRoute route) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
        final ConnectionRequest connRequest = mgr.requestConnection(route, null);
        return connRequest.get(0, TimeUnit.MILLISECONDS);
    }
View Full Code Here

     * 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(
                Mockito.any(HttpClientConnection.class),
                Mockito.any(HttpRoute.class),
View Full Code Here

        final HttpGet httpget = new HttpGet("/random/20000");
        final HttpHost target = getServerHttp();

        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        EntityUtils.consume(e);

        // Expect one connection in the pool
        stats = this.mgr.getTotalStats();
        Assert.assertEquals(1, stats.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

        final HttpGet httpget = new HttpGet("/random/20000");
        final HttpHost target = getServerHttp();

        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);

        // Expect one connection in the pool
        stats = this.mgr.getTotalStats();
        Assert.assertEquals(1, stats.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

        final HttpGet httpget = new HttpGet("/random/20000");
        final HttpHost target = getServerHttp();

        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        httpget.abort();

        // 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

        final HttpGet httpget = new HttpGet("/dropdead");
        final HttpHost target = getServerHttp();

        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        // Read the content
        try {
            EntityUtils.toByteArray(e);
            Assert.fail("MalformedChunkCodingException should have been thrown");
        } catch (final MalformedChunkCodingException expected) {

        }

        // 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

        final HttpHost target = start();
        // Get some random data
        final HttpGet httpget = new HttpGet("/random/20000");
        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        EntityUtils.consume(e);

        // Expect one connection in the pool
        stats = this.connManager.getTotalStats();
        Assert.assertEquals(1, stats.getAvailable());

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

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

        final HttpHost target = start();
        // Get some random data
        final HttpGet httpget = new HttpGet("/random/20000");
        final HttpResponse response = this.httpclient.execute(target, httpget);

        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
        try {
            connreq.get(250, TimeUnit.MILLISECONDS);
            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (final ConnectionPoolTimeoutException expected) {
        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);

        // Expect one connection in the pool
        stats = this.connManager.getTotalStats();
        Assert.assertEquals(1, stats.getAvailable());

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

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

TOP

Related Classes of org.apache.http.conn.ConnectionRequest

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.