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:32:24 UTC

svn commit: r1370635 - in /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client: Client.java RemoteHTable.java

Author: jxiang
Date: Wed Aug  8 02:32:24 2012
New Revision: 1370635

URL: http://svn.apache.org/viewvc?rev=1370635&view=rev
Log:
HBASE-6444 Expose the ability to set custom HTTP Request Headers for the REST client used by RemoteHTable

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java?rev=1370635&r1=1370634&r2=1370635&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java Wed Aug  8 02:32:24 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;
@@ -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);
@@ -89,6 +95,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
@@ -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();
     }
   }
-
 }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java?rev=1370635&r1=1370634&r2=1370635&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java Wed Aug  8 02:32:24 2012
@@ -80,7 +80,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();