public final class HttpConnectionUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
HttpConnectionUtils.FlakyDownloadException
Downloaded file error.
|
static class |
HttpConnectionUtils.ResponseError
HTTP response error storage.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
CHARSET_MARK |
protected static java.lang.String |
DEFAULT_RESPONSE_CHARSET |
Modifier and Type | Method and Description |
---|---|
static boolean |
downloadBinaryFile(java.net.URL fileURL,
java.util.Map<java.lang.String,java.lang.String> headers,
java.util.Set<java.lang.String> expectedMime,
java.io.File saveFilePath)
Downloads a binary file from a URL.
|
static void |
downloadZipFileAndExtract(java.net.URL url,
java.io.File dir,
java.util.List<java.lang.String> expectedFiles)
Download Zip file from remote site and extract it to specified directory.
|
static java.lang.String |
get(java.lang.String address,
java.util.Map<java.lang.String,java.lang.String> params,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders)
Get data from the remote URL.
|
static java.lang.String |
get(java.lang.String address,
java.util.Map<java.lang.String,java.lang.String> params,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders,
java.lang.String defaultOutputCharset)
Get data from the remote URL.
|
static java.lang.String |
getURL(java.net.URL url)
Get resource from URL with default timeout.
|
static java.lang.String |
getURL(java.net.URL url,
int timeout)
Download a file to memory.
|
static byte[] |
getURLasByteArray(java.lang.String target)
Obtain byte array context from remote URL.
|
static java.lang.String |
post(java.lang.String address,
java.util.Map<java.lang.String,java.lang.String> params)
Method call without additional headers for possible calls from plugins.
|
static java.lang.String |
post(java.lang.String address,
java.util.Map<java.lang.String,java.lang.String> params,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders)
Post data to the remote URL.
|
static java.lang.String |
postJSON(java.lang.String address,
java.lang.String json,
java.util.Map<java.lang.String,java.lang.String> additionalHeaders)
Post JSON data to the remote URL.
|
protected static final java.lang.String DEFAULT_RESPONSE_CHARSET
protected static final java.lang.String CHARSET_MARK
public static java.lang.String getURL(java.net.URL url) throws java.io.IOException
url
- resource URL.java.io.IOException
- raises when connection is failed.public static java.lang.String getURL(java.net.URL url, int timeout) throws java.io.IOException
url
- resource URL to downloadtimeout
- timeout to connect and read.java.io.IOException
- when connection and read method error.public static void downloadZipFileAndExtract(java.net.URL url, java.io.File dir, java.util.List<java.lang.String> expectedFiles) throws java.io.IOException
url
- URL of zip file resource to download.dir
- target directory to extractexpectedFiles
- filter extract file namesjava.io.IOException
- raises when extraction is failed, maybe flaky download happened.public static boolean downloadBinaryFile(java.net.URL fileURL, java.util.Map<java.lang.String,java.lang.String> headers, java.util.Set<java.lang.String> expectedMime, java.io.File saveFilePath) throws java.io.IOException, HttpConnectionUtils.FlakyDownloadException
fileURL
- HTTP URL of the file to be downloadedheaders
- Additional HTTP headersexpectedMime
- Mime type expected and check against such as ["application/octet-stream",
"application/jar-archive"]. If getting type is differed, return false.saveFilePath
- path of the filejava.io.IOException
- raise when connection and file write failed.HttpConnectionUtils.FlakyDownloadException
- raise when downloaded file length differs from expected content length.public static byte[] getURLasByteArray(java.lang.String target) throws java.io.IOException
target
- String representation of well-formed URL.java.io.IOException
- raise when connection failed.public static java.lang.String post(java.lang.String address, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
address
- URL to postparams
- post parameters in Mapjava.io.IOException
- raises when connection failed.public static java.lang.String get(java.lang.String address, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> additionalHeaders) throws java.io.IOException
address
- address to postparams
- parametersadditionalHeaders
- additional headers for request, can be nulljava.io.IOException
public static java.lang.String get(java.lang.String address, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.String defaultOutputCharset) throws java.io.IOException
address
- address to postparams
- parametersadditionalHeaders
- additional headers for request, can be nulldefaultOutputCharset
- default charset used to interpret the responsejava.io.IOException
public static java.lang.String post(java.lang.String address, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> additionalHeaders) throws java.io.IOException
address
- address to postparams
- parametersadditionalHeaders
- additional headers for request, can be nulljava.io.IOException
public static java.lang.String postJSON(java.lang.String address, java.lang.String json, java.util.Map<java.lang.String,java.lang.String> additionalHeaders) throws java.io.IOException
address
- address to postjson
- JSON-encoded dataadditionalHeaders
- additional headers for request, can be nulljava.io.IOException