Class DefaultConnection

java.lang.Object
com.onlinepayments.communication.DefaultConnection
All Implemented Interfaces:
Connection, PooledConnection, LoggingCapable, ObfuscationCapable, Closeable, AutoCloseable

public class DefaultConnection extends Object implements PooledConnection
Connection implementation based on HttpClient.
  • Field Details

    • httpClient

      protected final org.apache.http.impl.client.CloseableHttpClient httpClient
    • requestConfig

      protected final org.apache.http.client.config.RequestConfig requestConfig
  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Description copied from interface: Connection
      Releases any system resources associated with this object. Should be called when this object is about to go out of scope.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Connection
      Throws:
      IOException
    • get

      public <R> R get(URI uri, List<RequestHeader> requestHeaders, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a GET request to the Online Payments platform.
      Specified by:
      get in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      responseHandler - A handler for the response.
    • delete

      public <R> R delete(URI uri, List<RequestHeader> requestHeaders, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a DELETE request to the Online Payments platform.
      Specified by:
      delete in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      responseHandler - A handler for the response.
    • post

      public <R> R post(URI uri, List<RequestHeader> requestHeaders, String body, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a POST request to the Online Payments platform.
      Specified by:
      post in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      body - The optional body to send.
      responseHandler - A handler for the response.
    • post

      public <R> R post(URI uri, List<RequestHeader> requestHeaders, MultipartFormDataObject multipart, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a multipart/form-data POST request to the Online Payments platform.

      The content type of the request will be be part of the given request header list. If the connection creates its own content type, it should be multipart.getContentType(). Otherwise, authentication failures will occur.

      Specified by:
      post in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      multipart - The multipart/form-data request to send.
      responseHandler - A handler for the response.
    • put

      public <R> R put(URI uri, List<RequestHeader> requestHeaders, String body, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a PUT request to the Online Payments platform.
      Specified by:
      put in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      body - The optional body to send.
      responseHandler - A handler for the response.
    • put

      public <R> R put(URI uri, List<RequestHeader> requestHeaders, MultipartFormDataObject multipart, ResponseHandler<R> responseHandler)
      Description copied from interface: Connection
      Send a multipart/form-data PUT request to the Online Payments platform.

      The content type of the request will be be part of the given request header list. If the connection creates its own content type, it should be multipart.getContentType(). Otherwise, authentication failures will occur.

      Specified by:
      put in interface Connection
      Parameters:
      uri - The URI to call, including any necessary query parameters.
      requestHeaders - An optional list of request headers.
      multipart - The multipart/form-data request to send.
      responseHandler - A handler for the response.
    • executeRequest

      protected <R> R executeRequest(org.apache.http.client.methods.HttpUriRequest request, ResponseHandler<R> responseHandler)
    • addHeaders

      protected void addHeaders(org.apache.http.client.methods.HttpRequestBase httpRequestBase, List<RequestHeader> requestHeaders)
    • getHeaders

      protected List<ResponseHeader> getHeaders(org.apache.http.HttpResponse httpResponse)
    • closeIdleConnections

      public void closeIdleConnections(long idleTime, TimeUnit timeUnit)
      Description copied from interface: PooledConnection
      Closes all HTTP connections that have been idle for the specified time. This should also include all expired HTTP connections.
      Specified by:
      closeIdleConnections in interface PooledConnection
      See Also:
    • closeExpiredConnections

      public void closeExpiredConnections()
      Description copied from interface: PooledConnection
      Closes all expired HTTP connections.
      Specified by:
      closeExpiredConnections in interface PooledConnection
    • setBodyObfuscator

      public void setBodyObfuscator(BodyObfuscator bodyObfuscator)
      Description copied from interface: ObfuscationCapable
      Sets the current non-null body obfuscator to use.
      Specified by:
      setBodyObfuscator in interface ObfuscationCapable
    • setHeaderObfuscator

      public void setHeaderObfuscator(HeaderObfuscator headerObfuscator)
      Description copied from interface: ObfuscationCapable
      Sets the current non-null header obfuscator to use.
      Specified by:
      setHeaderObfuscator in interface ObfuscationCapable
    • enableLogging

      public void enableLogging(CommunicatorLogger communicatorLogger)
      Description copied from interface: LoggingCapable
      Turns on logging using the given communicator logger.
      Specified by:
      enableLogging in interface LoggingCapable
    • disableLogging

      public void disableLogging()
      Description copied from interface: LoggingCapable
      Turns off logging.
      Specified by:
      disableLogging in interface LoggingCapable