public class HttpRequestConnector extends Object
Modifier and Type | Class and Description |
---|---|
static class |
HttpRequestConnector.BinaryFile
Handler for streaming a binary file in a multi-part
request.
|
static class |
HttpRequestConnector.HttpMethod |
static class |
HttpRequestConnector.ParamType |
static class |
HttpRequestConnector.ResponseOption
Options for processing the HTTP response
|
Modifier and Type | Field and Description |
---|---|
static String |
HTTP_CONTENT_TYPE_CSV |
static String |
HTTP_CONTENT_TYPE_JSON |
static String |
HTTP_CONTENT_TYPE_MULTIPART_FORM |
static String |
HTTP_CONTENT_TYPE_MULTIPART_FORM_BOUNDARY |
static String |
HTTP_CONTENT_TYPE_OCTET |
static String |
HTTP_CONTENT_TYPE_PLAINTEXT |
static String |
HTTP_CONTENT_TYPE_SCIM_JSON |
static String |
HTTP_CONTENT_TYPE_XFORM |
static String |
HTTP_HEADER_ACCEPT |
static String |
HTTP_HEADER_CONTENT_LENGTH |
static String |
HTTP_HEADER_CONTENT_MD5 |
static String |
HTTP_HEADER_CONTENT_TYPE |
static String |
HTTP_HEADER_RANGE |
Constructor and Description |
---|
HttpRequestConnector(String url)
Constructor for an HTTP request to a given URL
|
Modifier and Type | Method and Description |
---|---|
void |
addBinary(String mediaType,
byte[] binaryContent)
Add a file in multipart/form-data request.
|
void |
addBodyParam(String name,
Object value)
Add a body name/value pair to the request
|
void |
addBodyParamMultiPart(String name,
Object value)
Add a body name/value pair to the request
|
void |
addFile(String mediaType,
String filePath)
Add a file to the request, such as "--data-binary" POST request,
in which the file is the only entity in the post request.
|
void |
addFileBinary(String name,
byte[] binaryContent,
String fileName)
Add a binary content of a file in multipart/form-data request.
|
void |
addFileMultiPart(String name,
String filePath)
Add a file in multipart/form-data request.
|
void |
addHeaderParam(String name,
Object value)
Add a header name/value pair to the request
|
void |
addQueryParam(String name,
Object value)
Add a query name/value pair to the request
|
void |
addRawString(String mediaType,
String rawString)
Add a string to the request, such as POST of raw data
|
protected Map<String,Object> |
encodeMap(Map<String,Object> map)
Encode the value in a map of name/value pairs
|
Map<String,Object> |
getBodyParams() |
Map<String,Object> |
getHeaderParams() |
Map<String,Object> |
getQueryParams() |
String |
getUrl() |
protected String |
getUrl(String url,
Map<String,Object> queryParams)
Form a URL with request params.
|
HttpResponseConnector |
send(HttpRequestConnector.HttpMethod method)
Perform an HTTP call based on the class properties
(url, queryParams, headerParams, bodyParams)
for the provided HTTP Method.
|
HttpResponseConnector |
send(HttpRequestConnector.HttpMethod method,
HttpRequestConnector.ResponseOption responseOption)
Perform an HTTP call based on the class properties
(url, queryParams, headerParams, bodyParams)
for the provided HTTP Method.
|
HttpResponseConnector |
send(HttpRequestConnector.HttpMethod method,
HttpRequestConnector.ResponseOption responseOption,
String outputFilePath)
Perform an HTTP call based on the class properties
(url, queryParams, headerParams, bodyParams)
for the provided HTTP Method.
|
HttpResponseConnector |
sendDelete()
Perform an HTTP DELETE
|
HttpResponseConnector |
sendGet()
Perform an HTTP GET with default response processing (as a string)
|
HttpResponseConnector |
sendGet(HttpRequestConnector.ResponseOption responseOption)
Perform an HTTP GET while specifying the response processing option
|
HttpResponseConnector |
sendGet(String outputFilePath)
Perform an HTTP GET and writing the response to the specified file.
|
HttpResponseConnector |
sendPost()
Perform an HTTP POST
|
HttpResponseConnector |
sendPut()
Perform an HTTP PUT
|
void |
setBodyParams(Map<String,Object> bodyParams) |
static void |
setGlobalTimeout(int minutes)
Set the global timeout for the HTTP Client.
|
void |
setHeaderParams(Map<String,Object> headerParams) |
void |
setQueryParams(Map<String,Object> queryParams) |
void |
setUrl(String url) |
public static final String HTTP_HEADER_CONTENT_TYPE
public static final String HTTP_HEADER_ACCEPT
public static final String HTTP_HEADER_CONTENT_MD5
public static final String HTTP_HEADER_RANGE
public static final String HTTP_HEADER_CONTENT_LENGTH
public static final String HTTP_CONTENT_TYPE_CSV
public static final String HTTP_CONTENT_TYPE_JSON
public static final String HTTP_CONTENT_TYPE_SCIM_JSON
public static final String HTTP_CONTENT_TYPE_OCTET
public static final String HTTP_CONTENT_TYPE_PLAINTEXT
public static final String HTTP_CONTENT_TYPE_XFORM
public static final String HTTP_CONTENT_TYPE_MULTIPART_FORM
public static final String HTTP_CONTENT_TYPE_MULTIPART_FORM_BOUNDARY
public HttpRequestConnector(String url)
url
- Endpoint for the HTTP callpublic HttpResponseConnector send(HttpRequestConnector.HttpMethod method)
method
- The HttpMethod for the request (GET, POST, PUT, DELETE)public HttpResponseConnector send(HttpRequestConnector.HttpMethod method, HttpRequestConnector.ResponseOption responseOption)
method
- The HttpMethod for the request (GET, POST, PUT, DELETE)responseOption
- The format to return the HTTP responsepublic HttpResponseConnector send(HttpRequestConnector.HttpMethod method, HttpRequestConnector.ResponseOption responseOption, String outputFilePath)
method
- The HttpMethod for the request (GET, POST, PUT, DELETE)responseOption
- The format to return the HTTP responseoutputFilePath
- Optional output file to write, pass null to ignorepublic HttpResponseConnector sendGet()
public HttpResponseConnector sendGet(HttpRequestConnector.ResponseOption responseOption)
responseOption
- Option for processing the response as string, inputstream, byte array, etc.public HttpResponseConnector sendGet(String outputFilePath)
outputFilePath
- The output file path to write topublic HttpResponseConnector sendPost()
public HttpResponseConnector sendPut()
public HttpResponseConnector sendDelete()
protected String getUrl(String url, Map<String,Object> queryParams)
url
- Endpoint for the HTTP callqueryParams
- (Optional) Request parameters to add to the URL string. Pass null if none.protected Map<String,Object> encodeMap(Map<String,Object> map)
map
- Name/Value pairs to encodepublic String getUrl()
public void setUrl(String url)
public void addQueryParam(String name, Object value)
name
- The parameter namevalue
- The parameter valuepublic void addHeaderParam(String name, Object value)
name
- The parameter namevalue
- The parameter valuepublic void addBodyParam(String name, Object value)
name
- The body parameter namevalue
- The body parameter valuepublic void addBodyParamMultiPart(String name, Object value)
name
- The body parameter namevalue
- The body parameter valuepublic void addFile(String mediaType, String filePath)
mediaType
- The media type of the filefilePath
- Absolute file path of file to stream in the requestpublic void addRawString(String mediaType, String rawString)
mediaType
- The media type of the raw stringrawString
- The data as a stringpublic void addBinary(String mediaType, byte[] binaryContent)
mediaType
- The media type of the raw stringbinaryContent
- Absolute file path of file to uploadpublic void addFileMultiPart(String name, String filePath)
name
- The name of the body param in the multipart/form-data requestfilePath
- Absolute file path of file to uploadpublic void addFileBinary(String name, byte[] binaryContent, String fileName)
name
- The name of the body param in the multipart/form-data requestbinaryContent
- Binary content of the filefileName
- The name of the file for receiving server to createpublic static void setGlobalTimeout(int minutes)
Can only be set before any and all HTTP calls are first executed
minutes
- Number of minutes before http timeout occursCopyright © 2021. All rights reserved.