HttpRoutepublic final class HttpRoute extends Object implements Cloneable, RouteInfoThe route for a request.
Instances of this class are unmodifiable and therefore suitable
for use as lookup keys. |
Fields Summary |
---|
private final HttpHost | targetHostThe target host to connect to. | private final InetAddress | localAddressThe local address to connect from.
null indicates that the default should be used. | private final HttpHost[] | proxyChainThe proxy servers, if any. | private final TunnelType | tunnelledWhether the the route is tunnelled through the proxy. | private final LayerType | layeredWhether the route is layered. | private final boolean | secureWhether the route is (supposed to be) secure. |
Constructors Summary |
---|
private HttpRoute(InetAddress local, HttpHost target, HttpHost[] proxies, boolean secure, TunnelType tunnelled, LayerType layered)Internal, fully-specified constructor.
This constructor does not clone the proxy chain array,
nor test it for null elements. This conversion and
check is the responsibility of the public constructors.
The order of arguments here is different from the similar public
constructor, as required by Java.
if (target == null) {
throw new IllegalArgumentException
("Target host may not be null.");
}
if ((tunnelled == TunnelType.TUNNELLED) && (proxies == null)) {
throw new IllegalArgumentException
("Proxy required if tunnelled.");
}
// tunnelled is already checked above, that is in line with the default
if (tunnelled == null)
tunnelled = TunnelType.PLAIN;
if (layered == null)
layered = LayerType.PLAIN;
this.targetHost = target;
this.localAddress = local;
this.proxyChain = proxies;
this.secure = secure;
this.tunnelled = tunnelled;
this.layered = layered;
| public HttpRoute(HttpHost target, InetAddress local, HttpHost[] proxies, boolean secure, TunnelType tunnelled, LayerType layered)Creates a new route with all attributes specified explicitly.
this(local, target, toChain(proxies), secure, tunnelled, layered);
| public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy, boolean secure, TunnelType tunnelled, LayerType layered)Creates a new route with at most one proxy.
this(local, target, toChain(proxy), secure, tunnelled, layered);
| public HttpRoute(HttpHost target, InetAddress local, boolean secure)Creates a new direct route.
That is a route without a proxy.
this(local, target, null, secure, TunnelType.PLAIN, LayerType.PLAIN);
| public HttpRoute(HttpHost target)Creates a new direct insecure route.
this(null, target, null, false, TunnelType.PLAIN, LayerType.PLAIN);
| public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy, boolean secure)Creates a new route through a proxy.
When using this constructor, the proxy MUST be given.
For convenience, it is assumed that a secure connection will be
layered over a tunnel through the proxy.
this(local, target, toChain(proxy), secure,
secure ? TunnelType.TUNNELLED : TunnelType.PLAIN,
secure ? LayerType.LAYERED : LayerType.PLAIN);
if (proxy == null) {
throw new IllegalArgumentException
("Proxy host may not be null.");
}
|
Methods Summary |
---|
public java.lang.Object | clone()
return super.clone();
| public final boolean | equals(java.lang.Object o)Compares this route to another.
if (o == this)
return true;
if (!(o instanceof HttpRoute))
return false;
HttpRoute that = (HttpRoute) o;
boolean equal = this.targetHost.equals(that.targetHost);
equal &=
( this.localAddress == that.localAddress) ||
((this.localAddress != null) &&
this.localAddress.equals(that.localAddress));
equal &=
( this.proxyChain == that.proxyChain) ||
((this.proxyChain != null) &&
(that.proxyChain != null) &&
(this.proxyChain.length == that.proxyChain.length));
// comparison of actual proxies follows below
equal &=
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
(this.layered == that.layered);
// chain length has been compared above, now check the proxies
if (equal && (this.proxyChain != null)) {
for (int i=0; equal && (i<this.proxyChain.length); i++)
equal = this.proxyChain[i].equals(that.proxyChain[i]);
}
return equal;
| public final int | getHopCount()
return (proxyChain == null) ? 1 : (proxyChain.length+1);
| public final org.apache.http.HttpHost | getHopTarget(int hop)
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
final int hopcount = getHopCount();
if (hop >= hopcount)
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds route length " + hopcount);
HttpHost result = null;
if (hop < hopcount-1)
result = this.proxyChain[hop];
else
result = this.targetHost;
return result;
| public final LayerType | getLayerType()
return this.layered;
| public final java.net.InetAddress | getLocalAddress()
return this.localAddress;
| public final org.apache.http.HttpHost | getProxyHost()
return (this.proxyChain == null) ? null : this.proxyChain[0];
| public final org.apache.http.HttpHost | getTargetHost()
return this.targetHost;
| public final TunnelType | getTunnelType()
return this.tunnelled;
| public final int | hashCode()Generates a hash code for this route.
int hc = this.targetHost.hashCode();
if (this.localAddress != null)
hc ^= localAddress.hashCode();
if (this.proxyChain != null) {
hc ^= proxyChain.length;
for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode();
}
if (this.secure)
hc ^= 0x11111111;
hc ^= this.tunnelled.hashCode();
hc ^= this.layered.hashCode();
return hc;
| public final boolean | isLayered()
return (this.layered == LayerType.LAYERED);
| public final boolean | isSecure()
return this.secure;
| public final boolean | isTunnelled()
return (this.tunnelled == TunnelType.TUNNELLED);
| private static org.apache.http.HttpHost[] | toChain(org.apache.http.HttpHost proxy)Helper to convert a proxy to a proxy chain.
if (proxy == null)
return null;
return new HttpHost[]{ proxy };
| private static org.apache.http.HttpHost[] | toChain(org.apache.http.HttpHost[] proxies)Helper to duplicate and check a proxy chain.
An empty proxy chain is converted to null .
if ((proxies == null) || (proxies.length < 1))
return null;
for (HttpHost proxy : proxies) {
if (proxy == null)
throw new IllegalArgumentException
("Proxy chain may not contain null elements.");
}
// copy the proxy chain, the traditional way
HttpHost[] result = new HttpHost[proxies.length];
System.arraycopy(proxies, 0, result, 0, proxies.length);
return result;
| public final java.lang.String | toString()Obtains a description of this route.
StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
cab.append("HttpRoute[");
if (this.localAddress != null) {
cab.append(this.localAddress);
cab.append("->");
}
cab.append('{");
if (this.tunnelled == TunnelType.TUNNELLED)
cab.append('t");
if (this.layered == LayerType.LAYERED)
cab.append('l");
if (this.secure)
cab.append('s");
cab.append("}->");
if (this.proxyChain != null) {
for (HttpHost aProxyChain : this.proxyChain) {
cab.append(aProxyChain);
cab.append("->");
}
}
cab.append(this.targetHost);
cab.append(']");
return cab.toString();
|
|