Class HTTP


  • public class HTTP
    extends java.lang.Object
    This class provides functions to do HTTP related operations. We will try to extract http related credentials from the hostProps if existed.
    The following properties may be used:
    property name property note
    http.user / httpuser the username for basic authentication
    http.pass / httppass the password for basic authentication
    • Constructor Summary

      Constructors 
      Constructor Description
      HTTP()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String body​(java.lang.String url)
      do an HTTP GET on the provided url and return only the HTTP body
      static java.lang.String body​(java.lang.String url, java.lang.String username, java.lang.String password)
      do an HTTP GET on the provided url and return only the HTTP body
      static java.lang.String delete​(java.lang.String url, java.lang.String data)
      do an HTTP DELETE to the provided url and return the entire response
      static java.lang.String delete​(java.lang.String url, java.lang.String data, java.util.Map headers)
      do an HTTP DELETE to the provided url and return the entire response
      static java.lang.String delete​(java.lang.String url, java.util.Map headers)
      do an HTTP DELETE to the provided url and return the entire response
      static java.lang.String get​(java.lang.String url)
      do an HTTP GET on the provided url and return the entire HTTP response
      static java.lang.String get​(java.lang.String url, java.lang.String username, java.lang.String password)
      do an HTTP GET on the provided url and return the entire HTTP response
      static java.lang.String get​(java.lang.String url, java.lang.String username, java.lang.String password, java.util.Map headers)
      do an HTTP GET on the provided url and return the entire HTTP response
      static java.lang.String get​(java.lang.String url, java.util.Map headers)
      do an HTTP GET on the provided url and return the entire HTTP response
      static java.lang.String headers​(java.lang.String url)
      do an HTTP GET on the provided url and return only the HTTP headers
      static java.lang.String headers​(java.lang.String url, java.lang.String username, java.lang.String password)
      do an HTTP GET on the provided url and return only the HTTP headers
      static Client open​(java.lang.String host, int port)
      instantiate a non-ssl HTTP session object for use across multiple HTTP transactions
      Will try to extract http credentials from the related hostProps if existed
      static Client open​(java.lang.String host, int port, boolean ssl)
      instantiate an HTTP session object for use across multiple HTTP transactions
      Will try to extract http credentials from the related hostProps if existed
      static java.lang.String post​(java.lang.String url, java.lang.String data)
      do an HTTP POST to the provided url and return the entire response
      static java.lang.String post​(java.lang.String url, java.lang.String data, java.util.Map headers)
      do an HTTP POST to the provided url and return the entire response
      static java.lang.String put​(java.lang.String url, java.lang.String data)
      do an HTTP PUT to the provided url and return the entire response
      static java.lang.String put​(java.lang.String url, java.lang.String data, java.util.Map headers)
      do an HTTP PUT to the provided url and return the entire response
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HTTP

        public HTTP()
    • Method Detail

      • open

        public static Client open​(java.lang.String host,
                                  int port)
                           throws java.io.IOException
        instantiate a non-ssl HTTP session object for use across multiple HTTP transactions
        Will try to extract http credentials from the related hostProps if existed
        Parameters:
        host - The url of http host
        port - The host http port
        Returns:
        Http client
        Throws:
        java.io.IOException - If some other I/O error occurs
      • open

        public static Client open​(java.lang.String host,
                                  int port,
                                  boolean ssl)
                           throws java.io.IOException
        instantiate an HTTP session object for use across multiple HTTP transactions
        Will try to extract http credentials from the related hostProps if existed
        Parameters:
        host - The url of http host
        port - The host http port
        ssl - Is this a ssl connection
        Returns:
        Http client
        Throws:
        java.io.IOException - If some other I/O error occurs
      • get

        public static java.lang.String get​(java.lang.String url)
                                    throws java.io.IOException
        do an HTTP GET on the provided url and return the entire HTTP response
        Parameters:
        url - The url of http host
        Returns:
        This url content
        Throws:
        java.io.IOException - If some other I/O error occurs
      • get

        public static java.lang.String get​(java.lang.String url,
                                           java.util.Map headers)
                                    throws java.io.IOException
        do an HTTP GET on the provided url and return the entire HTTP response
        Parameters:
        url - The url of http host
        headers - The http header with this http request
        Returns:
        This url content
        Throws:
        java.io.IOException - If some other I/O error occurs
      • get

        public static java.lang.String get​(java.lang.String url,
                                           java.lang.String username,
                                           java.lang.String password)
                                    throws java.io.IOException
        do an HTTP GET on the provided url and return the entire HTTP response
        Parameters:
        url - The url of http host
        username - This http host's username
        password - This http host's password
        Returns:
        This url content
        Throws:
        java.io.IOException - If some other I/O error occurs
      • get

        public static java.lang.String get​(java.lang.String url,
                                           java.lang.String username,
                                           java.lang.String password,
                                           java.util.Map headers)
                                    throws java.io.IOException
        do an HTTP GET on the provided url and return the entire HTTP response
        Parameters:
        url - The url of http host
        username - This http host's username
        password - This http host's password
        headers - The http header with this http request
        Returns:
        This url content
        Throws:
        java.io.IOException - If some other I/O error occurs
      • headers

        public static java.lang.String headers​(java.lang.String url)
                                        throws java.io.IOException
        do an HTTP GET on the provided url and return only the HTTP headers
        Parameters:
        url - Http url
        Returns:
        All http response headers
        Throws:
        java.io.IOException - If some other I/O error occurs
      • headers

        public static java.lang.String headers​(java.lang.String url,
                                               java.lang.String username,
                                               java.lang.String password)
                                        throws java.io.IOException
        do an HTTP GET on the provided url and return only the HTTP headers
        Parameters:
        url - Http url
        username - Auth username
        password - Auth password
        Returns:
        All http response header
        Throws:
        java.io.IOException - If some other I/O error occurs
      • body

        public static java.lang.String body​(java.lang.String url)
                                     throws java.io.IOException
        do an HTTP GET on the provided url and return only the HTTP body
        Parameters:
        url - Http url
        Returns:
        Http response body string value
        Throws:
        java.io.IOException - If some other I/O error occurs
      • body

        public static java.lang.String body​(java.lang.String url,
                                            java.lang.String username,
                                            java.lang.String password)
                                     throws java.io.IOException
        do an HTTP GET on the provided url and return only the HTTP body
        Parameters:
        url - Http url
        username - Auth username
        password - Auth password
        Returns:
        Http response body string value
        Throws:
        java.io.IOException - If some other I/O error occurs
      • post

        public static java.lang.String post​(java.lang.String url,
                                            java.lang.String data)
                                     throws java.io.IOException
        do an HTTP POST to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http post request data
        Returns:
        Http response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • post

        public static java.lang.String post​(java.lang.String url,
                                            java.lang.String data,
                                            java.util.Map headers)
                                     throws java.io.IOException
        do an HTTP POST to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http post request data
        headers - This http post request header
        Returns:
        This http post response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • put

        public static java.lang.String put​(java.lang.String url,
                                           java.lang.String data)
                                    throws java.io.IOException
        do an HTTP PUT to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http put request data
        Returns:
        Http response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • put

        public static java.lang.String put​(java.lang.String url,
                                           java.lang.String data,
                                           java.util.Map headers)
                                    throws java.io.IOException
        do an HTTP PUT to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http put request data
        headers - This http put request header
        Returns:
        This http put response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • delete

        public static java.lang.String delete​(java.lang.String url,
                                              java.util.Map headers)
                                       throws java.io.IOException
        do an HTTP DELETE to the provided url and return the entire response
        Parameters:
        url - Http url
        headers - This http delete request header
        Returns:
        Http response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • delete

        public static java.lang.String delete​(java.lang.String url,
                                              java.lang.String data)
                                       throws java.io.IOException
        do an HTTP DELETE to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http delete request data
        Returns:
        Http response string
        Throws:
        java.io.IOException - If some other I/O error occurs
      • delete

        public static java.lang.String delete​(java.lang.String url,
                                              java.lang.String data,
                                              java.util.Map headers)
                                       throws java.io.IOException
        do an HTTP DELETE to the provided url and return the entire response
        Parameters:
        url - Http url
        data - This http delete request data
        headers - This http delete request header
        Returns:
        This http delete response string
        Throws:
        java.io.IOException - If some other I/O error occurs