Package org.apache.hc.core5.http
Class HttpHost
- java.lang.Object
-
- org.apache.hc.core5.http.HttpHost
-
- All Implemented Interfaces:
java.io.Serializable
,NamedEndpoint
@Contract(threading=IMMUTABLE) public final class HttpHost extends java.lang.Object implements NamedEndpoint, java.io.Serializable
Component that holds all details needed to describe an HTTP connection to a host. This includes remote host name, port and protocol scheme.- Since:
- 4.0, 5.0 For constructors that take a scheme as an argument, that argument is now the first one.
- See Also:
Host
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.InetAddress
address
static URIScheme
DEFAULT_SCHEME
The default scheme is "http".private Host
host
private java.lang.String
schemeName
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description HttpHost(java.lang.String hostname)
CreatesHttpHost
instance with the default scheme and port and the given hostname.HttpHost(java.lang.String hostname, int port)
CreatesHttpHost
instance with the default scheme and the given hostname and port.HttpHost(java.lang.String scheme, java.lang.String hostname)
CreatesHttpHost
instance with the given hostname and scheme and the default port for that scheme.HttpHost(java.lang.String scheme, java.lang.String hostname, int port)
CreatesHttpHost
instance with the given scheme, hostname and port.HttpHost(java.lang.String scheme, java.net.InetAddress address, int port)
CreatesHttpHost
instance with the given scheme, inet address and port.HttpHost(java.lang.String scheme, java.net.InetAddress address, java.lang.String hostname, int port)
Creates a newHttpHost
, specifying all values.HttpHost(java.lang.String scheme, NamedEndpoint namedEndpoint)
HttpHost(java.net.InetAddress address)
CreatesHttpHost
instance with the default scheme and port and the given inet address.HttpHost(java.net.InetAddress address, int port)
CreatesHttpHost
instance with the default scheme and the given inet address and port.HttpHost(URIAuthority authority)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpHost
create(java.lang.String s)
CreatesHttpHost
instance from a string.static HttpHost
create(java.net.URI uri)
Creates anHttpHost
instance from the scheme, host, and port from the given URI.boolean
equals(java.lang.Object obj)
java.net.InetAddress
getAddress()
Returns the inet address if explicitly set by a constructor,null
otherwise.java.lang.String
getHostName()
Returns the host name.int
getPort()
Returns the port.java.lang.String
getSchemeName()
Returns the scheme name.int
hashCode()
java.lang.String
toHostString()
Obtains the host string, without scheme prefix.java.lang.String
toString()
java.lang.String
toURI()
Return the host URI, as a string.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
DEFAULT_SCHEME
public static final URIScheme DEFAULT_SCHEME
The default scheme is "http".
-
schemeName
private final java.lang.String schemeName
-
host
private final Host host
-
address
private final java.net.InetAddress address
-
-
Constructor Detail
-
HttpHost
public HttpHost(java.lang.String scheme, java.net.InetAddress address, java.lang.String hostname, int port)
Creates a newHttpHost
, specifying all values. Constructor for HttpHost.- Parameters:
scheme
- the name of the scheme.null
indicates thedefault scheme
address
- the inet address. Can benull
hostname
- the hostname (IP or DNS name)port
- the port number.-1
indicates the scheme default port.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.- Since:
- 5.0
-
HttpHost
public HttpHost(java.lang.String scheme, java.lang.String hostname, int port)
CreatesHttpHost
instance with the given scheme, hostname and port.- Parameters:
scheme
- the name of the scheme.null
indicates thedefault scheme
hostname
- the hostname (IP or DNS name)port
- the port number.-1
indicates the scheme default port.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.
-
HttpHost
public HttpHost(java.lang.String hostname, int port)
CreatesHttpHost
instance with the default scheme and the given hostname and port.- Parameters:
hostname
- the hostname (IP or DNS name)port
- the port number.-1
indicates the scheme default port.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.
-
HttpHost
public HttpHost(java.lang.String scheme, java.lang.String hostname)
CreatesHttpHost
instance with the given hostname and scheme and the default port for that scheme.- Parameters:
scheme
- the name of the scheme.null
indicates thedefault scheme
hostname
- the hostname (IP or DNS name)- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.
-
HttpHost
public HttpHost(java.lang.String hostname)
CreatesHttpHost
instance with the default scheme and port and the given hostname.- Parameters:
hostname
- the hostname (IP or DNS name)- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.
-
HttpHost
public HttpHost(java.lang.String scheme, java.net.InetAddress address, int port)
CreatesHttpHost
instance with the given scheme, inet address and port.- Parameters:
scheme
- the name of the scheme.null
indicates thedefault scheme
address
- the inet address.port
- the port number.-1
indicates the scheme default port.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.- Since:
- 5.0
-
HttpHost
public HttpHost(java.net.InetAddress address, int port)
CreatesHttpHost
instance with the default scheme and the given inet address and port.- Parameters:
address
- the inet address.port
- the port number.-1
indicates the scheme default port.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.- Since:
- 4.3
-
HttpHost
public HttpHost(java.net.InetAddress address)
CreatesHttpHost
instance with the default scheme and port and the given inet address.- Parameters:
address
- the inet address.- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.- Since:
- 4.3
-
HttpHost
public HttpHost(java.lang.String scheme, NamedEndpoint namedEndpoint)
- Throws:
java.lang.IllegalArgumentException
- If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.-1
indicates the scheme default port.- Since:
- 5.0
-
HttpHost
@Deprecated public HttpHost(URIAuthority authority)
Deprecated.- Since:
- 5.0
-
-
Method Detail
-
create
public static HttpHost create(java.lang.String s) throws java.net.URISyntaxException
CreatesHttpHost
instance from a string. Text may not contain any blanks.- Throws:
java.net.URISyntaxException
- Since:
- 4.4
-
create
public static HttpHost create(java.net.URI uri)
Creates anHttpHost
instance from the scheme, host, and port from the given URI. Other URI elements are ignored.- Parameters:
uri
- scheme, host, and port.- Returns:
- a new HttpHost
- Since:
- 5.0
-
getHostName
public java.lang.String getHostName()
Returns the host name.- Specified by:
getHostName
in interfaceNamedEndpoint
- Returns:
- the host name (IP or DNS name)
-
getPort
public int getPort()
Returns the port.- Specified by:
getPort
in interfaceNamedEndpoint
- Returns:
- the host port, or
-1
if not set
-
getSchemeName
public java.lang.String getSchemeName()
Returns the scheme name.- Returns:
- the scheme name
-
getAddress
public java.net.InetAddress getAddress()
Returns the inet address if explicitly set by a constructor,null
otherwise.- Returns:
- the inet address
- Since:
- 4.3
-
toURI
public java.lang.String toURI()
Return the host URI, as a string.- Returns:
- the host URI
-
toHostString
public java.lang.String toHostString()
Obtains the host string, without scheme prefix.- Returns:
- the host string, for example
localhost:8080
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
-