java.lang.Object
com.aquima.interactions.foundation.connectivity.impl.HttpConnection
All Implemented Interfaces:
IConnection, IHttpConnection

public class HttpConnection extends Object implements 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 Details

    • HttpConnection

      public HttpConnection(String name, String url)
      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

      public HttpConnection(String name, String url, String username, String password)
      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

      public IHttpConnectionFiller fill()
      Description copied from interface: IHttpConnection
      Returns an object which can fill in the missing configurations of this connection.
      Specified by:
      fill in interface IHttpConnection
      Returns:
      a filler for this connection's settings.
    • createConnection

      protected HttpURLConnection createConnection(IHttpRequest request) throws IOException
      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

      protected void setAuthentication(HttpURLConnection httpConn)
      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

      protected HttpResponse createHttpResponse(HttpURLConnection httpConn) throws IOException
      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

      public void invoke(IHttpRequest request, IHttpResponseHandler responseHandler) throws IOException
      Description copied from interface: IHttpConnection
      This method should be called to transfer data over http and handle its response.
      Specified by:
      invoke in interface IHttpConnection
      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

      public String 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 interface IConnection
      Returns:
      the name of the connection object.
    • getType

      public ConnectionType getType()
      Description copied from interface: IConnection
      This method returns the type of the connection object.
      Specified by:
      getType in interface IConnection
      Returns:
      the type of the connection object.
    • getUrl

      public String getUrl()
      Description copied from interface: IHttpConnection
      This method returns the url used for connecting to the endpoint.
      Specified by:
      getUrl in interface IHttpConnection
      Returns:
      The url (never null).
    • getUsername

      protected String getUsername()
    • getPassword

      protected String getPassword()
    • toString

      public String toString()
      Overrides:
      toString in class Object