Class Client
java.lang.Object
org.apache.hadoop.hbase.rest.client.Client
A wrapper around HttpClient which provides some useful function and semantics for interacting
with the REST gateway.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private static final String
private Cluster
private org.apache.hadoop.conf.Configuration
private static final String
static final org.apache.http.Header[]
private org.apache.http.client.HttpClient
private org.apache.http.client.methods.HttpGet
private Integer
private static final org.slf4j.Logger
private org.apache.http.HttpResponse
private boolean
private boolean
-
Constructor Summary
ConstructorDescriptionClient()
Default ConstructorConstructorConstructorClient
(Cluster cluster, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections)ConstructorClient
(Cluster cluster, org.apache.hadoop.conf.Configuration conf, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExtraHeader
(String name, String value) Add extra headers.Send a DELETE requestSend a DELETE requestSend a DELETE requestSend a DELETE requestorg.apache.http.HttpResponse
execute
(Cluster cluster, org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String path) Execute a transaction method.org.apache.http.HttpResponse
executePathOnly
(Cluster cluster, org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String path) Execute a transaction method given only the path.org.apache.http.HttpResponse
executeURI
(org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String uri) Execute a transaction method given a complete URI.Send a GET requestSend a GET requestSend a GET requestSend a GET requestSend a GET requestSend a GET requestReturns the cluster definitiongetExtraHeader
(String name) Get an extra header value.Get all extra headers (read-only).org.apache.http.client.HttpClient
Returns the wrapped HttpClientstatic byte[]
getResponseBody
(org.apache.http.HttpResponse resp) Returns the response body of the HTTPResponse, if any, as an array of bytes.Send a HEAD requestSend a HEAD requestprivate void
initialize
(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, Optional<KeyStore> trustStore) private void
injectToken
(org.apache.http.client.methods.HttpUriRequest method, org.apache.hadoop.security.authentication.client.AuthenticatedURL.Token token) Helper method that injects an authentication token to send with the method.boolean
isSticky()
The default behaviour is load balancing by sending each request to a random host.private void
Initiate client side Kerberos negotiation with the server.Send a POST requestSend a POST requestSend a POST requestSend a POST requestpost
(Cluster cluster, String path, String contentType, byte[] content, org.apache.http.Header extraHdr) Send a POST requestSend a POST requestSend a PUT requestSend a PUT requestSend a PUT requestSend a PUT requestput
(Cluster cluster, String path, String contentType, byte[] content, org.apache.http.Header extraHdr) Send a PUT requestSend a PUT requestvoid
removeExtraHeader
(String name) Remove an extra header.void
setCluster
(Cluster cluster) void
setSticky
(boolean sticky) The default behaviour is load balancing by sending each request to a random host.void
shutdown()
Shut down the client.
-
Field Details
-
EMPTY_HEADER_ARRAY
-
LOG
-
httpClient
-
cluster
-
lastNodeId
-
sticky
-
conf
-
sslEnabled
-
resp
-
httpGet
-
extraHeaders
-
AUTH_COOKIE
- See Also:
-
AUTH_COOKIE_EQ
- See Also:
-
COOKIE
- See Also:
-
-
Constructor Details
-
Client
public Client()Default Constructor -
Client
Constructor- Parameters:
cluster
- the cluster definition
-
Client
Constructor- Parameters:
cluster
- the cluster definitionsslEnabled
- enable SSL or not
-
Client
Constructor- Parameters:
cluster
- the cluster definitionconf
- ConfigurationsslEnabled
- enable SSL or not
-
Client
public Client(Cluster cluster, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections)- Parameters:
cluster
- the cluster definitiontrustStorePath
- custom trust store to use for SSL connectionstrustStorePassword
- password to use for custom trust storetrustStoreType
- type of custom trust store- Throws:
Client.ClientTrustStoreInitializationException
- if the trust store file can not be loaded
-
Client
public Client(Cluster cluster, org.apache.hadoop.conf.Configuration conf, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections)- Parameters:
cluster
- the cluster definitionconf
- ConfigurationtrustStorePath
- custom trust store to use for SSL connectionstrustStorePassword
- password to use for custom trust storetrustStoreType
- type of custom trust store- Throws:
Client.ClientTrustStoreInitializationException
- if the trust store file can not be loaded
-
-
Method Details
-
initialize
private void initialize(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, Optional<KeyStore> trustStore) -
shutdown
Shut down the client. Close any open persistent connections. -
getHttpClient
Returns the wrapped HttpClient -
addExtraHeader
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
Get an extra header value. -
getExtraHeaders
Get all extra headers (read-only). -
removeExtraHeader
Remove an extra header. -
executePathOnly
public org.apache.http.HttpResponse executePathOnly(Cluster cluster, org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String path) throws IOException Execute a transaction method given only the path. If sticky is false: 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. If sticky is true: For the first request it will select a random one of the members of the supplied cluster definition. For subsequent requests it will use the same member, and it will not automatically re-try if the call fails.- Parameters:
cluster
- the cluster definitionmethod
- the transaction methodheaders
- HTTP header values to sendpath
- the properly urlencoded path- Returns:
- the HTTP response code
- Throws:
IOException
-
executeURI
public org.apache.http.HttpResponse executeURI(org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String uri) throws IOException Execute a transaction method given a complete URI.- Parameters:
method
- the transaction methodheaders
- HTTP header values to senduri
- a properly urlencoded URI- Returns:
- the HTTP response code
- Throws:
IOException
-
execute
public org.apache.http.HttpResponse execute(Cluster cluster, org.apache.http.client.methods.HttpUriRequest method, org.apache.http.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 definitionmethod
- the HTTP methodheaders
- HTTP header values to sendpath
- the properly urlencoded path or URI- Returns:
- the HTTP response code
- Throws:
IOException
-
negotiate
private void negotiate(org.apache.http.client.methods.HttpUriRequest method, String uri) throws IOException Initiate client side Kerberos negotiation with the server.- Parameters:
method
- method to inject the authentication token into.uri
- the String to parse as a URL.- Throws:
IOException
- if unknown protocol is found.
-
injectToken
private void injectToken(org.apache.http.client.methods.HttpUriRequest method, org.apache.hadoop.security.authentication.client.AuthenticatedURL.Token token) Helper method that injects an authentication token to send with the method.- Parameters:
method
- method to inject the authentication token into.token
- authentication token to inject.
-
getCluster
Returns the cluster definition -
setCluster
- Parameters:
cluster
- the cluster definition
-
isSticky
The default behaviour is load balancing by sending each request to a random host. This DOES NOT work with scans, which have state on the REST servers. Make sure sticky is set to true before attempting Scan related operations if more than one host is defined in the cluster.- Returns:
- whether subsequent requests will use the same host
-
setSticky
The default behaviour is load balancing by sending each request to a random host. This DOES NOT work with scans, which have state on the REST servers. Set sticky to true before attempting Scan related operations if more than one host is defined in the cluster. Nodes must not be added or removed from the Cluster object while sticky is true.- Parameters:
sticky
- whether subsequent requests will use the same host
-
head
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.http.Header[] headers) throws IOException Send a HEAD request- Parameters:
cluster
- the cluster definitionpath
- the path or URIheaders
- the HTTP headers to include in the request- Returns:
- a Response object with response detail
- Throws:
IOException
-
get
Send a GET request- Parameters:
path
- the path or URI- Returns:
- a Response object with response detail
- Throws:
IOException
-
get
Send a GET request- Parameters:
cluster
- the cluster definitionpath
- the path or URI- Returns:
- a Response object with response detail
- Throws:
IOException
-
get
Send a GET request- Parameters:
path
- the path or URIaccept
- Accept header value- Returns:
- a Response object with response detail
- Throws:
IOException
-
get
Send a GET request- Parameters:
cluster
- the cluster definitionpath
- the path or URIaccept
- Accept header value- Returns:
- a Response object with response detail
- Throws:
IOException
-
get
Send a GET request- Parameters:
path
- the path or URIheaders
- the HTTP headers to include in the request, Accept must be supplied- Returns:
- a Response object with response detail
- Throws:
IOException
-
getResponseBody
Returns the response body of the HTTPResponse, if any, as an array of bytes. If response body is not available or cannot be read, returns null Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or reasonably large.- Parameters:
resp
- HttpResponse- Returns:
- The response body, null if body is empty
- Throws:
IOException
- If an I/O (transport) problem occurs while obtaining the response body.
-
get
Send a GET request- Parameters:
c
- the cluster definitionpath
- the path or URIheaders
- the HTTP headers to include in the request- Returns:
- a Response object with response detail
- Throws:
IOException
-
put
Send a PUT request- Parameters:
path
- the path or URIcontentType
- the content MIME typecontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
put
public Response put(String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a PUT request- Parameters:
path
- the path or URIcontentType
- the content MIME typecontent
- the content bytesextraHdr
- extra Header to send- 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 definitionpath
- the path or URIcontentType
- the content MIME typecontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-
put
public Response put(Cluster cluster, String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a PUT request- Parameters:
cluster
- the cluster definitionpath
- the path or URIcontentType
- the content MIME typecontent
- the content bytesextraHdr
- additional Header to send- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-
put
public Response put(String path, org.apache.http.Header[] headers, byte[] content) throws IOException Send a PUT request- Parameters:
path
- the path or URIheaders
- the HTTP headers to include, Content-Type must be suppliedcontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
put
public Response put(Cluster cluster, String path, org.apache.http.Header[] headers, byte[] content) throws IOException Send a PUT request- Parameters:
cluster
- the cluster definitionpath
- the path or URIheaders
- the HTTP headers to include, Content-Type must be suppliedcontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
post
Send a POST request- Parameters:
path
- the path or URIcontentType
- the content MIME typecontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
post
public Response post(String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a POST request- Parameters:
path
- the path or URIcontentType
- the content MIME typecontent
- the content bytesextraHdr
- additional Header to send- 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 definitionpath
- the path or URIcontentType
- the content MIME typecontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-
post
public Response post(Cluster cluster, String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a POST request- Parameters:
cluster
- the cluster definitionpath
- the path or URIcontentType
- the content MIME typecontent
- the content bytesextraHdr
- additional Header to send- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-
post
public Response post(String path, org.apache.http.Header[] headers, byte[] content) throws IOException Send a POST request- Parameters:
path
- the path or URIheaders
- the HTTP headers to include, Content-Type must be suppliedcontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
post
public Response post(Cluster cluster, String path, org.apache.http.Header[] headers, byte[] content) throws IOException Send a POST request- Parameters:
cluster
- the cluster definitionpath
- the path or URIheaders
- the HTTP headers to include, Content-Type must be suppliedcontent
- the content bytes- Returns:
- a Response object with response detail
- Throws:
IOException
-
delete
Send a DELETE request- Parameters:
path
- the path or URI- Returns:
- a Response object with response detail
- Throws:
IOException
-
delete
Send a DELETE request- Parameters:
path
- the path or URIextraHdr
- additional Header to send- Returns:
- a Response object with response detail
- Throws:
IOException
-
delete
Send a DELETE request- Parameters:
cluster
- the cluster definitionpath
- the path or URI- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-
delete
public Response delete(Cluster cluster, String path, org.apache.http.Header extraHdr) throws IOException Send a DELETE request- Parameters:
cluster
- the cluster definitionpath
- the path or URI- Returns:
- a Response object with response detail
- Throws:
IOException
- for error
-