Example usage for org.apache.http.conn.routing HttpRoute getHopTarget

List of usage examples for org.apache.http.conn.routing HttpRoute getHopTarget

Introduction

In this page you can find the example usage for org.apache.http.conn.routing HttpRoute getHopTarget.

Prototype

public final HttpHost getHopTarget(final int hop) 

Source Link

Usage

From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java

/**
 * Establishes the target route./*from ww w  . ja v a2  s  . c  om*/
 *
 * @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 {

    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)
            final int hop = fact.getHopCount() - 1; // the hop to establish
            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);

}

From source file:org.vietspider.net.apache.DefaultRequestDirector.java

/**
 * Establishes the target route.//from   w w  w .  j  a  v a2 s .c o  m
 *
 * @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 {

    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)
            final int hop = fact.getHopCount() - 1; // the hop to establish
            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 HttpException(
                    "Unable to establish route: " + "planned = " + route + "; current = " + fact);
        case HttpRouteDirector.COMPLETE:
            // do nothing
            break;
        default:
            throw new IllegalStateException("Unknown step indicator " + step + " from RouteDirector.");
        }

    } while (step > HttpRouteDirector.COMPLETE);

}

From source file:org.apache.http.impl.client.DefaultRequestDirector.java

/**
 * Establishes the target route./*from   w ww  .j a va 2  s.c  o  m*/
 *
 * @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(final HttpRoute route, final HttpContext context)
        throws HttpException, IOException {

    final HttpRouteDirector rowdy = new BasicRouteDirector();
    int step;
    do {
        final 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: {
            final 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)
            final int hop = fact.getHopCount() - 1; // the hop to establish
            final 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 HttpException(
                    "Unable to establish route: " + "planned = " + route + "; current = " + fact);
        case HttpRouteDirector.COMPLETE:
            // do nothing
            break;
        default:
            throw new IllegalStateException("Unknown step indicator " + step + " from RouteDirector.");
        }

    } while (step > HttpRouteDirector.COMPLETE);

}

From source file:org.apache.http.impl.execchain.MainClientExec.java

/**
 * Establishes the target route./* w  w  w  .  j  a v a2  s. c o  m*/
 */
void establishRoute(final AuthState proxyAuthState, final HttpClientConnection managedConn,
        final HttpRoute route, final HttpRequest request, final HttpClientContext context)
        throws HttpException, IOException {
    final RequestConfig config = context.getRequestConfig();
    final int timeout = config.getConnectTimeout();
    final RouteTracker tracker = new RouteTracker(route);
    int step;
    do {
        final HttpRoute fact = tracker.toRoute();
        step = this.routeDirector.nextStep(route, fact);

        switch (step) {

        case HttpRouteDirector.CONNECT_TARGET:
            this.connManager.connect(managedConn, route, timeout > 0 ? timeout : 0, context);
            tracker.connectTarget(route.isSecure());
            break;
        case HttpRouteDirector.CONNECT_PROXY:
            this.connManager.connect(managedConn, route, timeout > 0 ? timeout : 0, context);
            final HttpHost proxy = route.getProxyHost();
            tracker.connectProxy(proxy, false);
            break;
        case HttpRouteDirector.TUNNEL_TARGET: {
            final boolean secure = createTunnelToTarget(proxyAuthState, managedConn, route, request, context);
            this.log.debug("Tunnel to target created.");
            tracker.tunnelTarget(secure);
        }
            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)
            final int hop = fact.getHopCount() - 1; // the hop to establish
            final boolean secure = createTunnelToProxy(route, hop, context);
            this.log.debug("Tunnel to proxy created.");
            tracker.tunnelProxy(route.getHopTarget(hop), secure);
        }
            break;

        case HttpRouteDirector.LAYER_PROTOCOL:
            this.connManager.upgrade(managedConn, route, context);
            tracker.layerProtocol(route.isSecure());
            break;

        case HttpRouteDirector.UNREACHABLE:
            throw new HttpException(
                    "Unable to establish route: " + "planned = " + route + "; current = " + fact);
        case HttpRouteDirector.COMPLETE:
            this.connManager.routeComplete(managedConn, route, context);
            break;
        default:
            throw new IllegalStateException("Unknown step indicator " + step + " from RouteDirector.");
        }

    } while (step > HttpRouteDirector.COMPLETE);
}