Class HttpRequestConnector

java.lang.Object
com.veeva.vault.vapil.connector.HttpRequestConnector

public class HttpRequestConnector extends Object
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).
  • Field Details

  • Constructor Details

    • HttpRequestConnector

      public HttpRequestConnector(String url)
      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

      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

      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 response
      outputFilePath - Optional output file to write, pass null to ignore
      Returns:
      The HTTP response from the request, returned in format as specific by responseOption
    • sendGet

      public HttpResponseConnector 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

      public HttpResponseConnector sendGet(String outputFilePath)
      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

      public HttpResponseConnector sendPost()
      Perform an HTTP POST
      Returns:
      The HTTP response from the request
    • sendPut

      public HttpResponseConnector sendPut()
      Perform an HTTP PUT
      Returns:
      The HTTP response from the request
    • sendDelete

      public HttpResponseConnector sendDelete()
      Perform an HTTP DELETE
      Returns:
      The HTTP response from the request
    • getUrl

      protected String getUrl(String url, Map<String,Object> queryParams)
      Form a URL with request params. The request param values are encoding for sending.
      Parameters:
      url - Endpoint for the HTTP call
      queryParams - (Optional) Request parameters to add to the URL string. Pass null if none.
      Returns:
      Formed URL with request params
    • encodeMap

      protected Map<String,Object> encodeMap(Map<String,Object> map)
      Encode the value in a map of name/value pairs
      Parameters:
      map - Name/Value pairs to encode
      Returns:
      Encoded map
    • getUrl

      public String getUrl()
    • getQueryParams

      public Map<String,Object> getQueryParams()
    • getHeaderParams

      public Map<String,Object> getHeaderParams()
    • getBodyParams

      public Map<String,Object> getBodyParams()
    • setUrl

      public void setUrl(String url)
    • setQueryParams

      public void setQueryParams(Map<String,Object> queryParams)
    • setHeaderParams

      public void setHeaderParams(Map<String,Object> headerParams)
    • setBodyParams

      public void setBodyParams(Map<String,Object> bodyParams)
    • addQueryParam

      public void addQueryParam(String name, Object value)
      Add a query name/value pair to the request
      Parameters:
      name - The parameter name
      value - The parameter value
    • addHeaderParam

      public void addHeaderParam(String name, Object value)
      Add a header name/value pair to the request
      Parameters:
      name - The parameter name
      value - The parameter value
    • addBodyParam

      public void addBodyParam(String name, Object value)
      Add a body name/value pair to the request
      Parameters:
      name - The body parameter name
      value - The body parameter value
    • addBodyParamMultiPart

      public void addBodyParamMultiPart(String name, Object value)
      Add a body name/value pair to the request
      Parameters:
      name - The body parameter name
      value - The body parameter value
    • addFile

      public 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.
      Parameters:
      mediaType - The media type of the file
      filePath - Absolute file path of file to stream in the request
    • addRawString

      public void addRawString(String mediaType, String rawString)
      Add a string to the request, such as POST of raw data
      Parameters:
      mediaType - The media type of the raw string
      rawString - The data as a string
    • addBinary

      public void addBinary(String mediaType, byte[] binaryContent)
      Add a file in multipart/form-data request.
      Parameters:
      mediaType - The media type of the raw string
      binaryContent - Absolute file path of file to upload
    • addFileMultiPart

      public void addFileMultiPart(String name, String filePath)
      Add a file in multipart/form-data request.
      Parameters:
      name - The name of the body param in the multipart/form-data request
      filePath - Absolute file path of file to upload
    • addFileBinary

      public void addFileBinary(String name, byte[] binaryContent, String fileName)
      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 request
      binaryContent - Binary content of the file
      fileName - The name of the file for receiving server to create
    • addInputStream

      public void addInputStream(String mediaType, InputStream inputStream)
      Add an inputStream to the request.
      Parameters:
      mediaType - The media type
      inputStream - The inputStream
    • setGlobalTimeout

      public static void setGlobalTimeout(int minutes)
      Set the global timeout for the HTTP Client. Default = 60 minutes.

       

      Can only be set before any and all HTTP calls are first executed
      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.

       

      Can only be set before any and all HTTP calls are first executed
      Parameters:
      allowAllCerts - True to allow all SSL Certificates