Class HttpHost

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    @Contract(threading=IMMUTABLE)
    public final class HttpHost
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host name, port and scheme.
    Since:
    4.0
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_SCHEME_NAME
      The default scheme is "http".
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpHost​(java.lang.String hostname)
      Creates HttpHost instance with the default scheme and port and the given hostname.
      HttpHost​(java.lang.String hostname, int port)
      Creates HttpHost instance with the default scheme and the given hostname and port.
      HttpHost​(java.lang.String hostname, int port, java.lang.String scheme)
      Creates HttpHost instance with the given scheme, hostname and port.
      HttpHost​(java.net.InetAddress address)
      Creates HttpHost instance with the default scheme and port and the given inet address.
      HttpHost​(java.net.InetAddress address, int port)
      Creates HttpHost instance with the default scheme and the given inet address and port.
      HttpHost​(java.net.InetAddress address, int port, java.lang.String scheme)
      Creates HttpHost instance with the given scheme, inet address and port.
      HttpHost​(java.net.InetAddress address, java.lang.String hostname, int port, java.lang.String scheme)
      Creates a new HttpHost, specifying all values.
      HttpHost​(HttpHost httphost)
      Copy constructor for HttpHost.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      static HttpHost create​(java.lang.String s)
      Creates HttpHost instance from string.
      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.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_SCHEME_NAME

        public static final java.lang.String DEFAULT_SCHEME_NAME
        The default scheme is "http".
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpHost

        public HttpHost​(java.lang.String hostname,
                        int port,
                        java.lang.String scheme)
        Creates HttpHost instance with the given scheme, hostname and port.
        Parameters:
        hostname - the hostname (IP or DNS name)
        port - the port number. -1 indicates the scheme default port.
        scheme - the name of the scheme. null indicates the default scheme
      • HttpHost

        public HttpHost​(java.lang.String hostname,
                        int port)
        Creates HttpHost 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.
      • HttpHost

        public HttpHost​(java.lang.String hostname)
        Creates HttpHost instance with the default scheme and port and the given hostname.
        Parameters:
        hostname - the hostname (IP or DNS name)
      • HttpHost

        public HttpHost​(java.net.InetAddress address,
                        int port,
                        java.lang.String scheme)
        Creates HttpHost instance with the given scheme, inet address and port.
        Parameters:
        address - the inet address.
        port - the port number. -1 indicates the scheme default port.
        scheme - the name of the scheme. null indicates the default scheme
        Since:
        4.3
      • HttpHost

        public HttpHost​(java.net.InetAddress address,
                        java.lang.String hostname,
                        int port,
                        java.lang.String scheme)
        Creates a new HttpHost, specifying all values. Constructor for HttpHost.
        Parameters:
        address - the inet address.
        hostname - the hostname (IP or DNS name)
        port - the port number. -1 indicates the scheme default port.
        scheme - the name of the scheme. null indicates the default scheme
        Since:
        4.4
      • HttpHost

        public HttpHost​(java.net.InetAddress address,
                        int port)
        Creates HttpHost 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.
        Since:
        4.3
      • HttpHost

        public HttpHost​(java.net.InetAddress address)
        Creates HttpHost instance with the default scheme and port and the given inet address.
        Parameters:
        address - the inet address.
        Since:
        4.3
      • HttpHost

        public HttpHost​(HttpHost httphost)
        Copy constructor for HttpHost.
        Parameters:
        httphost - the HTTP host to copy details from
    • Method Detail

      • create

        public static HttpHost create​(java.lang.String s)
        Creates HttpHost instance from string. Text may not contain any blanks.
        Since:
        4.4
      • getHostName

        public java.lang.String getHostName()
        Returns the host name.
        Returns:
        the host name (IP or DNS name)
      • getPort

        public int getPort()
        Returns the port.
        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 class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Throws:
        java.lang.CloneNotSupportedException