Class HttpClientUtil

java.lang.Object
org.seppiko.commons.utils.http.HttpClientUtil

public class HttpClientUtil
extends java.lang.Object
Http Client Util with java.net.http
Author:
Leonard Woo
  • Constructor Summary

    Constructors
    Constructor Description
    HttpClientUtil()  
  • Method Summary

    Modifier and Type Method Description
    static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, byte[] requestBody)
    Get Request object with byte array
    static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, java.io.InputStream requestBody)
    Get Request object with inputstream
    static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, java.lang.String requestBody)
    Get Request object with String
    static java.net.http.HttpResponse<byte[]> getResponseByteArray​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)
    Get Response with byte array body
    static java.net.http.HttpResponse<java.io.InputStream> getResponseInputStream​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)
    Get Response with inputstream body
    static java.net.http.HttpResponse<java.lang.String> getResponseString​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)
    Get Response with String body

    Methods inherited from class java.lang.Object

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

    • HttpClientUtil

      public HttpClientUtil()
  • Method Details

    • getRequest

      public static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, java.lang.String requestBody) throws java.net.URISyntaxException
      Get Request object with String
      Parameters:
      url - URL
      method - see HttpMethod
      timeout - Timeout
      headers - Headers
      requestBody - Request body string
      Returns:
      HttpRequest object
      Throws:
      java.net.URISyntaxException - URL is an illegal address
    • getRequest

      public static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, java.io.InputStream requestBody) throws java.net.URISyntaxException
      Get Request object with inputstream
      Parameters:
      url - URL
      method - see HttpMethod
      timeout - Timeout
      headers - Headers
      requestBody - Request body inputstream
      Returns:
      HttpRequest object
      Throws:
      java.net.URISyntaxException - URL is an illegal address
    • getRequest

      public static java.net.http.HttpRequest getRequest​(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,​java.util.ArrayList<java.lang.String>> headers, byte[] requestBody) throws java.net.URISyntaxException
      Get Request object with byte array
      Parameters:
      url - URL
      method - see HttpMethod
      timeout - Timeout
      headers - Headers
      requestBody - Request body byte array
      Returns:
      HttpRequest object
      Throws:
      java.net.URISyntaxException - URL is an illegal address
    • getResponseString

      public static java.net.http.HttpResponse<java.lang.String> getResponseString​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientException
      Get Response with String body
      Parameters:
      req - HttpRequest object
      proxy - Not null is enable proxy
      Returns:
      HttpResponse object, if NULL has failed
      Throws:
      HttpClientException - get response exception
    • getResponseByteArray

      public static java.net.http.HttpResponse<byte[]> getResponseByteArray​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientException
      Get Response with byte array body
      Parameters:
      req - HttpRequest object
      proxy - Not null is enable proxy
      Returns:
      HttpResponse object, if NULL has failed
      Throws:
      HttpClientException - get response exception
    • getResponseInputStream

      public static java.net.http.HttpResponse<java.io.InputStream> getResponseInputStream​(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientException
      Get Response with inputstream body
      Parameters:
      req - HttpRequest object
      proxy - Not null is enable proxy
      Returns:
      HttpResponse object, if NULL has failed
      Throws:
      HttpClientException - get response exception