Interface IHttpClient


public interface IHttpClient
  • Method Details

    • getJaxb

      HttpClientResponse<Object> getJaxb(String url, Class<?>... responseTypes) throws HttpClientException
      Issue an HTTP GET to the provided URL, receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes
      Parameters:
      url -
      responseTypes -
      Returns:
      - HttpClientResponse with a JAXB content type
      Throws:
      HttpClientException
    • putJaxb

      HttpClientResponse<Object> putJaxb(String url, Object jaxbObject, Class<?>... responseTypes) throws HttpClientException
      Issue an HTTP PUT to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes
      Parameters:
      url -
      jaxbObject -
      responseTypes -
      Returns:
      - HttpClientResponse with a JAXB content type
      Throws:
      HttpClientException
    • postJaxb

      HttpClientResponse<Object> postJaxb(String url, Object jaxbObject, Class<?>... responseTypes) throws HttpClientException
      Issue an HTTP POST to the provided URL, sending the provided jaxbObject and receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes
      Parameters:
      url -
      jaxbObject -
      responseTypes -
      Returns:
      - HttpClientResponse with a JAXB content type
      Throws:
      HttpClientException
    • deleteJaxb

      HttpClientResponse<Object> deleteJaxb(String url, Class<?>... responseTypes) throws HttpClientException
      Issue an HTTP DELETE to the provided URL, receiving a JAXB Object in the response. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes
      Parameters:
      url -
      responseTypes -
      Returns:
      - HttpClientResponse with a JAXB content type
      Throws:
      HttpClientException
    • putXML

      Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response.
      Parameters:
      url -
      xml -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • postSOAP

      Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response. Uses a content type of application/soap+xml
      Parameters:
      url -
      xml -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • putSOAP

      Issue an HTTP PUT to the provided URL, sending the provided XML as a String and receiving a String in the response. Uses a content type of application/soap+xml
      Parameters:
      url -
      xml -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • postXML

      Issue an HTTP POST to the provided URL, sending the provided XML as a String and receiving a String in the response.
      Parameters:
      url -
      xml -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • getJson

      HttpClientResponse<com.google.gson.JsonObject> getJson(String url) throws HttpClientException
      Issue an HTTP GET to the provided URL, receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • postJson

      HttpClientResponse<com.google.gson.JsonObject> postJson(String url, com.google.gson.JsonObject json) throws HttpClientException
      Issue an HTTP POST to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      json -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • patchJson

      HttpClientResponse<com.google.gson.JsonObject> patchJson(String url, com.google.gson.JsonObject json) throws HttpClientException
      Issue an HTTP PATCH to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      json -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • putJson

      HttpClientResponse<com.google.gson.JsonObject> putJson(String url, com.google.gson.JsonObject json) throws HttpClientException
      Issue an HTTP PUT to the provided URL, sending the provided com.google.gson.JsonObject and receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      json -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • deleteJson

      HttpClientResponse<com.google.gson.JsonObject> deleteJson(String url) throws HttpClientException
      Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • deleteJson

      HttpClientResponse<com.google.gson.JsonObject> deleteJson(String url, com.google.gson.JsonObject json) throws HttpClientException
      Issue an HTTP DELETE to the provided URL, receiving a com.google.gson.JsonObject in the response.
      Parameters:
      url -
      json -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • getText

      Issue an HTTP GET to the provided URL, receiving a String in the response.
      Parameters:
      url -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • postText

      Issue an HTTP POST to the provided URL, sending the provided String and receiving a String in the response.
      Parameters:
      url -
      text -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • postForm

      Issue an HTTP POST to the provided URL, sending form-encoded data and receiving a String in the response.

      This is a convenience method for posting form data (e.g., login credentials). The data is encoded as application/x-www-form-urlencoded, which is the standard format for HTML form submissions.

      This method is commonly used for form-based authentication where credentials are posted as form fields (e.g., j_username, j_password for Java EE security).

      Parameters:
      url - - URL path
      fields - - Form fields as key-value pairs
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException - if the request fails
    • putText

      Issue an HTTP PUT to the provided URL, sending the provided String and receiving a String in the response.
      Parameters:
      url -
      text -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • deleteText

      Issue an HTTP DELETE to the provided URL, receiving a String in the response.
      Parameters:
      url -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • putBinary

      HttpClientResponse<byte[]> putBinary(String url, byte[] binary) throws HttpClientException
      Issue an HTTP PUT to the provided URL, sending the provided byte and receiving a byte in the response.
      Parameters:
      url -
      binary -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • getBinary

      HttpClientResponse<byte[]> getBinary(String url, byte[] binary) throws HttpClientException
      Issue an HTTP GET to the provided URL, sending the provided byte and receiving a byte in the response.
      Parameters:
      url -
      binary -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • postBinary

      HttpClientResponse<byte[]> postBinary(String url, byte[] binary) throws HttpClientException
      Issue an HTTP POST to the provided URL, sending the provided byte and receiving a byte in the response.
      Parameters:
      url -
      binary -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • deleteBinary

      HttpClientResponse<byte[]> deleteBinary(String url, byte[] binary) throws HttpClientException
      Issue an HTTP DELETE to the provided URL, sending the provided byte and receiving a byte in the response.
      Parameters:
      url -
      binary -
      Returns:
      - HttpClientResponse with a com.google.gson.JsonObject content type
      Throws:
      HttpClientException
    • getFileStream

      HttpFileResponse getFileStream(String path) throws HttpClientException
      Download a file from a specified location, returning a wrapped response that provides access to the file stream and metadata.

      Example usage:

       try (HttpFileResponse response = client.getFileStream("/path/to/file")) {
           if (response.isSuccessful()) {
               InputStream stream = response.getContent();
               // Process the stream
           }
       }
       
      Parameters:
      path - - URL path
      Returns:
      HttpFileResponse containing the file stream and metadata
      Throws:
      HttpClientException - if the request fails
      Since:
      0.47.0
    • getFileStream

      HttpFileResponse getFileStream(String path, ContentType... acceptTypes) throws HttpClientException
      Download a file from a specified location with specific accept types, returning a wrapped response that provides access to the file stream and metadata.

      Example usage:

       try (HttpFileResponse response = client.getFileStream("/path/to/file",
               ContentType.APPLICATION_OCTET_STREAM)) {
           if (response.isSuccessful()) {
               InputStream stream = response.getContent();
               // Process the stream
           }
       }
       
      Parameters:
      path - - URL path
      acceptTypes - - Content types to accept in the response
      Returns:
      HttpFileResponse containing the file stream and metadata
      Throws:
      HttpClientException - if the request fails
      Since:
      0.47.0
    • getFile

      @Deprecated org.apache.http.client.methods.CloseableHttpResponse getFile(String path) throws HttpClientException
      Deprecated.
      Use getFileStream(String) instead. This method exposes internal implementation details (CloseableHttpResponse) and will be removed in a future release.
      Download a file from a specified location to a specified destination on local host.
      Parameters:
      path - = URL path
      Returns:
      the HTTP response
      Throws:
      HttpClientException - if the request fails
    • getFile

      @Deprecated org.apache.http.client.methods.CloseableHttpResponse getFile(String path, ContentType... acceptTypes) throws HttpClientException
      Deprecated.
      Use getFileStream(String, ContentType...) instead. This method exposes internal implementation details (CloseableHttpResponse) and will be removed in a future release.
      Download a file from a specified location to a specified destination on local host.
      Parameters:
      path - - URL path
      acceptTypes - - Content types to accept
      Returns:
      the HTTP response
      Throws:
      HttpClientException - if the request fails
    • putFile

      void putFile(String path, InputStream file)
      Send a compressed (tar) file from a local location to a specified destination on a host.
      Parameters:
      path - - URL path
      file - - tar archive file
    • head

      Execute an HttpClientRequest returning a JAXB object available through the returned HttpClientResponse. In order to unmarshal the response, an array of possible response classes must be provided in responseTypes *
      Parameters:
      url -
      Returns:
      - HttpClientResponse
      Throws:
      HttpClientException
    • post

      Object post(String path, Map<String,String> queryParams, ContentType contentType, Object data, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) throws HttpClientException
      Throws:
      HttpClientException
    • postForm

      Object postForm(String path, Map<String,String> queryParams, HashMap<String,String> fields, ContentType[] acceptTypes, Class<?>[] jaxbClasses, boolean retry) throws HttpClientException
      Throws:
      HttpClientException
    • getSSLContext

      SSLContext getSSLContext()
      Get the SSL context used by this client
      Returns:
      the SSLContext or null if there is none
    • getUsername

      String getUsername()
      Get the username set for this client
      Returns:
      the username
    • getUsername

      String getUsername(URI scope)
      Get the username set for this client for a specific scope
      Parameters:
      scope -
      Returns:
      the username
    • addCommonHeader

      void addCommonHeader(String name, String value)
      Add a header that will be used on all http requests
      Parameters:
      name -
      value -
    • clearCommonHeaders

      void clearCommonHeaders()
      Remove all headers for this http request
    • addOkResponseCode

      void addOkResponseCode(int responseCode)
      Add a response code for the execute to ignore and treat as OK
      Parameters:
      responseCode -
    • setSocketTimeout

      void setSocketTimeout(int seconds)
      Set the socket timeout in seconds. This is the timeout for waiting for data after connection is established. Must be called before build().
      Parameters:
      seconds - - timeout in seconds
    • setConnectTimeout

      void setConnectTimeout(int seconds)
      Set the connection timeout in seconds. This is the timeout for establishing the connection. Must be called before build().
      Parameters:
      seconds - - timeout in seconds
    • build

      IHttpClient build()
      Build the client
      Returns:
      the built client
    • close

      void close()
      close the underlying HTTPClient
    • setAuthorisation

      IHttpClient setAuthorisation(String username, String password)
      Set the username and password for all scopes
      Parameters:
      username -
      password -
      Returns:
      the updated client
    • setAuthorisation

      IHttpClient setAuthorisation(String username, String password, URI scope)
      Set the username and password for a specific scope
      Parameters:
      username -
      password -
      scope -
      Returns:
      the updated client
    • setHostnameVerifier

      IHttpClient setHostnameVerifier(HostnameVerifier hostnameVerifier)
      Set the hostname verifier
      Parameters:
      hostnameVerifier -
      Returns:
      the updated client
    • setNoopHostnameVerifier

      IHttpClient setNoopHostnameVerifier()
      Set the hostname verifier to a no-op verifier
      Returns:
      the updated client
    • setSSLContext

      IHttpClient setSSLContext(SSLContext sslContext)
      Set the SSL Context
      Parameters:
      sslContext -
      Returns:
      the updated client
    • setTrustingSSLContext

      IHttpClient setTrustingSSLContext() throws HttpClientException
      Set the SSL Context to a Trust All context
      Returns:
      the updated client
      Throws:
      HttpClientException
    • setupClientAuth

      IHttpClient setupClientAuth(KeyStore clientKeyStore, KeyStore serverKeyStore, String alias, String password) throws HttpClientException
      Set up Client Authentication SSL Context and install
      Parameters:
      clientKeyStore -
      serverKeyStore -
      alias -
      password -
      Returns:
      the updated client
      Throws:
      HttpClientException
    • setupClientAuth

      IHttpClient setupClientAuth(KeyStore keyStore, String password) throws HttpClientException
      Set up Client Authentication SSL Context using a single KeyStore for both client certificates and server trust. This is a convenience method for cases where the same KeyStore contains both the client certificate/private key and the trusted CA certificates.
      Parameters:
      keyStore - KeyStore containing both client cert and trusted CAs
      password - KeyStore password
      Returns:
      the updated client
      Throws:
      HttpClientException - if SSL setup fails
    • setURI

      void setURI(URI host)
      Set the URI endpoint for this client
      Parameters:
      host -
    • clearCookies

      void clearCookies()
      Clear the cookie store
    • setTlsVersions

      void setTlsVersions(TLS[] tlsVersions)
      Set TLS versions required.
      Parameters:
      tlsVersions - TLS versions