Package com.worldline.acquiring.sdk.java
Class Communicator
java.lang.Object
com.worldline.acquiring.sdk.java.Communicator
- All Implemented Interfaces:
LoggingCapable,ObfuscationCapable,Closeable,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionCommunicator(URI apiEndpoint, Connection connection, Authenticator authenticator, MetadataProvider metadataProvider, Marshaller marshaller) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddGenericHeaders(String httpMethod, URI uri, List<RequestHeader> requestHeaders, CallContext context) Adds the necessary headers to the given list of headers.voidclose()Releases any system resources associated with this object.voidUtility method that delegates the call to this communicator's connection if that's an instance ofPooledConnection.voidcloseIdleConnections(long idleTime, TimeUnit timeUnit) Utility method that delegates the call to this communicator's connection if that's an instance ofPooledConnection.voiddelete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context) Corresponds to the HTTP DELETE method.<O> Odelete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context) Corresponds to the HTTP DELETE method.voidTurns off logging.voidenableLogging(CommunicatorLogger communicatorLogger) Turns on logging using the given communicator logger.voidget(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context) Corresponds to the HTTP GET method.<O> Oget(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context) Corresponds to the HTTP GET method.protected static StringReturns the date in the preferred format for the HTTP date header (RFC1123).voidpost(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context) Corresponds to the HTTP POST method.<O> Opost(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context) Corresponds to the HTTP POST method.protected voidprocessResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, BodyHandler bodyHandler, String requestPath, CallContext context) protected <O> OprocessResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, Class<O> responseType, String requestPath, CallContext context) voidput(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context) Corresponds to the HTTP PUT method.<O> Oput(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context) Corresponds to the HTTP PUT method.voidsetBodyObfuscator(BodyObfuscator bodyObfuscator) Sets the current non-nullbody obfuscator to use.voidsetHeaderObfuscator(HeaderObfuscator headerObfuscator) Sets the current non-nullheader obfuscator to use.protected static voidthrowExceptionIfNecessary(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, String requestPath) Checks the status code and headers for errors and throws an exception if necessary.protected URItoAbsoluteURI(String relativePath, List<RequestParam> requestParameters) protected static voidupdateContext(List<ResponseHeader> headers, CallContext context) Updates the given call context based on the contents of the given response.
-
Constructor Details
-
Communicator
public Communicator(URI apiEndpoint, Connection connection, Authenticator authenticator, MetadataProvider metadataProvider, Marshaller marshaller)
-
-
Method Details
-
close
Releases any system resources associated with this object.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- 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 platformResponseException- when an error response was received from the Worldline Acquiring platform
-
getMarshaller
- Returns:
- The
Marshallerobject associated with this communicator. Nevernull.
-
toAbsoluteURI
-
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 callsuper.addGenericHeadersat the end of your overridden method. -
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
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
Utility method that delegates the call to this communicator's connection if that's an instance ofPooledConnection. If not this method does nothing. -
closeExpiredConnections
public void closeExpiredConnections()Utility method that delegates the call to this communicator's connection if that's an instance ofPooledConnection. If not this method does nothing. -
setBodyObfuscator
Description copied from interface:ObfuscationCapableSets the current non-nullbody obfuscator to use.- Specified by:
setBodyObfuscatorin interfaceObfuscationCapable
-
setHeaderObfuscator
Description copied from interface:ObfuscationCapableSets the current non-nullheader obfuscator to use.- Specified by:
setHeaderObfuscatorin interfaceObfuscationCapable
-
enableLogging
Description copied from interface:LoggingCapableTurns on logging using the given communicator logger.- Specified by:
enableLoggingin interfaceLoggingCapable
-
disableLogging
public void disableLogging()Description copied from interface:LoggingCapableTurns off logging.- Specified by:
disableLoggingin interfaceLoggingCapable
-