Search in sources :

Example 1 with BasicRouteDirector

use of org.apache.http.conn.routing.BasicRouteDirector in project robolectric by robolectric.

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 {
    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 2 with BasicRouteDirector

use of org.apache.http.conn.routing.BasicRouteDirector in project platform_external_apache-http by android.

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 3 with BasicRouteDirector

use of org.apache.http.conn.routing.BasicRouteDirector in project XobotOS by xamarin.

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 4 with BasicRouteDirector

use of org.apache.http.conn.routing.BasicRouteDirector 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)

Aggregations

BasicRouteDirector (org.apache.http.conn.routing.BasicRouteDirector)4 HttpRoute (org.apache.http.conn.routing.HttpRoute)4 HttpRouteDirector (org.apache.http.conn.routing.HttpRouteDirector)4