Search in sources :

Example 21 with HttpRoute

use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.

the class DefaultRequestDirector method establishRoute.

/**
     * Establishes the target route.
     *
     * @param route     the route to establish
     * @param context   the context for the request execution
     *
     * @throws HttpException    in case of a problem
     * @throws IOException      in case of an IO problem
     */
protected void establishRoute(HttpRoute route, HttpContext context) throws HttpException, IOException {
    //@@@ how to handle CONNECT requests for tunnelling?
    //@@@ refuse to send external CONNECT via director? special handling?
    //@@@ should the request parameters already be used below?
    //@@@ probably yes, but they're not linked yet
    //@@@ will linking above cause problems with linking in reqExec?
    //@@@ probably not, because the parent is replaced
    //@@@ just make sure we don't link parameters to themselves
    HttpRouteDirector rowdy = new BasicRouteDirector();
    int step;
    do {
        HttpRoute fact = managedConn.getRoute();
        step = rowdy.nextStep(route, fact);
        switch(step) {
            case HttpRouteDirector.CONNECT_TARGET:
            case HttpRouteDirector.CONNECT_PROXY:
                managedConn.open(route, context, this.params);
                break;
            case HttpRouteDirector.TUNNEL_TARGET:
                {
                    boolean secure = createTunnelToTarget(route, context);
                    this.log.debug("Tunnel to target created.");
                    managedConn.tunnelTarget(secure, this.params);
                }
                break;
            case HttpRouteDirector.TUNNEL_PROXY:
                {
                    // The most simple example for this case is a proxy chain
                    // of two proxies, where P1 must be tunnelled to P2.
                    // route: Source -> P1 -> P2 -> Target (3 hops)
                    // fact:  Source -> P1 -> Target       (2 hops)
                    // the hop to establish
                    final int hop = fact.getHopCount() - 1;
                    boolean secure = createTunnelToProxy(route, hop, context);
                    this.log.debug("Tunnel to proxy created.");
                    managedConn.tunnelProxy(route.getHopTarget(hop), secure, this.params);
                }
                break;
            case HttpRouteDirector.LAYER_PROTOCOL:
                managedConn.layerProtocol(context, this.params);
                break;
            case HttpRouteDirector.UNREACHABLE:
                throw new IllegalStateException("Unable to establish route." + "\nplanned = " + route + "\ncurrent = " + fact);
            case HttpRouteDirector.COMPLETE:
                // do nothing
                break;
            default:
                throw new IllegalStateException("Unknown step indicator " + step + " from RouteDirector.");
        }
    // switch
    } while (step > HttpRouteDirector.COMPLETE);
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute) BasicRouteDirector(org.apache.http.conn.routing.BasicRouteDirector) HttpRouteDirector(org.apache.http.conn.routing.HttpRouteDirector)

Example 22 with HttpRoute

use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.

the class AbstractConnPool method handleReference.

// non-javadoc, see interface RefQueueHandler
// BEGIN android-changed
public void handleReference(Reference ref) {
    // END android-changed
    poolLock.lock();
    try {
        if (ref instanceof BasicPoolEntryRef) {
            // check if the GCed pool entry was still in use
            //@@@ find a way to detect this without lookup
            //@@@ flag in the BasicPoolEntryRef, to be reset when freed?
            final boolean lost = issuedConnections.remove(ref);
            if (lost) {
                final HttpRoute route = ((BasicPoolEntryRef) ref).getRoute();
                if (log.isDebugEnabled()) {
                    log.debug("Connection garbage collected. " + route);
                }
                handleLostEntry(route);
            }
        }
    } finally {
        poolLock.unlock();
    }
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute)

Example 23 with HttpRoute

use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.

the class ConnPoolByRoute method freeEntry.

// getEntry
// non-javadoc, see base class AbstractConnPool
@Override
public void freeEntry(BasicPoolEntry entry, boolean reusable, long validDuration, TimeUnit timeUnit) {
    HttpRoute route = entry.getPlannedRoute();
    if (log.isDebugEnabled()) {
        log.debug("Freeing connection" + " [" + route + "][" + entry.getState() + "]");
    }
    poolLock.lock();
    try {
        if (isShutDown) {
            // the pool is shut down, release the
            // connection's resources and get out of here
            closeConnection(entry.getConnection());
            return;
        }
        // no longer issued, we keep a hard reference now
        issuedConnections.remove(entry.getWeakRef());
        RouteSpecificPool rospl = getRoutePool(route, true);
        if (reusable) {
            rospl.freeEntry(entry);
            freeConnections.add(entry);
            idleConnHandler.add(entry.getConnection(), validDuration, timeUnit);
        } else {
            rospl.dropEntry();
            numConnections--;
        }
        notifyWaitingThread(rospl);
    } finally {
        poolLock.unlock();
    }
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute)

Example 24 with HttpRoute

use of org.apache.http.conn.routing.HttpRoute in project robovm by robovm.

the class ConnPoolByRoute method deleteEntry.

/**
     * Deletes a given pool entry.
     * This closes the pooled connection and removes all references,
     * so that it can be GCed.
     * 
     * <p><b>Note:</b> Does not remove the entry from the freeConnections list.
     * It is assumed that the caller has already handled this step.</p>
     * <!-- @@@ is that a good idea? or rather fix it? -->
     * 
     * @param entry         the pool entry for the connection to delete
     */
protected void deleteEntry(BasicPoolEntry entry) {
    HttpRoute route = entry.getPlannedRoute();
    if (log.isDebugEnabled()) {
        log.debug("Deleting connection" + " [" + route + "][" + entry.getState() + "]");
    }
    poolLock.lock();
    try {
        closeConnection(entry.getConnection());
        RouteSpecificPool rospl = getRoutePool(route, true);
        rospl.deleteEntry(entry);
        numConnections--;
        if (rospl.isUnused()) {
            routeToPool.remove(route);
        }
        // not idle, but dead
        idleConnHandler.remove(entry.getConnection());
    } finally {
        poolLock.unlock();
    }
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute)

Example 25 with HttpRoute

use of org.apache.http.conn.routing.HttpRoute in project pinpoint by naver.

the class HttpClientConnectionManagerConnectMethodInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof HttpRoute) {
        final HttpRoute route = (HttpRoute) args[1];
        final StringBuilder sb = new StringBuilder();
        if (route.getProxyHost() != null) {
            sb.append(route.getProxyHost().getHostName());
            if (route.getProxyHost().getPort() > 0) {
                sb.append(":").append(route.getProxyHost().getPort());
            }
        } else {
            if (route.getTargetHost() != null) {
                sb.append(route.getTargetHost().getHostName());
                if (route.getTargetHost().getPort() > 0) {
                    sb.append(":").append(route.getTargetHost().getPort());
                }
            }
        }
        recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
    }
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL);
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute)

Aggregations

HttpRoute (org.apache.http.conn.routing.HttpRoute)33 HttpHost (org.apache.http.HttpHost)17 HttpRequest (org.apache.http.HttpRequest)9 AbortableHttpRequest (org.apache.http.client.methods.AbortableHttpRequest)8 BasicHttpRequest (org.apache.http.message.BasicHttpRequest)8 InetAddress (java.net.InetAddress)7 IOException (java.io.IOException)6 HttpException (org.apache.http.HttpException)6 Scheme (org.apache.http.conn.scheme.Scheme)6 HttpResponse (org.apache.http.HttpResponse)5 AuthenticationException (org.apache.http.auth.AuthenticationException)5 RedirectException (org.apache.http.client.RedirectException)5 ClientConnectionRequest (org.apache.http.conn.ClientConnectionRequest)5 HttpParams (org.apache.http.params.HttpParams)5 InterruptedIOException (java.io.InterruptedIOException)4 URI (java.net.URI)4 Header (org.apache.http.Header)4 HttpEntity (org.apache.http.HttpEntity)4 CredentialsProvider (org.apache.http.client.CredentialsProvider)4 NonRepeatableRequestException (org.apache.http.client.NonRepeatableRequestException)4