public class DefaultCommunicator extends Object implements Communicator
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 |
|---|
DefaultCommunicator(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 session'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 session's connection if that's an instance of
PooledConnection. |
<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.
|
<O> O |
get(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP GET method.
|
URI |
getApiEndpoint() |
Authenticator |
getAuthenticator() |
Connection |
getConnection() |
protected String |
getHeaderDateString()
Returns the date in the preferred format for the HTTP date header (RFC1123).
|
Marshaller |
getMarshaller() |
MetaDataProvider |
getMetaDataProvider() |
<O> O |
post(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP POST method.
|
protected <O> O |
processResponse(int statusCode,
InputStream bodyStream,
List<ResponseHeader> headers,
Class<O> responseType,
String requestPath,
CallContext context) |
<O> O |
put(String relativePath,
List<RequestHeader> requestHeaders,
ParamRequest requestParameters,
Object requestBody,
Class<O> responseType,
CallContext context)
Corresponds to the HTTP PUT method.
|
protected 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 void |
updateContext(List<ResponseHeader> headers,
CallContext context)
Updates the given call context based on the contents of the given response.
|
public DefaultCommunicator(URI apiEndpoint, Connection connection, Authenticator authenticator, MetaDataProvider metaDataProvider, Marshaller marshaller)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic <O> O get(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
get in interface CommunicatorrelativePath - 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.public <O> O delete(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Class<O> responseType, CallContext context)
delete in interface CommunicatorrelativePath - 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.public <O> O post(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
post in interface CommunicatorrelativePath - 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.public <O> O put(String relativePath, List<RequestHeader> requestHeaders, ParamRequest requestParameters, Object requestBody, Class<O> responseType, CallContext context)
put in interface CommunicatorrelativePath - 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.public URI getApiEndpoint()
public Connection getConnection()
getConnection in interface Communicatorpublic Authenticator getAuthenticator()
getAuthenticator in interface Communicatorpublic MetaDataProvider getMetaDataProvider()
getMetaDataProvider in interface Communicatorpublic Marshaller getMarshaller()
getMarshaller in interface Communicatorprotected 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 String getHeaderDateString()
protected <O> O processResponse(int statusCode,
InputStream bodyStream,
List<ResponseHeader> headers,
Class<O> responseType,
String requestPath,
CallContext context)
protected void updateContext(List<ResponseHeader> headers, CallContext context)
protected 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.closeIdleConnections in interface CommunicatorPooledConnection.closeIdleConnections(long, TimeUnit)public void closeExpiredConnections()
PooledConnection. If not this method does nothing.closeExpiredConnections in interface CommunicatorPooledConnection.closeExpiredConnections()public void enableLogging(CommunicatorLogger communicatorLogger)
LoggingCapableenableLogging in interface LoggingCapablepublic void disableLogging()
LoggingCapabledisableLogging in interface LoggingCapableCopyright © 2024 Worldline Online Payments Direct. All rights reserved.