Example usage for org.apache.http.conn.routing BasicRouteDirector BasicRouteDirector

List of usage examples for org.apache.http.conn.routing BasicRouteDirector BasicRouteDirector

Introduction

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

Prototype

BasicRouteDirector

Source Link

Usage

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java

/**
 * Establishes the target route./*  w  ww.j  a v  a  2s .  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
 */
private 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, params);
            break;

        case HttpRouteDirector.TUNNEL_TARGET: {
            boolean secure = createTunnelToTarget(route, context);
            LOGGER.debug("Tunnel to target created.");
            managedConn.tunnelTarget(secure, params);
        }
            break;

        case HttpRouteDirector.TUNNEL_PROXY: {
            throw new NotImplementedException("Proxy chaining not supported");
        }

        case HttpRouteDirector.LAYER_PROTOCOL:
            managedConn.layerProtocol(context, 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.robolectric.shadows.httpclient.DefaultRequestDirector.java

/**
 * Establishes the target route./*ww  w .j ava  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(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 ww .j a  v a 2s  .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  w w .  ja v  a  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

public MainClientExec(final HttpRequestExecutor requestExecutor, final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy, final ConnectionKeepAliveStrategy keepAliveStrategy,
        final AuthenticationStrategy targetAuthStrategy, final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    Args.notNull(targetAuthStrategy, "Target authentication strategy");
    Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
    Args.notNull(userTokenHandler, "User token handler");
    this.authenticator = new HttpAuthenticator();
    this.proxyHttpProcessor = new ImmutableHttpProcessor(new RequestTargetHost(),
            new RequestClientConnControl());
    this.routeDirector = new BasicRouteDirector();
    this.requestExecutor = requestExecutor;
    this.connManager = connManager;
    this.reuseStrategy = reuseStrategy;
    this.keepAliveStrategy = keepAliveStrategy;
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy = proxyAuthStrategy;
    this.userTokenHandler = userTokenHandler;
}

From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java

public DefaultAsyncRequestDirector(final Log log, final HttpAsyncRequestProducer requestProducer,
        final HttpAsyncResponseConsumer<T> responseConsumer, final HttpContext localContext,
        final ResultCallback<T> callback, final ClientAsyncConnectionManager connmgr,
        final HttpProcessor httppocessor, final HttpRoutePlanner routePlanner,
        final ConnectionReuseStrategy reuseStrategy, final ConnectionKeepAliveStrategy keepaliveStrategy,
        final RedirectStrategy redirectStrategy, final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy, final UserTokenHandler userTokenHandler,
        final HttpParams clientParams) {
    super();/*from w ww .j a  v a 2s . co  m*/
    this.log = log;
    this.requestProducer = requestProducer;
    this.responseConsumer = responseConsumer;
    this.localContext = localContext;
    this.resultCallback = callback;
    this.connmgr = connmgr;
    this.httppocessor = httppocessor;
    this.routePlanner = routePlanner;
    this.reuseStrategy = reuseStrategy;
    this.keepaliveStrategy = keepaliveStrategy;
    this.redirectStrategy = redirectStrategy;
    this.routeDirector = new BasicRouteDirector();
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy = proxyAuthStrategy;
    this.userTokenHandler = userTokenHandler;
    this.targetAuthState = new AuthState();
    this.proxyAuthState = new AuthState();
    this.authenticator = new HttpAuthenticator(log);
    this.clientParams = clientParams;
    this.id = COUNTER.getAndIncrement();
}

From source file:org.apache.http.impl.nio.client.MainClientExec.java

public MainClientExec(final HttpProcessor httpProcessor, final HttpRoutePlanner routePlanner,
        final RedirectStrategy redirectStrategy, final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy, final UserTokenHandler userTokenHandler) {
    super();//from w  w w  . j  a  v  a 2s. com
    this.httpProcessor = httpProcessor;
    this.proxyHttpProcessor = new ImmutableHttpProcessor(new RequestTargetHost(),
            new RequestClientConnControl());
    this.routePlanner = routePlanner;
    this.redirectStrategy = redirectStrategy;
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy = proxyAuthStrategy;
    this.userTokenHandler = userTokenHandler;
    this.routeDirector = new BasicRouteDirector();
    this.authenticator = new HttpAuthenticator(log);
}