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 SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate org.apache.hadoop.security.authentication.client.KerberosAuthenticatorprivate Clusterprivate org.apache.hadoop.conf.Configurationprivate static final Stringstatic final org.apache.http.Header[]private org.apache.http.impl.client.CloseableHttpClientprivate org.apache.http.client.methods.HttpGetprivate Integerprivate static final org.slf4j.Loggerprivate org.apache.http.impl.client.BasicCredentialsProviderprivate org.apache.http.HttpResponseprivate booleanprivate booleanprivate org.apache.http.client.protocol.HttpClientContext
- 
Constructor SummaryConstructorsConstructorDescriptionClient()Default ConstructorConstructor This constructor will create an object using the old faulty load balancing logic.Constructor This constructor will create an object using the old faulty load balancing logic.Client(Cluster cluster, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections) This constructor will create an object using the old faulty load balancing logic.Constructor This constructor will create an object using the old faulty load balancing logic.Client(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, Optional<KeyStore> trustStore, Optional<String> userName, Optional<String> password, Optional<String> bearerToken) Client(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, Optional<KeyStore> trustStore, Optional<String> userName, Optional<String> password, Optional<String> bearerToken, Optional<org.apache.http.conn.HttpClientConnectionManager> connManager) Constructor that accepts an optional trustStore and authentication information for either BASIC or BEARER authentication in sticky mode, which does not use the old faulty load balancing logic, and enables correct session handling.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).
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddExtraHeader(String name, String value) Add extra headers.voidclose()Send a DELETE requestSend a DELETE requestSend a DELETE requestSend a DELETE requestorg.apache.http.HttpResponseexecute(Cluster cluster, org.apache.http.client.methods.HttpUriRequest method, org.apache.http.Header[] headers, String path) Execute a transaction method.org.apache.http.HttpResponseexecutePathOnly(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.HttpResponseexecuteURI(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.HttpClientReturns 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 voidinitialize(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, boolean sticky, Optional<KeyStore> trustStore, Optional<String> userName, Optional<String> password, Optional<String> bearerToken, Optional<org.apache.http.conn.HttpClientConnectionManager> connManager) private voidinjectToken(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.booleanisSticky()The default behaviour is load balancing by sending each request to a random host.static KeyStoreloadTruststore(String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Loads a trustStore from the local fileSystem.private voidInitiate 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 requestvoidremoveExtraHeader(String name) Remove an extra header.voidsetCluster(Cluster cluster) voidsetSticky(boolean sticky) The default behaviour is load balancing by sending each request to a random host.private org.apache.hadoop.conf.ConfigurationsetupTrustStoreForHadoop(KeyStore trustStore) voidshutdown()Shut down the client.
- 
Field Details- 
EMPTY_HEADER_ARRAY
- 
LOG
- 
httpClient
- 
cluster
- 
lastNodeId
- 
sticky
- 
conf
- 
sslEnabled
- 
resp
- 
httpGet
- 
stickyContext
- 
provider
- 
trustStore
- 
extraHeaders
- 
authenticator
- 
AUTH_COOKIE- See Also:
 
- 
AUTH_COOKIE_EQ- See Also:
 
- 
COOKIE- See Also:
 
 
- 
- 
Constructor Details- 
Clientpublic Client()Default Constructor
- 
ClientConstructor This constructor will create an object using the old faulty load balancing logic. When specifying multiple servers in the cluster object, it is highly recommended to call setSticky() on the created client, or use the preferred constructor instead.- Parameters:
- cluster- the cluster definition
 
- 
ClientConstructor This constructor will create an object using the old faulty load balancing logic. When specifying multiple servers in the cluster object, it is highly recommended to call setSticky() on the created client, or use the preferred constructor instead.- Parameters:
- cluster- the cluster definition
- sslEnabled- enable SSL or not
 
- 
ClientConstructor This constructor will create an object using the old faulty load balancing logic. When specifying multiple servers in the cluster object, it is highly recommended to call setSticky() on the created client, or use the preferred constructor instead.- Parameters:
- cluster- the cluster definition
- conf- Configuration
- sslEnabled- enable SSL or not
 
- 
Clientpublic Client(Cluster cluster, String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Constructor, allowing to define custom trust store (only for SSL connections) This constructor will create an object using the old faulty load balancing logic. When specifying multiple servers in the cluster object, it is highly recommended to call setSticky() on the created client, or use the preferred constructor instead.- Parameters:
- cluster- the cluster definition
- trustStorePath- custom trust store to use for SSL connections
- trustStorePassword- password to use for custom trust store
- trustStoreType- type of custom trust store
- Throws:
- Client.ClientTrustStoreInitializationException- if the trust store file can not be loaded
 
- 
Client@Private public Client(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, Optional<KeyStore> trustStore, Optional<String> userName, Optional<String> password, Optional<String> bearerToken, Optional<org.apache.http.conn.HttpClientConnectionManager> connManager) Constructor that accepts an optional trustStore and authentication information for either BASIC or BEARER authentication in sticky mode, which does not use the old faulty load balancing logic, and enables correct session handling. If neither userName/password, nor the bearer token is specified, the client falls back to SPNEGO auth. The loadTrustsore static method can be used to load a local TrustStore file. If connManager is specified, it must be fully configured. Even then, the TrustStore related parameters must be specified because they are also used for SPNEGO authentication which uses a separate HTTP client implementation. Specifying the HttpClientConnectionManager is an experimental feature. It exposes the internal HTTP library details, and may be changed/removed when the library is updated or replaced.- Parameters:
- cluster- the cluster definition
- conf- HBase/Hadoop configuration
- sslEnabled- use HTTPS
- trustStore- the optional trustStore object
- userName- for BASIC auth
- password- for BASIC auth
- bearerToken- for BEAERER auth
 
- 
Client
- 
Clientpublic 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). This constructor will create an object using the old faulty load balancing logic. When specifying multiple servers in the cluster object, it is highly recommended to call setSticky() on the created client, or use the preferred constructor instead.- Parameters:
- cluster- the cluster definition
- conf- HBase/Hadoop Configuration
- trustStorePath- custom trust store to use for SSL connections
- trustStorePassword- password to use for custom trust store
- trustStoreType- type of custom trust store
- Throws:
- Client.ClientTrustStoreInitializationException- if the trust store file can not be loaded
 
 
- 
- 
Method Details- 
initializeprivate void initialize(Cluster cluster, org.apache.hadoop.conf.Configuration conf, boolean sslEnabled, boolean sticky, Optional<KeyStore> trustStore, Optional<String> userName, Optional<String> password, Optional<String> bearerToken, Optional<org.apache.http.conn.HttpClientConnectionManager> connManager) 
- 
loadTruststorepublic static KeyStore loadTruststore(String trustStorePath, Optional<String> trustStorePassword, Optional<String> trustStoreType) Loads a trustStore from the local fileSystem. Can be used to load the trustStore for the preferred constructor.
- 
shutdownShut down the client. Close any open persistent connections.
- 
getHttpClientReturns the wrapped HttpClient
- 
addExtraHeaderAdd 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.
- 
getExtraHeaderGet an extra header value.
- 
getExtraHeadersGet all extra headers (read-only).
- 
removeExtraHeaderRemove an extra header.
- 
executePathOnlypublic 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 definition
- method- the transaction method
- headers- HTTP header values to send
- path- the properly urlencoded path
- Returns:
- the HTTP response code
- Throws:
- IOException
 
- 
executeURIpublic 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 method
- headers- HTTP header values to send
- uri- a properly urlencoded URI
- Returns:
- the HTTP response code
- Throws:
- IOException
 
- 
executepublic 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 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
 
- 
negotiateprivate void negotiate(org.apache.http.client.methods.HttpUriRequest method, String uri) throws IOException, GeneralSecurityException 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.
- GeneralSecurityException
 
- 
setupTrustStoreForHadoopprivate org.apache.hadoop.conf.Configuration setupTrustStoreForHadoop(KeyStore trustStore) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException 
- 
injectTokenprivate 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.
 
- 
getClusterReturns the cluster definition
- 
setCluster- Parameters:
- cluster- the cluster definition
 
- 
isStickyThe 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
 
- 
setStickyThe 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. Setting the sticky flag also enables session handling, which eliminates the need to re-authenticate each request, and lets the client handle any other cookies (like the sticky cookie set by load balancers) correctly.- Parameters:
- sticky- whether subsequent requests will use the same host
 
- 
headSend a HEAD request- Parameters:
- path- the path or URI
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
headpublic Response head(Cluster cluster, String path, org.apache.http.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
 
- 
getSend a GET request- Parameters:
- path- the path or URI
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
getSend a GET request- Parameters:
- cluster- the cluster definition
- path- the path or URI
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
getSend a GET request- Parameters:
- path- the path or URI
- accept- Accept header value
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
getSend 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
 
- 
getSend 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
 
- 
getResponseBodyReturns 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.
 
- 
getSend 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
 
- 
putSend 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
 
- 
putpublic Response put(String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a PUT request- Parameters:
- path- the path or URI
- contentType- the content MIME type
- content- the content bytes
- extraHdr- extra Header to send
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
putpublic 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- for error
 
- 
putpublic 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 definition
- path- the path or URI
- contentType- the content MIME type
- content- the content bytes
- extraHdr- additional Header to send
- Returns:
- a Response object with response detail
- Throws:
- IOException- for error
 
- 
putpublic Response put(String path, org.apache.http.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
 
- 
putpublic Response put(Cluster cluster, String path, org.apache.http.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
 
- 
postSend 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
 
- 
postpublic Response post(String path, String contentType, byte[] content, org.apache.http.Header extraHdr) throws IOException Send a POST request- Parameters:
- path- the path or URI
- contentType- the content MIME type
- content- the content bytes
- extraHdr- additional Header to send
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
postpublic 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- for error
 
- 
postpublic 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 definition
- path- the path or URI
- contentType- the content MIME type
- content- the content bytes
- extraHdr- additional Header to send
- Returns:
- a Response object with response detail
- Throws:
- IOException- for error
 
- 
postpublic Response post(String path, org.apache.http.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
 
- 
postpublic Response post(Cluster cluster, String path, org.apache.http.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
 
- 
deleteSend a DELETE request- Parameters:
- path- the path or URI
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
deleteSend a DELETE request- Parameters:
- path- the path or URI
- extraHdr- additional Header to send
- Returns:
- a Response object with response detail
- Throws:
- IOException
 
- 
deleteSend a DELETE request- Parameters:
- cluster- the cluster definition
- path- the path or URI
- Returns:
- a Response object with response detail
- Throws:
- IOException- for error
 
- 
deletepublic Response delete(Cluster cluster, String path, org.apache.http.Header extraHdr) 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- for error
 
- 
close
 
-