public class Communicator extends Object implements Closeable, LoggingCapable, ObfuscationCapable
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 and Description |
---|
Communicator(URI apiEndpoint,
Connection connection,
Authenticator authenticator,
MetadataProvider metadataProvider,
Marshaller marshaller) |
Modifier and Type | Method and Description |
---|---|
protected void |
addGenericHeaders(String httpMethod,
URI uri,
List<RequestHeader> requestHeaders,
CallContext context)
Adds the necessary headers to the given list of headers.
|
void |
close()
Releases any system resources associated with this object.
|
void |
closeExpiredConnections()
Utility method that delegates the call to this communicator's connection if that's an instance of
PooledConnection . |
void |
closeIdleConnections(long idleTime,
TimeUnit timeUnit)
Utility method that delegates the call to this communicator's connection if that's an instance of
PooledConnection . |
void |
delete(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
BodyHandler bodyHandler,
CallContext context)
Corresponds to the HTTP DELETE method.
|
<O> O |
delete(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP DELETE method.
|
void |
disableLogging()
Turns off logging.
|
void |
enableLogging(CommunicatorLogger communicatorLogger)
Turns on logging using the given communicator logger.
|
void |
get(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
BodyHandler bodyHandler,
CallContext context)
Corresponds to the HTTP GET method.
|
<O> O |
get(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP GET method.
|
protected static String |
getHeaderDateString()
Returns the date in the preferred format for the HTTP date header (RFC1123).
|
Marshaller |
getMarshaller() |
void |
post(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
BodyHandler bodyHandler,
CallContext context)
Corresponds to the HTTP POST method.
|
<O> O |
post(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP POST method.
|
protected void |
processResponse(int statusCode,
InputStream bodyStream,
List<ResponseHeader> headers,
BodyHandler bodyHandler,
String requestPath,
CallContext context) |
protected <O> O |
processResponse(int statusCode,
InputStream bodyStream,
List<ResponseHeader> headers,
Class<O> responseType,
String requestPath,
CallContext context) |
void |
put(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
BodyHandler bodyHandler,
CallContext context)
Corresponds to the HTTP PUT method.
|
<O> O |
put(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP PUT method.
|
void |
setBodyObfuscator(BodyObfuscator bodyObfuscator)
Sets the current non-
null body obfuscator to use. |
void |
setHeaderObfuscator(HeaderObfuscator headerObfuscator)
Sets the current non-
null header obfuscator to use. |
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.
|
protected URI |
toAbsoluteURI(String relativePath,
List<RequestParam> requestParameters) |
protected static void |
updateContext(List<ResponseHeader> headers,
CallContext context)
Updates the given call context based on the contents of the given response.
|
public Communicator(URI apiEndpoint, Connection connection, Authenticator authenticator, MetadataProvider metadataProvider, Marshaller marshaller)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public <O> O get(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic void get(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic <O> O delete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic void delete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, BodyHandler bodyHandler, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic <O> O post(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic void post(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic <O> O put(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic void put(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, BodyHandler bodyHandler, CallContext context)
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.CommunicationException
- when an exception occurred communicating with the Worldline Global Collect platformResponseException
- when an error response was received from the Worldline Global Collect platformpublic Marshaller getMarshaller()
Marshaller
object associated with this communicator. Never null
.protected URI toAbsoluteURI(String relativePath, List<RequestParam> requestParameters)
protected void addGenericHeaders(String httpMethod, URI uri, List<RequestHeader> requestHeaders, CallContext context)
super.addGenericHeaders
at the end of your overridden method.protected static String getHeaderDateString()
protected <O> O processResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, Class<O> responseType, String requestPath, CallContext context)
protected void processResponse(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, BodyHandler bodyHandler, String requestPath, CallContext context)
protected static void updateContext(List<ResponseHeader> headers, CallContext context)
protected static void throwExceptionIfNecessary(int statusCode, InputStream bodyStream, List<ResponseHeader> headers, String requestPath)
public void closeIdleConnections(long idleTime, TimeUnit timeUnit)
PooledConnection
. If not this method does nothing.public void closeExpiredConnections()
PooledConnection
. If not this method does nothing.public void setBodyObfuscator(BodyObfuscator bodyObfuscator)
ObfuscationCapable
null
body obfuscator to use.setBodyObfuscator
in interface ObfuscationCapable
public void setHeaderObfuscator(HeaderObfuscator headerObfuscator)
ObfuscationCapable
null
header obfuscator to use.setHeaderObfuscator
in interface ObfuscationCapable
public void enableLogging(CommunicatorLogger communicatorLogger)
LoggingCapable
enableLogging
in interface LoggingCapable
public void disableLogging()
LoggingCapable
disableLogging
in interface LoggingCapable
Copyright © 2024 Worldline Global Collect. All rights reserved.