java.lang.Object
org.seppiko.commons.utils.http.HttpClientUtil
Http Client Util with java.net.http
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequestgetRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, byte[] requestBody) Get Request object with byte arraystatic HttpRequestgetRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, InputStream requestBody) Get Request object with inputstreamstatic HttpRequestgetRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, String requestBody) Get Request object with Stringstatic HttpResponse<byte[]>getResponseByteArray(HttpRequest req, InetSocketAddress proxy) Get Response with byte array bodystatic HttpResponse<InputStream>getResponseInputStream(HttpRequest req, InetSocketAddress proxy) Get Response with inputstream bodystatic HttpResponse<String>getResponseString(HttpRequest req, InetSocketAddress proxy) Get Response with String bodystatic <R,T> HttpResponse<?> sendRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, R requestBody, Class<T> responseType, InetSocketAddress proxy) send http request
-
Constructor Details
-
HttpClientUtil
public HttpClientUtil()
-
-
Method Details
-
getRequest
public static HttpRequest getRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, String requestBody) throws URISyntaxException, IllegalArgumentException, NullPointerException Get Request object with String- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body string- Returns:
- HttpRequest object
- Throws:
URISyntaxException- URL is an illegal addressIllegalArgumentException- something not supported or undefinedNullPointerException- something is null
-
getRequest
public static HttpRequest getRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, InputStream requestBody) throws URISyntaxException Get Request object with inputstream- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body inputstream- Returns:
- HttpRequest object
- Throws:
URISyntaxException- URL is an illegal address
-
getRequest
public static HttpRequest getRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, byte[] requestBody) throws URISyntaxException Get Request object with byte array- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body byte array- Returns:
- HttpRequest object
- Throws:
URISyntaxException- URL is an illegal address
-
getResponseString
public static HttpResponse<String> getResponseString(HttpRequest req, InetSocketAddress proxy) throws HttpClientException Get Response with String body- Parameters:
req- HttpRequest objectproxy- Http proxy, Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-
getResponseByteArray
public static HttpResponse<byte[]> getResponseByteArray(HttpRequest req, InetSocketAddress proxy) throws HttpClientException Get Response with byte array body- Parameters:
req- HttpRequest objectproxy- Http proxy, Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-
getResponseInputStream
public static HttpResponse<InputStream> getResponseInputStream(HttpRequest req, InetSocketAddress proxy) throws HttpClientException Get Response with inputstream body- Parameters:
req- HttpRequest objectproxy- Http proxy, Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-
sendRequest
public static <R,T> HttpResponse<?> sendRequest(String url, HttpMethod method, int timeout, HttpHeaders headers, R requestBody, Class<T> responseType, InetSocketAddress proxy) throws URISyntaxException, HttpClientException send http request- Type Parameters:
R- request type (String, InputStream and byte[])T- response type (String, InputStream and byte[])- Parameters:
url- URLmethod- request http methodtimeout- request timeoutheaders- request headers, if none is nullrequestBody- request body, is none is nullresponseType- response type, default is byte arrayproxy- request http proxy, if had not is null- Returns:
- http response
- Throws:
URISyntaxException- URL is an illegal addressHttpClientException- get response exception
-