Package com.veeva.vault.vapil.connector
Class HttpRequestConnector
java.lang.Object
com.veeva.vault.vapil.connector.HttpRequestConnector
HTTP request class, whether to the Vault API or other servers/APIs.
This is a generic set of methods with no Vault specific information.
It is used internally by VAPIL for all HTTP requests.
It can also be used
for integration specific HTTP calls (non-Vault).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Handler for streaming a binary file in a multi-part request.static enum
static enum
static enum
Options for processing the HTTP responsestatic final class
Handler class sending requests using an Input Stream -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for an HTTP request to a given URL -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a file in multipart/form-data request.void
addBodyParam
(String name, Object value) Add a body name/value pair to the requestvoid
addBodyParamMultiPart
(String name, Object value) Add a body name/value pair to the requestvoid
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 requestvoid
addInputStream
(String mediaType, InputStream inputStream) Add an inputStream to the request.void
addQueryParam
(String name, Object value) Add a query name/value pair to the requestvoid
addRawString
(String mediaType, String rawString) Add a string to the request, such as POST of raw dataEncode the value in a map of name/value pairsgetUrl()
protected String
Form a URL with request params.send
(HttpRequestConnector.HttpMethod method) Perform an HTTP call based on the class properties (url, queryParams, headerParams, bodyParams) for the provided HTTP Method.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.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.Perform an HTTP DELETEsendGet()
Perform an HTTP GET with default response processing (as a string)sendGet
(HttpRequestConnector.ResponseOption responseOption) Perform an HTTP GET while specifying the response processing optionPerform an HTTP GET and writing the response to the specified file.sendPost()
Perform an HTTP POSTsendPut()
Perform an HTTP PUTstatic void
setAllowAllCertificates
(boolean allowAllCerts) Turn on setting to allow all SSL Certificates.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
-
Field Details
-
HTTP_HEADER_CONTENT_TYPE
- See Also:
-
HTTP_HEADER_ACCEPT
- See Also:
-
HTTP_HEADER_CONTENT_MD5
- See Also:
-
HTTP_HEADER_RANGE
- See Also:
-
HTTP_HEADER_CONTENT_LENGTH
- See Also:
-
HTTP_CONTENT_TYPE_CSV
- See Also:
-
HTTP_CONTENT_TYPE_JSON
- See Also:
-
HTTP_CONTENT_TYPE_SCIM_JSON
- See Also:
-
HTTP_CONTENT_TYPE_OCTET
- See Also:
-
HTTP_CONTENT_TYPE_PLAINTEXT
- See Also:
-
HTTP_CONTENT_TYPE_XFORM
- See Also:
-
HTTP_CONTENT_TYPE_MULTIPART_FORM
- See Also:
-
HTTP_CONTENT_TYPE_MULTIPART_FORM_BOUNDARY
- See Also:
-
-
Constructor Details
-
HttpRequestConnector
Constructor for an HTTP request to a given URL- Parameters:
url
- Endpoint for the HTTP call
-
-
Method Details
-
send
Perform an HTTP call based on the class properties (url, queryParams, headerParams, bodyParams) for the provided HTTP Method. Responses are returned as a string.- Parameters:
method
- The HttpMethod for the request (GET, POST, PUT, DELETE)- Returns:
- The HTTP response from the request, returned as a string
-
send
public 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. Responses are returned based on the provided response option input.- Parameters:
method
- The HttpMethod for the request (GET, POST, PUT, DELETE)responseOption
- The format to return the HTTP response- Returns:
- The HTTP response from the request, returned in format as specified by responseOption
-
send
public 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. Responses are returned based on the provided response option input. An output file is optionally written for streamed data.- Parameters:
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 ignore- Returns:
- The HTTP response from the request, returned in format as specific by responseOption
-
sendGet
Perform an HTTP GET with default response processing (as a string)- Returns:
- The HTTP response from the request, returned as a string
-
sendGet
Perform an HTTP GET while specifying the response processing option- Parameters:
responseOption
- Option for processing the response as string, inputstream, byte array, etc.- Returns:
- The HTTP response from the request, returned in format as specified by responseOption
-
sendGet
Perform an HTTP GET and writing the response to the specified file.- Parameters:
outputFilePath
- The output file path to write to- Returns:
- The HTTP response from the request
-
sendPost
Perform an HTTP POST- Returns:
- The HTTP response from the request
-
sendPut
Perform an HTTP PUT- Returns:
- The HTTP response from the request
-
sendDelete
Perform an HTTP DELETE- Returns:
- The HTTP response from the request
-
getUrl
Form a URL with request params. The request param values are encoding for sending.- Parameters:
url
- Endpoint for the HTTP callqueryParams
- (Optional) Request parameters to add to the URL string. Pass null if none.- Returns:
- Formed URL with request params
-
encodeMap
Encode the value in a map of name/value pairs- Parameters:
map
- Name/Value pairs to encode- Returns:
- Encoded map
-
getUrl
-
getQueryParams
-
getHeaderParams
-
getBodyParams
-
setUrl
-
setQueryParams
-
setHeaderParams
-
setBodyParams
-
addQueryParam
Add a query name/value pair to the request- Parameters:
name
- The parameter namevalue
- The parameter value
-
addHeaderParam
Add a header name/value pair to the request- Parameters:
name
- The parameter namevalue
- The parameter value
-
addBodyParam
Add a body name/value pair to the request- Parameters:
name
- The body parameter namevalue
- The body parameter value
-
addBodyParamMultiPart
Add a body name/value pair to the request- Parameters:
name
- The body parameter namevalue
- The body parameter value
-
addFile
Add a file to the request, such as "--data-binary" POST request, in which the file is the only entity in the post request.- Parameters:
mediaType
- The media type of the filefilePath
- Absolute file path of file to stream in the request
-
addRawString
Add a string to the request, such as POST of raw data- Parameters:
mediaType
- The media type of the raw stringrawString
- The data as a string
-
addBinary
Add a file in multipart/form-data request.- Parameters:
mediaType
- The media type of the raw stringbinaryContent
- Absolute file path of file to upload
-
addFileMultiPart
Add a file in multipart/form-data request.- Parameters:
name
- The name of the body param in the multipart/form-data requestfilePath
- Absolute file path of file to upload
-
addFileBinary
Add a binary content of a file in multipart/form-data request.- Parameters:
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 create
-
addInputStream
Add an inputStream to the request.- Parameters:
mediaType
- The media typeinputStream
- The inputStream
-
setGlobalTimeout
public static void setGlobalTimeout(int minutes) Set the global timeout for the HTTP Client. Default = 60 minutes.- Parameters:
minutes
- Number of minutes before http timeout occurs
-
setAllowAllCertificates
public static void setAllowAllCertificates(boolean allowAllCerts) Turn on setting to allow all SSL Certificates. Default = false.- Parameters:
allowAllCerts
- True to allow all SSL Certificates
-