Examples of ConnectionRequest


Examples of org.apache.http.conn.ConnectionRequest

        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

Examples of org.apache.http.conn.ConnectionRequest

            Proxies.enhanceEntity((HttpEntityEnclosingRequest) request);
        }

        Object userToken = context.getUserToken();

        final ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
        if (execAware != null) {
            if (execAware.isAborted()) {
                connRequest.cancel();
                throw new RequestAbortedException("Request aborted");
            } else {
                execAware.setCancellable(connRequest);
            }
        }

        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);
        }

        context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
View Full Code Here

Examples of org.apache.http.conn.ConnectionRequest

            final HttpExecutionAware execAware) throws IOException, HttpException {
        Args.notNull(route, "HTTP route");
        Args.notNull(request, "HTTP request");
        Args.notNull(context, "HTTP context");

        final ConnectionRequest connRequest = connManager.requestConnection(route, null);
        if (execAware != null) {
            if (execAware.isAborted()) {
                connRequest.cancel();
                throw new RequestAbortedException("Request aborted");
            } else {
                execAware.setCancellable(connRequest);
            }
        }

        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);
View Full Code Here

Examples of org.apache.http.conn.ConnectionRequest

    public final ConnectionRequest requestConnection(
            final HttpRoute route,
            final Object state) {
        Args.notNull(route, "Route");
        return new ConnectionRequest() {

            public boolean cancel() {
                // Nothing to abort, since requests are immediate.
                return false;
            }
View Full Code Here

Examples of org.apache.http.conn.ConnectionRequest

     * 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(HttpHost.class),
View Full Code Here

Examples of org.apache.http.conn.ConnectionRequest

            // If this is the redirect route, stub the return value
            // so-as to pretend the host is waiting on a slot...
            if(route.getTargetHost().getHostName().equals("localhost")) {
                final Thread currentThread = Thread.currentThread();

                return new ConnectionRequest() {

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

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

Examples of org.apache.http.conn.ConnectionRequest

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

Examples of org.apache.http.conn.ConnectionRequest

    }

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

Examples of org.apache.http.conn.ConnectionRequest

        Mockito.when(future.isCancelled()).thenReturn(false);
        Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
        Mockito.when(pool.lease(route, null, null)).thenReturn(future);

        final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
        final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
        Assert.assertNotNull(conn1);
        Assert.assertFalse(conn1.isOpen());
        Assert.assertNotSame(conn, conn1);

        mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.