Class HttpHost

java.lang.Object
org.apache.http.HttpHost
All Implemented Interfaces:
Cloneable

public final class HttpHost
extends Object
implements Cloneable
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
Author:
Michael Becke, Mike Bowler, Oleg Kalnichevski, Laura Werner
  • Field Details

    • DEFAULT_SCHEME_NAME

      public static final String DEFAULT_SCHEME_NAME
      The default scheme is "http".
      See Also:
      Constant Field Values
    • hostname

      protected final String hostname
      The host to use.
    • lcHostname

      protected final String lcHostname
      The lowercase host, for equals(java.lang.Object) and hashCode().
    • port

      protected final int port
      The port to use.
    • schemeName

      protected final String schemeName
      The scheme
  • Constructor Details

    • HttpHost

      public HttpHost​(String hostname, int port, String scheme)
      Creates a new HttpHost, specifying all values. Constructor for HttpHost.
      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​(String hostname, int port)
      Creates a new HttpHost, with default scheme.
      Parameters:
      hostname - the hostname (IP or DNS name)
      port - the port number. -1 indicates the scheme default port.
    • HttpHost

      public HttpHost​(String hostname)
      Creates a new HttpHost, with default scheme and port.
      Parameters:
      hostname - the hostname (IP or DNS name)
    • HttpHost

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

    • getHostName

      public 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 String getSchemeName()
      Returns the scheme name.
      Returns:
      the scheme name
    • toURI

      public String toURI()
      Return the host URI, as a string.
      Returns:
      the host URI
    • toHostString

      public String toHostString()
      Obtains the host string, without scheme prefix.
      Returns:
      the host string, for example localhost:8080
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
         getClass().getName() + '@' + Integer.toHexString(hashCode())

      See Writing a useful toString method if you intend implementing your own toString method.

      Overrides:
      toString in class Object
      Returns:
      a printable representation of this object.
    • equals

      public boolean equals​(Object obj)
      Description copied from class: Object
      Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

      The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

      The general contract for the equals and Object.hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare this instance with.
      Returns:
      true if the specified object is equal to this Object; false otherwise.
      See Also:
      Object.hashCode()
    • hashCode

      public int hashCode()
      Description copied from class: Object
      Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

      Note that hash values must not change over time unless information used in equals comparisons also changes.

      See Writing a correct hashCode method if you intend implementing your own hashCode method.

      Overrides:
      hashCode in class Object
      Returns:
      this object's hash code.
      See Also:
      Object.hashCode()
    • clone

      public Object clone() throws CloneNotSupportedException
      Description copied from class: Object
      Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.
      Overrides:
      clone in class Object
      Returns:
      a copy of this object.
      Throws:
      CloneNotSupportedException - if this object's class does not implement the Cloneable interface.