Class HttpConnection
java.lang.Object
com.aquima.interactions.foundation.connectivity.impl.HttpConnection
- All Implemented Interfaces:
IConnection
,IHttpConnection
Class providing a simple implementation to interact over http connections. (basic http authentication is supported)
- Since:
- 9.0
- Author:
- Jon van Leuven, Martijn van Tilburg
-
Constructor Summary
ConstructorsConstructorDescriptionHttpConnection
(String name, String url) Create a simple http connection for a specific Url.HttpConnection
(String name, String url, String username, String password) Create a simple http connection for a specific Url with basic http authorization. -
Method Summary
Modifier and TypeMethodDescriptionprotected HttpURLConnection
createConnection
(IHttpRequest request) Create the HTTP connection that will be used for the request.protected HttpResponse
createHttpResponse
(HttpURLConnection httpConn) Create the HTTP response for the HTTP request.fill()
Returns an object which can fill in the missing configurations of this connection.getName()
This method returns the name of the connection object.protected String
getType()
This method returns the type of the connection object.getUrl()
This method returns the url used for connecting to the endpoint.protected String
void
invoke
(IHttpRequest request, IHttpResponseHandler responseHandler) This method should be called to transfer data over http and handle its response.protected void
setAuthentication
(HttpURLConnection httpConn) Set authentication for the HTTP request.void
setTimeout
(int timeout) Sets the read timeout to a specified timeout, in milliseconds.toString()
-
Constructor Details
-
HttpConnection
Create a simple http connection for a specific Url.- Parameters:
name
- The name of this connection (required).url
- The url of the http endpoint (required).
-
HttpConnection
Create a simple http connection for a specific Url with basic http authorization. With http authorization the username and password will be send in the http request header using base64 encoding.- Parameters:
name
- The name of this connection (required).url
- The url of the http endpoint.username
- The username used for authorization when connecting to the url.password
- The password used for authorization when connecting to the url.
-
-
Method Details
-
setTimeout
public void setTimeout(int timeout) Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout. Some non-standard implementation of this method ignores the specified timeout.- Parameters:
timeout
- An int that specifies the timeout value to be used in milliseconds
-
fill
Description copied from interface:IHttpConnection
Returns an object which can fill in the missing configurations of this connection.- Specified by:
fill
in interfaceIHttpConnection
- Returns:
- a filler for this connection's settings.
-
createConnection
Create the HTTP connection that will be used for the request. The default implementation concatenates 'this.url' and 'request.getQueryString()' to construct an URL. A connection to this URL is opened and returned as the result of this method- Parameters:
request
- The object that is responsible for the HTTP request data- Returns:
- the HTTP connection for the request
- Throws:
IOException
- if an I/O exception occurs while opening the connection
-
setAuthentication
Set authentication for the HTTP request. The default implementation uses 'username' and 'password' for BASIC authentication- Parameters:
httpConn
- The HTTP connection instance used for this request
-
createHttpResponse
Create the HTTP response for the HTTP request. The default implementation uses the response code and all response headers from the HTTP connection- Parameters:
httpConn
- The HTTP connection instance used for this request- Returns:
- the HTTP response
- Throws:
IOException
- if an error occurred connecting to the server
-
invoke
Description copied from interface:IHttpConnection
This method should be called to transfer data over http and handle its response.- Specified by:
invoke
in interfaceIHttpConnection
- Parameters:
request
- The object that is responsible for the http request data.responseHandler
- The object that is used to handle the http response.- Throws:
IOException
- Is thrown when IO error occurs.
-
getName
Description copied from interface:IConnection
This method returns the name of the connection object. The name is used to uniquely identify the connection object.- Specified by:
getName
in interfaceIConnection
- Returns:
- the name of the connection object.
-
getType
Description copied from interface:IConnection
This method returns the type of the connection object.- Specified by:
getType
in interfaceIConnection
- Returns:
- the type of the connection object.
-
getUrl
Description copied from interface:IHttpConnection
This method returns the url used for connecting to the endpoint.- Specified by:
getUrl
in interfaceIHttpConnection
- Returns:
- The url (never null).
-
getUsername
-
getPassword
-
toString
-