Class Communicator

java.lang.Object
com.worldline.acquiring.sdk.java.Communicator
All Implemented Interfaces:
LoggingCapable, ObfuscationCapable, Closeable, AutoCloseable

public class Communicator extends Object implements Closeable, LoggingCapable, ObfuscationCapable
Used to communicate with the Worldline Acquiring platform web services.

It contains all the logic to transform a request object to a HTTP request and a HTTP response to a response object.

Thread-safe.

  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Releases any system resources associated with this object.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • get

      public <O> O get(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
      Corresponds to the HTTP GET method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      responseType - The type of response to return.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • get

      public void get(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context)
      Corresponds to the HTTP GET method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      bodyHandler - The handler for the response body.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • delete

      public <O> O delete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
      Corresponds to the HTTP DELETE method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      responseType - The type of response to return.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • delete

      public void delete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context)
      Corresponds to the HTTP DELETE method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      bodyHandler - The handler for the response body.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • post

      public <O> O post(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
      Corresponds to the HTTP POST method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      requestBody - The optional request body to send.
      responseType - The type of response to return.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • post

      public void post(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context)
      Corresponds to the HTTP POST method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      requestBody - The optional request body to send.
      bodyHandler - The handler for the response body.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • put

      public <O> O put(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
      Corresponds to the HTTP PUT method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      requestBody - The optional request body to send.
      responseType - The type of response to return.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • put

      public void put(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context)
      Corresponds to the HTTP PUT method.
      Parameters:
      relativePath - The path to call, relative to the base URI.
      requestHeaders - An optional list of request headers.
      requestParameters - An optional set of request parameters.
      requestBody - The optional request body to send.
      bodyHandler - The handler for the response body.
      context - The optional call context to use.
      Throws:
      CommunicationException - when an exception occurred communicating with the Worldline Acquiring platform
      ResponseException - when an error response was received from the Worldline Acquiring platform
    • getMarshaller

      public Marshaller getMarshaller()
      Returns:
      The Marshaller object associated with this communicator. Never null.
    • toAbsoluteURI

      protected URI toAbsoluteURI(String relativePath, List<RequestParam> requestParameters)
    • addGenericHeaders

      protected void addGenericHeaders(String httpMethod, URI uri, List<RequestHeader> requestHeaders, CallContext context)
      Adds the necessary headers to the given list of headers. This includes the authorization header, which uses other headers, so when you need to override this method, make sure to call super.addGenericHeaders at the end of your overridden method.
    • getHeaderDateString

      protected static String getHeaderDateString()
      Returns the date in the preferred format for the HTTP date header (RFC1123).
    • processResponse

      protected <O> O processResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, Class<O> responseType, String requestPath, CallContext context)
    • processResponse

      protected void processResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, BodyHandler bodyHandler, String requestPath, CallContext context)
    • updateContext

      protected static void updateContext(List<ResponseHeader> headers, CallContext context)
      Updates the given call context based on the contents of the given response.
    • throwExceptionIfNecessary

      protected static void throwExceptionIfNecessary(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, String requestPath)
      Checks the status code and headers for errors and throws an exception if necessary.
    • closeIdleConnections

      public void closeIdleConnections(long idleTime, TimeUnit timeUnit)
      Utility method that delegates the call to this communicator's connection if that's an instance of PooledConnection. If not this method does nothing.
      See Also:
    • closeExpiredConnections

      public void closeExpiredConnections()
      Utility method that delegates the call to this communicator's connection if that's an instance of PooledConnection. If not this method does nothing.
      See Also:
    • 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