You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jx...@apache.org on 2012/08/08 04:43:33 UTC
svn commit: r1370645 - in
/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client:
Client.java RemoteHTable.java
Author: jxiang
Date: Wed Aug 8 02:43:33 2012
New Revision: 1370645
URL: http://svn.apache.org/viewvc?rev=1370645&view=rev
Log:
HBASE-6444 Expose the ability to set custom HTTP Request Headers for the REST client used by RemoteHTable
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java?rev=1370645&r1=1370644&r2=1370645&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java Wed Aug 8 02:43:33 2012
@@ -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;
@@ -51,6 +54,8 @@ public class Client {
private HttpClient httpClient;
private Cluster cluster;
+ private Map<String, String> extraHeaders;
+
/**
* Default Constructor
*/
@@ -70,6 +75,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);
@@ -85,6 +91,43 @@ public class Client {
}
/**
+ * @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
* the list until a transaction can be successfully completed. The
@@ -132,6 +175,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);
@@ -452,5 +498,4 @@ public class Client {
method.releaseConnection();
}
}
-
}
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java?rev=1370645&r1=1370644&r2=1370645&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java Wed Aug 8 02:43:33 2012
@@ -76,7 +76,7 @@ public class RemoteHTable implements HTa
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();