io.keen.client.java.http
Class UrlConnectionHttpHandler

java.lang.Object
  extended by io.keen.client.java.http.UrlConnectionHttpHandler
All Implemented Interfaces:
HttpHandler

public class UrlConnectionHttpHandler
extends java.lang.Object
implements HttpHandler

This class provides a default implementation of HttpHandler using HttpURLConnection. To use a different HttpURLConnection implementation simply override the execute(Request)} method.

Since:
2.0.0

Constructor Summary
UrlConnectionHttpHandler()
           
 
Method Summary
 Response execute(Request request)
          Sends an HTTP request.
protected  java.net.HttpURLConnection openConnection(Request request)
          Opens a connection based on the URL in the given request.
protected  Response readResponse(java.net.HttpURLConnection connection)
          Reads a Response from an existing connection.
protected  void sendRequest(java.net.HttpURLConnection connection, Request request)
          Sends a request over a given connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlConnectionHttpHandler

public UrlConnectionHttpHandler()
Method Detail

execute

public Response execute(Request request)
                 throws java.io.IOException
Sends an HTTP request.

Specified by:
execute in interface HttpHandler
Parameters:
request - The Request to send.
Returns:
A Response object describing the response from the server.
Throws:
java.io.IOException - If there was an error during the connection.

openConnection

protected java.net.HttpURLConnection openConnection(Request request)
                                             throws java.io.IOException
Opens a connection based on the URL in the given request. Subclasses can override this method to use a different implementation of HttpURLConnection.

Parameters:
request - The Request.
Returns:
A new HttpURLConnection.
Throws:
java.io.IOException - If there is an error opening the connection.

sendRequest

protected void sendRequest(java.net.HttpURLConnection connection,
                           Request request)
                    throws java.io.IOException
Sends a request over a given connection.

Parameters:
connection - The connection over which to send the request.
request - The request to send.
Throws:
java.io.IOException - If there is an error sending the request.

readResponse

protected Response readResponse(java.net.HttpURLConnection connection)
                         throws java.io.IOException
Reads a Response from an existing connection. This method should only be called on a connection for which the entire request has been sent.

Throws:
java.io.IOException - If there is an error reading the response from the connection.