List of usage examples for org.apache.http.conn.routing HttpRouteDirector nextStep
public int nextStep(RouteInfo plan, RouteInfo fact);
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java
/** * Establishes the target route.//from w w w .j ava2 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 */ 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./*from www . j a 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 ww w . jav a2 s.co 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.// ww w . j a v a2s. 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(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); }