BasicRouteDirectorpublic class BasicRouteDirector extends Object implements HttpRouteDirectorBasic implementation of an {@link HttpRouteDirector HttpRouteDirector}.
This implementation is stateless and therefore thread-safe. |
Methods Summary |
---|
protected int | directStep(org.apache.http.conn.routing.RouteInfo plan, org.apache.http.conn.routing.RouteInfo fact)Determines the next step to establish a direct connection.
if (fact.getHopCount() > 1)
return UNREACHABLE;
if (!plan.getTargetHost().equals(fact.getTargetHost()))
return UNREACHABLE;
// If the security is too low, we could now suggest to layer
// a secure protocol on the direct connection. Layering on direct
// connections has not been supported in HttpClient 3.x, we don't
// consider it here until there is a real-life use case for it.
// Should we tolerate if security is better than planned?
// (plan.isSecure() && !fact.isSecure())
if (plan.isSecure() != fact.isSecure())
return UNREACHABLE;
// Local address has to match only if the plan specifies one.
if ((plan.getLocalAddress() != null) &&
!plan.getLocalAddress().equals(fact.getLocalAddress())
)
return UNREACHABLE;
return COMPLETE;
| protected int | firstStep(org.apache.http.conn.routing.RouteInfo plan)Determines the first step to establish a route.
return (plan.getHopCount() > 1) ?
CONNECT_PROXY : CONNECT_TARGET;
| public int | nextStep(org.apache.http.conn.routing.RouteInfo plan, org.apache.http.conn.routing.RouteInfo fact)Provides the next step.
if (plan == null) {
throw new IllegalArgumentException
("Planned route may not be null.");
}
int step = UNREACHABLE;
if ((fact == null) || (fact.getHopCount() < 1))
step = firstStep(plan);
else if (plan.getHopCount() > 1)
step = proxiedStep(plan, fact);
else
step = directStep(plan, fact);
return step;
| protected int | proxiedStep(org.apache.http.conn.routing.RouteInfo plan, org.apache.http.conn.routing.RouteInfo fact)Determines the next step to establish a connection via proxy.
if (fact.getHopCount() <= 1)
return UNREACHABLE;
if (!plan.getTargetHost().equals(fact.getTargetHost()))
return UNREACHABLE;
final int phc = plan.getHopCount();
final int fhc = fact.getHopCount();
if (phc < fhc)
return UNREACHABLE;
for (int i=0; i<fhc-1; i++) {
if (!plan.getHopTarget(i).equals(fact.getHopTarget(i)))
return UNREACHABLE;
}
// now we know that the target matches and proxies so far are the same
if (phc > fhc)
return TUNNEL_PROXY; // need to extend the proxy chain
// proxy chain and target are the same, check tunnelling and layering
if ((fact.isTunnelled() && !plan.isTunnelled()) ||
(fact.isLayered() && !plan.isLayered()))
return UNREACHABLE;
if (plan.isTunnelled() && !fact.isTunnelled())
return TUNNEL_TARGET;
if (plan.isLayered() && !fact.isLayered())
return LAYER_PROTOCOL;
// tunnel and layering are the same, remains to check the security
// Should we tolerate if security is better than planned?
// (plan.isSecure() && !fact.isSecure())
if (plan.isSecure() != fact.isSecure())
return UNREACHABLE;
return COMPLETE;
|
|