org.apache.hadoop.hbase.rest.client
Class Client

java.lang.Object
  extended by org.apache.hadoop.hbase.rest.client.Client

public class Client
extends Object

A wrapper around HttpClient which provides some useful function and semantics for interacting with the REST gateway.


Field Summary
static org.apache.commons.httpclient.Header[] EMPTY_HEADER_ARRAY
           
 
Constructor Summary
Client()
          Default Constructor
Client(Cluster cluster)
          Constructor
 
Method Summary
 void addExtraHeader(String name, String value)
          Add extra headers.
 Response delete(Cluster cluster, String path)
          Send a DELETE request
 Response delete(String path)
          Send a DELETE request
 int execute(Cluster cluster, org.apache.commons.httpclient.HttpMethod method, org.apache.commons.httpclient.Header[] headers, String path)
          Execute a transaction method.
 int executePathOnly(Cluster cluster, org.apache.commons.httpclient.HttpMethod method, org.apache.commons.httpclient.Header[] headers, String path)
          Execute a transaction method given only the path.
 int executeURI(org.apache.commons.httpclient.HttpMethod method, org.apache.commons.httpclient.Header[] headers, String uri)
          Execute a transaction method given a complete URI.
 Response get(Cluster cluster, String path)
          Send a GET request
 Response get(Cluster c, String path, org.apache.commons.httpclient.Header[] headers)
          Send a GET request
 Response get(Cluster cluster, String path, String accept)
          Send a GET request
 Response get(String path)
          Send a GET request
 Response get(String path, org.apache.commons.httpclient.Header[] headers)
          Send a GET request
 Response get(String path, String accept)
          Send a GET request
 Cluster getCluster()
           
 String getExtraHeader(String name)
          Get an extra header value.
 Map<String,String> getExtraHeaders()
          Get all extra headers (read-only).
 org.apache.commons.httpclient.HttpClient getHttpClient()
           
 Response head(Cluster cluster, String path, org.apache.commons.httpclient.Header[] headers)
          Send a HEAD request
 Response head(String path)
          Send a HEAD request
 Response post(Cluster cluster, String path, org.apache.commons.httpclient.Header[] headers, byte[] content)
          Send a POST request
 Response post(Cluster cluster, String path, String contentType, byte[] content)
          Send a POST request
 Response post(String path, org.apache.commons.httpclient.Header[] headers, byte[] content)
          Send a POST request
 Response post(String path, String contentType, byte[] content)
          Send a POST request
 Response put(Cluster cluster, String path, org.apache.commons.httpclient.Header[] headers, byte[] content)
          Send a PUT request
 Response put(Cluster cluster, String path, String contentType, byte[] content)
          Send a PUT request
 Response put(String path, org.apache.commons.httpclient.Header[] headers, byte[] content)
          Send a PUT request
 Response put(String path, String contentType, byte[] content)
          Send a PUT request
 void removeExtraHeader(String name)
          Remove an extra header.
 void setCluster(Cluster cluster)
           
 void shutdown()
          Shut down the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_HEADER_ARRAY

public static final org.apache.commons.httpclient.Header[] EMPTY_HEADER_ARRAY
Constructor Detail

Client

public Client()
Default Constructor


Client

public Client(Cluster cluster)
Constructor

Parameters:
cluster - the cluster definition
Method Detail

shutdown

public void shutdown()
Shut down the client. Close any open persistent connections.


getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient()
Returns:
the wrapped HttpClient

addExtraHeader

public void addExtraHeader(String name,
                           String value)
Add extra headers. These extra headers will be applied to all http methods before they are removed. If any header is not used any more, client needs to remove it explicitly.


getExtraHeader

public String getExtraHeader(String name)
Get an extra header value.


getExtraHeaders

public Map<String,String> getExtraHeaders()
Get all extra headers (read-only).


removeExtraHeader

public void removeExtraHeader(String name)
Remove an extra header.


executePathOnly

public int executePathOnly(Cluster cluster,
                           org.apache.commons.httpclient.HttpMethod method,
                           org.apache.commons.httpclient.Header[] headers,
                           String path)
                    throws IOException
Execute a transaction method given only the path. Will select at random one of the members of the supplied cluster definition and iterate through the list until a transaction can be successfully completed. The definition of success here is a complete HTTP transaction, irrespective of result code.

Parameters:
cluster - the cluster definition
method - the transaction method
headers - HTTP header values to send
path - the properly urlencoded path
Returns:
the HTTP response code
Throws:
IOException

executeURI

public int executeURI(org.apache.commons.httpclient.HttpMethod method,
                      org.apache.commons.httpclient.Header[] headers,
                      String uri)
               throws IOException
Execute a transaction method given a complete URI.

Parameters:
method - the transaction method
headers - HTTP header values to send
uri - a properly urlencoded URI
Returns:
the HTTP response code
Throws:
IOException

execute

public int execute(Cluster cluster,
                   org.apache.commons.httpclient.HttpMethod method,
                   org.apache.commons.httpclient.Header[] headers,
                   String path)
            throws IOException
Execute a transaction method. Will call either executePathOnly or executeURI depending on whether a path only is supplied in 'path', or if a complete URI is passed instead, respectively.

Parameters:
cluster - the cluster definition
method - the HTTP method
headers - HTTP header values to send
path - the properly urlencoded path or URI
Returns:
the HTTP response code
Throws:
IOException

getCluster

public Cluster getCluster()
Returns:
the cluster definition

setCluster

public void setCluster(Cluster cluster)
Parameters:
cluster - the cluster definition

head

public Response head(String path)
              throws IOException
Send a HEAD request

Parameters:
path - the path or URI
Returns:
a Response object with response detail
Throws:
IOException

head

public Response head(Cluster cluster,
                     String path,
                     org.apache.commons.httpclient.Header[] headers)
              throws IOException
Send a HEAD request

Parameters:
cluster - the cluster definition
path - the path or URI
headers - the HTTP headers to include in the request
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(String path)
             throws IOException
Send a GET request

Parameters:
path - the path or URI
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(Cluster cluster,
                    String path)
             throws IOException
Send a GET request

Parameters:
cluster - the cluster definition
path - the path or URI
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(String path,
                    String accept)
             throws IOException
Send a GET request

Parameters:
path - the path or URI
accept - Accept header value
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(Cluster cluster,
                    String path,
                    String accept)
             throws IOException
Send a GET request

Parameters:
cluster - the cluster definition
path - the path or URI
accept - Accept header value
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(String path,
                    org.apache.commons.httpclient.Header[] headers)
             throws IOException
Send a GET request

Parameters:
path - the path or URI
headers - the HTTP headers to include in the request, Accept must be supplied
Returns:
a Response object with response detail
Throws:
IOException

get

public Response get(Cluster c,
                    String path,
                    org.apache.commons.httpclient.Header[] headers)
             throws IOException
Send a GET request

Parameters:
c - the cluster definition
path - the path or URI
headers - the HTTP headers to include in the request
Returns:
a Response object with response detail
Throws:
IOException

put

public Response put(String path,
                    String contentType,
                    byte[] content)
             throws IOException
Send a PUT request

Parameters:
path - the path or URI
contentType - the content MIME type
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

put

public Response put(Cluster cluster,
                    String path,
                    String contentType,
                    byte[] content)
             throws IOException
Send a PUT request

Parameters:
cluster - the cluster definition
path - the path or URI
contentType - the content MIME type
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

put

public Response put(String path,
                    org.apache.commons.httpclient.Header[] headers,
                    byte[] content)
             throws IOException
Send a PUT request

Parameters:
path - the path or URI
headers - the HTTP headers to include, Content-Type must be supplied
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

put

public Response put(Cluster cluster,
                    String path,
                    org.apache.commons.httpclient.Header[] headers,
                    byte[] content)
             throws IOException
Send a PUT request

Parameters:
cluster - the cluster definition
path - the path or URI
headers - the HTTP headers to include, Content-Type must be supplied
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

post

public Response post(String path,
                     String contentType,
                     byte[] content)
              throws IOException
Send a POST request

Parameters:
path - the path or URI
contentType - the content MIME type
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

post

public Response post(Cluster cluster,
                     String path,
                     String contentType,
                     byte[] content)
              throws IOException
Send a POST request

Parameters:
cluster - the cluster definition
path - the path or URI
contentType - the content MIME type
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

post

public Response post(String path,
                     org.apache.commons.httpclient.Header[] headers,
                     byte[] content)
              throws IOException
Send a POST request

Parameters:
path - the path or URI
headers - the HTTP headers to include, Content-Type must be supplied
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

post

public Response post(Cluster cluster,
                     String path,
                     org.apache.commons.httpclient.Header[] headers,
                     byte[] content)
              throws IOException
Send a POST request

Parameters:
cluster - the cluster definition
path - the path or URI
headers - the HTTP headers to include, Content-Type must be supplied
content - the content bytes
Returns:
a Response object with response detail
Throws:
IOException

delete

public Response delete(String path)
                throws IOException
Send a DELETE request

Parameters:
path - the path or URI
Returns:
a Response object with response detail
Throws:
IOException

delete

public Response delete(Cluster cluster,
                       String path)
                throws IOException
Send a DELETE request

Parameters:
cluster - the cluster definition
path - the path or URI
Returns:
a Response object with response detail
Throws:
IOException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.