Class HttpClientUtil


  • public class HttpClientUtil
    extends Object
    Utility class contained useful methods while working with HttpClient
    Since:
    06-27-2017
    Author:
    Yury_Bakhmutski
    • Constructor Detail

      • HttpClientUtil

        public HttpClientUtil()
    • Method Detail

      • responseToString

        public static String responseToString​(org.apache.http.HttpResponse response)
                                       throws IOException
        Parameters:
        response - the httpresponse for processing
        Returns:
        HttpEntity in String representation using "UTF-8" encoding
        Throws:
        IOException
      • responseToString

        public static String responseToString​(org.apache.http.HttpResponse response,
                                              Charset charset)
                                       throws IOException
        Parameters:
        response - the httpresponse for processing
        charset - the charset used for getting HttpEntity
        Returns:
        HttpEntity in decoded String representation using provided charset
        Throws:
        IOException
      • responseToString

        public static String responseToString​(org.apache.http.HttpResponse response,
                                              Charset charset,
                                              boolean decode)
                                       throws IOException
        Parameters:
        response - the httpresponse for processing
        charset - the charset used for getting HttpEntity
        decode - determines if the result should be decoded or not
        Returns:
        HttpEntity in String representation using provided charset
        Throws:
        IOException
      • responseToByteArray

        public static byte[] responseToByteArray​(org.apache.http.HttpResponse response)
                                          throws IOException
        Throws:
        IOException
      • createPreemptiveBasicAuthentication

        public static org.apache.http.client.protocol.HttpClientContext createPreemptiveBasicAuthentication​(String host,
                                                                                                            int port,
                                                                                                            String user,
                                                                                                            String password,
                                                                                                            String schema)
        Returns context with AuthCache or null in case of any exception was thrown.
        Parameters:
        host -
        port -
        user -
        password -
        schema -
        Returns:
        HttpClientContext
      • createPreemptiveBasicAuthentication

        public static org.apache.http.client.protocol.HttpClientContext createPreemptiveBasicAuthentication​(String host,
                                                                                                            int port,
                                                                                                            String user,
                                                                                                            String password)
        Returns context with AuthCache or null in case of any exception was thrown. Use "http" schema.
        Parameters:
        host -
        port -
        user -
        password -
        Returns:
        HttpClientContext