Package io.keyko.common.helpers
Class HttpHelper
- java.lang.Object
-
- io.keyko.common.helpers.HttpHelper
-
public abstract class HttpHelper extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
HttpHelper.DownloadResponseHandler
static class
HttpHelper.DownloadResult
-
Constructor Summary
Constructors Modifier Constructor Description private
HttpHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
download(String url, String destinationPath)
Download the content of a resourcestatic InputStream
download(String url, Map<String,String> headers, Boolean isRangeRequest, Integer startRange, Integer endRange)
Download the content of a resourcestatic HttpHelper.DownloadResult
downloadResource(String url, String destinationPath)
Download the content of a resourcestatic HttpResponse
httpClientDelete(String url)
Send a HTTP DELETE request and return the HttpResponse objectstatic HttpResponse
httpClientGenericMethod(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload)
Send a HTTP request with parameters and return the HttpResponse objectstatic HttpResponse
httpClientGenericMethod(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload, Map<String,String> headers)
Send a HTTP request with parameters and return the HttpResponse objectstatic HttpResponse
httpClientGenericMethod(org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload)
Send a HTTP request with parameters and return the HttpResponse objectstatic HttpResponse
httpClientGet(String url)
Send a HTTP GET request and return the HttpResponse objectstatic HttpResponse
httpClientGet(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.GetMethod getMethod)
Send a HTTP GET request and return the HttpResponse objectstatic HttpResponse
httpClientHead(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.HeadMethod headMethod)
Send a HTTP HEAD request and return the HttpResponse objectstatic HttpResponse
httpClientPost(String url)
Send a HTTP POST request and return the HttpResponse objectstatic HttpResponse
httpClientPost(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload)
Send a HTTP POST request and return the HttpResponse objectstatic HttpResponse
httpClientPost(String url, Map<String,String> headers)
Send a HTTP POST request and return the HttpResponse objectstatic String
httpClientPostBody(String url)
Send a HTTP POST request and return the bodystatic String
httpClientPostBody(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list)
Send a HTTP POST request with parameters and return the bodystatic HttpResponse
httpClientPut(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload)
Send a HTTP PUT request and return the HttpResponse objectstatic HttpResponse
httpClientRead(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.HttpMethodBase method)
Send a HTTP GET or HEAD request and return the HttpResponse object
-
-
-
Field Detail
-
UTF8
public static final String UTF8
- See Also:
- Constant Field Values
-
-
Method Detail
-
httpClientPostBody
public static final String httpClientPostBody(String url) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP POST request and return the body- Parameters:
url
- url to call- Returns:
- returned http body
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientPostBody
public static final String httpClientPostBody(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP POST request with parameters and return the body- Parameters:
url
- url to calllist
- parameters- Returns:
- returned http body
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientPost
public static final HttpResponse httpClientPost(String url) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP POST request and return the HttpResponse object- Parameters:
url
- url to call- Returns:
- HttpResponse returned
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientPost
public static final HttpResponse httpClientPost(String url, Map<String,String> headers) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP POST request and return the HttpResponse object- Parameters:
url
- url to callheaders
- http headers- Returns:
- HttpResponse returned
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientPost
public static final HttpResponse httpClientPost(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP POST request and return the HttpResponse object- Parameters:
url
- url to calllist
- parameterspayload
- payload to add to the request- Returns:
- HttpResponse returned
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientPut
public static final HttpResponse httpClientPut(String url, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP PUT request and return the HttpResponse object- Parameters:
url
- url to calllist
- parameterspayload
- payload to add to the request- Returns:
- HttpResponse returned
- Throws:
org.apache.commons.httpclient.HttpException
- Http errorUnsupportedEncodingException
- Encoding error
-
httpClientGenericMethod
public static final HttpResponse httpClientGenericMethod(org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP request with parameters and return the HttpResponse object- Parameters:
method
- EntityEnclosingMethodlist
- list of paramspayload
- payload to add to the request- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpExceptionUnsupportedEncodingException
- UnsupportedEncodingException
-
httpClientGenericMethod
public static final HttpResponse httpClientGenericMethod(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP request with parameters and return the HttpResponse object- Parameters:
client
- HttpClientmethod
- EntityEnclosingMethodlist
- list of paramspayload
- payload to add to the request- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpExceptionUnsupportedEncodingException
- UnsupportedEncodingException
-
httpClientGenericMethod
public static final HttpResponse httpClientGenericMethod(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.EntityEnclosingMethod method, ArrayList<org.apache.commons.httpclient.NameValuePair> list, String payload, Map<String,String> headers) throws org.apache.commons.httpclient.HttpException, UnsupportedEncodingException
Send a HTTP request with parameters and return the HttpResponse object- Parameters:
client
- HttpClientmethod
- EntityEnclosingMethodlist
- list of paramspayload
- payload to add to the requestheaders
- Http headers- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpExceptionUnsupportedEncodingException
- UnsupportedEncodingException
-
httpClientGet
public static final HttpResponse httpClientGet(String url) throws org.apache.commons.httpclient.HttpException
Send a HTTP GET request and return the HttpResponse object- Parameters:
url
- the url- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpException
-
httpClientGet
public static final HttpResponse httpClientGet(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.GetMethod getMethod) throws org.apache.commons.httpclient.HttpException
Send a HTTP GET request and return the HttpResponse object- Parameters:
client
- HttpClientgetMethod
- GetMethod- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpException
-
httpClientHead
public static final HttpResponse httpClientHead(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.methods.HeadMethod headMethod) throws org.apache.commons.httpclient.HttpException
Send a HTTP HEAD request and return the HttpResponse object- Parameters:
client
- HttpClientheadMethod
- HeadMethod- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpException
-
httpClientRead
public static final HttpResponse httpClientRead(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.HttpMethodBase method) throws org.apache.commons.httpclient.HttpException
Send a HTTP GET or HEAD request and return the HttpResponse object- Parameters:
client
- HttpClientmethod
- HttpMethodBase- Returns:
- HttpResponse
- Throws:
org.apache.commons.httpclient.HttpException
- HttpException
-
downloadResource
public static HttpHelper.DownloadResult downloadResource(String url, String destinationPath) throws IOException, URISyntaxException
Download the content of a resource- Parameters:
url
- the url of the resourcedestinationPath
- the path where the resource will be downloaded- Returns:
- Boolean flag
- Throws:
IOException
- IOExceptionURISyntaxException
- URISyntaxException
-
download
public static void download(String url, String destinationPath) throws IOException
Download the content of a resource- Parameters:
url
- the url of the resourcedestinationPath
- the path where the resource will be downloaded- Throws:
IOException
- Exception during the download
-
download
public static InputStream download(String url, Map<String,String> headers, Boolean isRangeRequest, Integer startRange, Integer endRange) throws IOException
Download the content of a resource- Parameters:
url
- the urlheaders
- http headersisRangeRequest
- indicates if is a range requeststartRange
- the start of the bytes rangeendRange
- the end of the bytes range- Returns:
- an InputStream that represents the binary content
- Throws:
IOException
- Exception during the download
-
httpClientDelete
public static final HttpResponse httpClientDelete(String url) throws org.apache.commons.httpclient.HttpException
Send a HTTP DELETE request and return the HttpResponse object- Parameters:
url
- url to call- Returns:
- HttpResponse returned
- Throws:
org.apache.commons.httpclient.HttpException
- Http error
-
-