Package com.onlinepayments.communication
Class DefaultConnection
java.lang.Object
com.onlinepayments.communication.DefaultConnection
- All Implemented Interfaces:
Connection,PooledConnection,LoggingCapable,ObfuscationCapable,Closeable,AutoCloseable
Connection implementation based on HttpClient.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.http.impl.client.CloseableHttpClientprotected final org.apache.http.client.config.RequestConfig -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefaultConnection(int connectTimeout, int socketTimeout) Creates a new connection with the given timeouts, the default number of maximum connections, no proxy and the default HTTPS protocols.protected -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddHeaders(org.apache.http.client.methods.HttpRequestBase httpRequestBase, List<RequestHeader> requestHeaders) voidclose()Releases any system resources associated with this object.voidCloses all expired HTTP connections.voidcloseIdleConnections(long idleTime, TimeUnit timeUnit) Closes all HTTP connections that have been idle for the specified time.<R> Rdelete(URI uri, List<RequestHeader> requestHeaders, ResponseHandler<R> responseHandler) Send a DELETE request to the Online Payments platform.voidTurns off logging.voidenableLogging(CommunicatorLogger communicatorLogger) Turns on logging using the given communicator logger.protected <R> RexecuteRequest(org.apache.http.client.methods.HttpUriRequest request, ResponseHandler<R> responseHandler) <R> Rget(URI uri, List<RequestHeader> requestHeaders, ResponseHandler<R> responseHandler) Send a GET request to the Online Payments platform.protected List<ResponseHeader> getHeaders(org.apache.http.HttpResponse httpResponse) <R> Rpost(URI uri, List<RequestHeader> requestHeaders, MultipartFormDataObject multipart, ResponseHandler<R> responseHandler) Send a multipart/form-data POST request to the Online Payments platform.<R> Rpost(URI uri, List<RequestHeader> requestHeaders, String body, ResponseHandler<R> responseHandler) Send a POST request to the Online Payments platform.<R> Rput(URI uri, List<RequestHeader> requestHeaders, MultipartFormDataObject multipart, ResponseHandler<R> responseHandler) Send a multipart/form-data PUT request to the Online Payments platform.<R> Rput(URI uri, List<RequestHeader> requestHeaders, String body, ResponseHandler<R> responseHandler) Send a PUT request to the Online Payments platform.voidsetBodyObfuscator(BodyObfuscator bodyObfuscator) Sets the current non-nullbody obfuscator to use.voidsetHeaderObfuscator(HeaderObfuscator headerObfuscator) Sets the current non-nullheader obfuscator to use.
-
Field Details
-
httpClient
protected final org.apache.http.impl.client.CloseableHttpClient httpClient -
requestConfig
protected final org.apache.http.client.config.RequestConfig requestConfig
-
-
Constructor Details
-
DefaultConnection
public DefaultConnection(int connectTimeout, int socketTimeout) Creates a new connection with the given timeouts, the default number of maximum connections, no proxy and the default HTTPS protocols.- See Also:
-
DefaultConnection
-
-
Method Details
-
close
Description copied from interface:ConnectionReleases any system resources associated with this object. Should be called when this object is about to go out of scope.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection- Throws:
IOException
-
get
Description copied from interface:ConnectionSend a GET request to the Online Payments platform.- Specified by:
getin interfaceConnection- 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:ConnectionSend a DELETE request to the Online Payments platform.- Specified by:
deletein interfaceConnection- 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:ConnectionSend a POST request to the Online Payments platform.- Specified by:
postin interfaceConnection- 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:ConnectionSend 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:
postin interfaceConnection- 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:ConnectionSend a PUT request to the Online Payments platform.- Specified by:
putin interfaceConnection- 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:ConnectionSend 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:
putin interfaceConnection- 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
-
closeIdleConnections
Description copied from interface:PooledConnectionCloses all HTTP connections that have been idle for the specified time. This should also include all expired HTTP connections.- Specified by:
closeIdleConnectionsin interfacePooledConnection- See Also:
-
closeExpiredConnections
public void closeExpiredConnections()Description copied from interface:PooledConnectionCloses all expired HTTP connections.- Specified by:
closeExpiredConnectionsin interfacePooledConnection
-
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
-