Package org.apache.http.conn.routing
Class HttpRoute
java.lang.Object
org.apache.http.conn.routing.HttpRoute
@Contract(threading=IMMUTABLE)
public final class HttpRoute
extends Object
implements RouteInfo, Cloneable
The route for a request.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.http.conn.routing.RouteInfo
RouteInfo.LayerType, RouteInfo.TunnelType
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new direct insecure route.HttpRoute
(HttpHost target, InetAddress local, boolean secure) Creates a new direct route.HttpRoute
(HttpHost target, InetAddress local, HttpHost[] proxies, boolean secure, RouteInfo.TunnelType tunnelled, RouteInfo.LayerType layered) Creates a new route with all attributes specified explicitly.HttpRoute
(HttpHost target, InetAddress local, HttpHost proxy, boolean secure) Creates a new route through a proxy.HttpRoute
(HttpHost target, InetAddress local, HttpHost proxy, boolean secure, RouteInfo.TunnelType tunnelled, RouteInfo.LayerType layered) Creates a new route with at most one proxy.Creates a new plain route through a proxy. -
Method Summary
Modifier and TypeMethodDescriptionclone()
final boolean
Compares this route to another.final int
Obtains the number of hops in this route.final HttpHost
getHopTarget
(int hop) Obtains the target of a hop in this route.final RouteInfo.LayerType
Obtains the layering type of this route.final InetAddress
Obtains the local address to connect from.final InetSocketAddress
final HttpHost
Obtains the first proxy host.final HttpHost
Obtains the target host.final RouteInfo.TunnelType
Obtains the tunnel type of this route.final int
hashCode()
Generates a hash code for this route.final boolean
Checks whether this route includes a layered protocol.final boolean
isSecure()
Checks whether this route is secure.final boolean
Checks whether this route is tunnelled through a proxy.final String
toString()
Obtains a description of this route.
-
Constructor Details
-
HttpRoute
public HttpRoute(HttpHost target, InetAddress local, HttpHost[] proxies, boolean secure, RouteInfo.TunnelType tunnelled, RouteInfo.LayerType layered) Creates a new route with all attributes specified explicitly.- Parameters:
target
- the host to which to routelocal
- the local address to route from, ornull
for the defaultproxies
- the proxy chain to use, ornull
for a direct routesecure
-true
if the route is (to be) secure,false
otherwisetunnelled
- the tunnel type of this routelayered
- the layering type of this route
-
HttpRoute
public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy, boolean secure, RouteInfo.TunnelType tunnelled, RouteInfo.LayerType layered) Creates a new route with at most one proxy.- Parameters:
target
- the host to which to routelocal
- the local address to route from, ornull
for the defaultproxy
- the proxy to use, ornull
for a direct routesecure
-true
if the route is (to be) secure,false
otherwisetunnelled
-true
if the route is (to be) tunnelled via the proxy,false
otherwiselayered
-true
if the route includes a layered protocol,false
otherwise
-
HttpRoute
Creates a new direct route. That is a route without a proxy.- Parameters:
target
- the host to which to routelocal
- the local address to route from, ornull
for the defaultsecure
-true
if the route is (to be) secure,false
otherwise
-
HttpRoute
Creates a new direct insecure route.- Parameters:
target
- the host to which to route
-
HttpRoute
Creates a new route through a proxy. When using this constructor, theproxy
MUST be given. For convenience, it is assumed that a secure connection will be layered over a tunnel through the proxy.- Parameters:
target
- the host to which to routelocal
- the local address to route from, ornull
for the defaultproxy
- the proxy to usesecure
-true
if the route is (to be) secure,false
otherwise
-
HttpRoute
Creates a new plain route through a proxy.- Parameters:
target
- the host to which to routeproxy
- the proxy to use- Since:
- 4.3
-
-
Method Details
-
getTargetHost
Description copied from interface:RouteInfo
Obtains the target host.- Specified by:
getTargetHost
in interfaceRouteInfo
- Returns:
- the target host
-
getLocalAddress
Description copied from interface:RouteInfo
Obtains the local address to connect from.- Specified by:
getLocalAddress
in interfaceRouteInfo
- Returns:
- the local address,
or
null
-
getLocalSocketAddress
-
getHopCount
public final int getHopCount()Description copied from interface:RouteInfo
Obtains the number of hops in this route. A direct route has one hop. A route through a proxy has two hops. A route through a chain of n proxies has n+1 hops.- Specified by:
getHopCount
in interfaceRouteInfo
- Returns:
- the number of hops in this route
-
getHopTarget
Description copied from interface:RouteInfo
Obtains the target of a hop in this route. The target of the last hop is thetarget host
, the target of previous hops is the respective proxy in the chain. For a route through exactly one proxy, target of hop 0 is the proxy and target of hop 1 is the target host.- Specified by:
getHopTarget
in interfaceRouteInfo
- Parameters:
hop
- index of the hop for which to get the target, 0 for first- Returns:
- the target of the given hop
-
getProxyHost
Description copied from interface:RouteInfo
Obtains the first proxy host.- Specified by:
getProxyHost
in interfaceRouteInfo
- Returns:
- the first proxy in the proxy chain, or
null
if this route is direct
-
getTunnelType
Description copied from interface:RouteInfo
Obtains the tunnel type of this route. If there is a proxy chain, only end-to-end tunnels are considered.- Specified by:
getTunnelType
in interfaceRouteInfo
- Returns:
- the tunnelling type
-
isTunnelled
public final boolean isTunnelled()Description copied from interface:RouteInfo
Checks whether this route is tunnelled through a proxy. If there is a proxy chain, only end-to-end tunnels are considered.- Specified by:
isTunnelled
in interfaceRouteInfo
- Returns:
true
if tunnelled end-to-end through at least one proxy,false
otherwise
-
getLayerType
Description copied from interface:RouteInfo
Obtains the layering type of this route. In the presence of proxies, only layering over an end-to-end tunnel is considered.- Specified by:
getLayerType
in interfaceRouteInfo
- Returns:
- the layering type
-
isLayered
public final boolean isLayered()Description copied from interface:RouteInfo
Checks whether this route includes a layered protocol. In the presence of proxies, only layering over an end-to-end tunnel is considered. -
isSecure
public final boolean isSecure()Description copied from interface:RouteInfo
Checks whether this route is secure. -
equals
Compares this route to another. -
hashCode
public final int hashCode()Generates a hash code for this route. -
toString
Obtains a description of this route. -
clone
- Throws:
CloneNotSupportedException
-