base.connection
Class ConnectionKey

java.lang.Object
  extended by base.connection.ConnectionKey
All Implemented Interfaces:
IConnection
Direct Known Subclasses:
ConnectionUserAndKey, LoggingConnection

public class ConnectionKey
extends java.lang.Object
implements IConnection

Manages a connection with a secret access key.


Field Summary
protected  java.lang.String accessId
          Identifies the user's account.
protected  java.lang.String accessKey
          The account user's secret key/password.
protected  Driver driver
          References the driver that owns this connection.
protected  java.lang.String host
          The host server.
 org.apache.http.impl.client.DefaultHttpClient httpClient
          Client used to make requests to the server.
protected  java.lang.String method
          HTTP operation (i.e.
protected  java.lang.String path
          Path to the resource being accessed (e.g.
protected  int port
          The server's port.
protected  boolean secure
          Indicates if the connection is secure.
 
Constructor Summary
ConnectionKey(java.lang.String accessKey, boolean secure, java.lang.String host, Driver driver)
          Constructs this connection with the default port.
ConnectionKey(java.lang.String accessKey, boolean secure, java.lang.String host, int port, Driver driver)
          Constructs this connection.
 
Method Summary
protected  java.util.Map<java.lang.String,java.lang.String> addDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
           
protected  java.util.Map<java.lang.String,java.lang.String> addDefaultParams(java.util.Map<java.lang.String,java.lang.String> params)
           
 void connect()
          Connects to the host with the already-defined host & port.
 void connect(java.lang.String host)
          Connects to the given host with the default port.
 void connect(java.lang.String host, int port)
          Connects to the given host at the given port.
protected  java.lang.String encodeData(java.lang.String data)
           
 Response request(java.lang.String method, java.lang.String path, java.util.Map<java.lang.String,java.lang.String> headers, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object data)
          Makes a request to this connection.
static java.lang.String urlEncodeMap(java.util.Map<java.lang.String,java.lang.String> map)
          Utility that performs UTF-8 encoding of a map of Strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

protected java.lang.String host
The host server.


port

protected int port
The server's port.


accessId

protected java.lang.String accessId
Identifies the user's account.


accessKey

protected java.lang.String accessKey
The account user's secret key/password.


secure

protected boolean secure
Indicates if the connection is secure. Defaults to true.


driver

protected Driver driver
References the driver that owns this connection.


method

protected java.lang.String method
HTTP operation (i.e. GET, DELETE, PUT, POST).


path

protected java.lang.String path
Path to the resource being accessed (e.g. /john.doe/images/1)


httpClient

public org.apache.http.impl.client.DefaultHttpClient httpClient
Client used to make requests to the server.

Constructor Detail

ConnectionKey

public ConnectionKey(java.lang.String accessKey,
                     boolean secure,
                     java.lang.String host,
                     Driver driver)
Constructs this connection with the default port.

Parameters:
accessKey - is the user's secret key used for authentication
secure - indicates if this connection is secure or not
host - is the host to connect to
driver - references the driver that owns this connection

ConnectionKey

public ConnectionKey(java.lang.String accessKey,
                     boolean secure,
                     java.lang.String host,
                     int port,
                     Driver driver)
Constructs this connection.

Parameters:
accessKey - is the user's secret key used for authentication
secure - indicates if this connection is secure
host - is the host to connect to
port - is the host's port to connect to
driver - references the driver that owns this connection
Method Detail

connect

public void connect()
Description copied from interface: IConnection
Connects to the host with the already-defined host & port.

Specified by:
connect in interface IConnection

connect

public void connect(java.lang.String host)
Description copied from interface: IConnection
Connects to the given host with the default port.

Specified by:
connect in interface IConnection
Parameters:
host - is the host to connect to

connect

public void connect(java.lang.String host,
                    int port)
Description copied from interface: IConnection
Connects to the given host at the given port.

Specified by:
connect in interface IConnection
Parameters:
host - is the host to connect to
port - is the host's port to connect to

request

public Response request(java.lang.String method,
                        java.lang.String path,
                        java.util.Map<java.lang.String,java.lang.String> headers,
                        java.util.Map<java.lang.String,java.lang.String> params,
                        java.lang.Object data)
Description copied from interface: IConnection
Makes a request to this connection.

Specified by:
request in interface IConnection
Parameters:
method - defines the operation to perform (i.e. GET, DELETE, PUT, POST)
path - path is the resource path (e.g. /john.doe/images/1)
headers - are the headers to include with the request
params - are the parameters to include with the request
data - is the body data to include with the request
Returns:
Response represents the server's response to this request

urlEncodeMap

public static java.lang.String urlEncodeMap(java.util.Map<java.lang.String,java.lang.String> map)
Utility that performs UTF-8 encoding of a map of Strings. Returns a String that is suitable for use as an application/x-www-form-urlencoded list of parameters in an HTTP PUT or HTTP POST.

Parameters:
map - is the map of String values to format as a UTF-8 String
Returns:
String is the UTF-8 encoding of the map of String values

addDefaultHeaders

protected java.util.Map<java.lang.String,java.lang.String> addDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)

addDefaultParams

protected java.util.Map<java.lang.String,java.lang.String> addDefaultParams(java.util.Map<java.lang.String,java.lang.String> params)

encodeData

protected java.lang.String encodeData(java.lang.String data)