HBASE-6444 Expose the ability to set custom HTTP Request Headers for the REST client used by RemoteHTable
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1370635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f807add65b
commit
5671b5ca86
|
@ -21,6 +21,9 @@
|
|||
package org.apache.hadoop.hbase.rest.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
|
@ -55,6 +58,8 @@ public class Client {
|
|||
private HttpClient httpClient;
|
||||
private Cluster cluster;
|
||||
|
||||
private Map<String, String> extraHeaders;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
|
@ -74,6 +79,7 @@ public class Client {
|
|||
managerParams.setConnectionTimeout(2000); // 2 s
|
||||
managerParams.setDefaultMaxConnectionsPerHost(10);
|
||||
managerParams.setMaxTotalConnections(100);
|
||||
extraHeaders = new ConcurrentHashMap<String, String>();
|
||||
this.httpClient = new HttpClient(manager);
|
||||
HttpClientParams clientParams = httpClient.getParams();
|
||||
clientParams.setVersion(HttpVersion.HTTP_1_1);
|
||||
|
@ -88,6 +94,43 @@ public class Client {
|
|||
manager.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wrapped HttpClient
|
||||
*/
|
||||
public HttpClient getHttpClient() {
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void addExtraHeader(final String name, final String value) {
|
||||
extraHeaders.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an extra header value.
|
||||
*/
|
||||
public String getExtraHeader(final String name) {
|
||||
return extraHeaders.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all extra headers (read-only).
|
||||
*/
|
||||
public Map<String, String> getExtraHeaders() {
|
||||
return Collections.unmodifiableMap(extraHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an extra header.
|
||||
*/
|
||||
public void removeExtraHeader(final String name) {
|
||||
extraHeaders.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a transaction method given only the path. Will select at random
|
||||
* one of the members of the supplied cluster definition and iterate through
|
||||
|
@ -136,6 +179,9 @@ public class Client {
|
|||
public int executeURI(HttpMethod method, Header[] headers, String uri)
|
||||
throws IOException {
|
||||
method.setURI(new URI(uri, true));
|
||||
for (Map.Entry<String, String> e: extraHeaders.entrySet()) {
|
||||
method.addRequestHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
if (headers != null) {
|
||||
for (Header header: headers) {
|
||||
method.addRequestHeader(header);
|
||||
|
@ -456,5 +502,4 @@ public class Client {
|
|||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class RemoteHTable implements HTableInterface {
|
|||
final int maxRetries;
|
||||
final long sleepTime;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected String buildRowSpec(final byte[] row, final Map familyMap,
|
||||
final long startTime, final long endTime, final int maxVersions) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
|
Loading…
Reference in New Issue