Skip to content

Commit

Permalink
HBASE-16267 Remove commons-httpclient dependency from hbase-rest module
Browse files Browse the repository at this point in the history
  • Loading branch information
tedyu committed Aug 2, 2016
1 parent b35cf8f commit 379b86c
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 107 deletions.
4 changes: 4 additions & 0 deletions hbase-rest/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Response get(final @Context UriInfo uriInfo) {
servlet.getMetrics().incrementSucessfulGetRequests(1); servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build(); return Response.ok(model).build();
} }
} catch (Exception e) { } catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1); servlet.getMetrics().incrementFailedGetRequests(1);
return processException(e); return processException(e);
} }
Expand Down
210 changes: 132 additions & 78 deletions hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/Client.java

Large diffs are not rendered by default.

Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@


package org.apache.hadoop.hbase.rest.client; package org.apache.hadoop.hbase.rest.client;


import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability; import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.mortbay.log.Log;


/** /**
* The HTTP result code, response headers, and body of a HTTP response. * The HTTP result code, response headers, and body of a HTTP response.
Expand All @@ -34,6 +37,7 @@ public class Response {
private int code; private int code;
private Header[] headers; private Header[] headers;
private byte[] body; private byte[] body;
private HttpResponse resp;
private InputStream stream; private InputStream stream;


/** /**
Expand Down Expand Up @@ -69,13 +73,15 @@ public Response(int code, Header[] headers, byte[] body) {
* Constructor * Constructor
* @param code the HTTP response code * @param code the HTTP response code
* @param headers headers the HTTP response headers * @param headers headers the HTTP response headers
* @param body the response body, can be null * @param resp the response
* @param in Inputstream if the response had one. * @param in Inputstream if the response had one.
* Note: this is not thread-safe
*/ */
public Response(int code, Header[] headers, byte[] body, InputStream in) { public Response(int code, Header[] headers, HttpResponse resp, InputStream in) {
this.code = code; this.code = code;
this.headers = headers; this.headers = headers;
this.body = body; this.body = null;
this.resp = resp;
this.stream = in; this.stream = in;
} }


Expand Down Expand Up @@ -129,6 +135,13 @@ public boolean hasBody() {
* @return the HTTP response body * @return the HTTP response body
*/ */
public byte[] getBody() { public byte[] getBody() {
if (body == null) {
try {
body = Client.getResponseBody(resp);
} catch (IOException ioe) {
Log.debug("encountered ioe when obtaining body", ioe);
}
}
return body; return body;
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Dictionary;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;


import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.hadoop.hbase.CompatibilityFactory; import org.apache.hadoop.hbase.CompatibilityFactory;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.rest.client.Response; import org.apache.hadoop.hbase.rest.client.Response;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
Expand Down Expand Up @@ -95,8 +96,8 @@ public void testGzipFilter() throws Exception {
// input side filter // input side filter


Header[] headers = new Header[2]; Header[] headers = new Header[2];
headers[0] = new Header("Content-Type", Constants.MIMETYPE_BINARY); headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Content-Encoding", "gzip"); headers[1] = new BasicHeader("Content-Encoding", "gzip");
Response response = client.put(path, headers, value_1_gzip); Response response = client.put(path, headers, value_1_gzip);
assertEquals(response.getCode(), 200); assertEquals(response.getCode(), 200);


Expand All @@ -110,8 +111,8 @@ public void testGzipFilter() throws Exception {


// output side filter // output side filter


headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY); headers[0] = new BasicHeader("Accept", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Accept-Encoding", "gzip"); headers[1] = new BasicHeader("Accept-Encoding", "gzip");
response = client.get(path, headers); response = client.get(path, headers);
assertEquals(response.getCode(), 200); assertEquals(response.getCode(), 200);
ByteArrayInputStream bis = new ByteArrayInputStream(response.getBody()); ByteArrayInputStream bis = new ByteArrayInputStream(response.getBody());
Expand All @@ -128,8 +129,8 @@ public void testGzipFilter() throws Exception {
@Test @Test
public void testErrorNotGzipped() throws Exception { public void testErrorNotGzipped() throws Exception {
Header[] headers = new Header[2]; Header[] headers = new Header[2];
headers[0] = new Header("Accept", Constants.MIMETYPE_BINARY); headers[0] = new BasicHeader("Accept", Constants.MIMETYPE_BINARY);
headers[1] = new Header("Accept-Encoding", "gzip"); headers[1] = new BasicHeader("Accept-Encoding", "gzip");
Response response = client.get("/" + TABLE + "/" + ROW_1 + "/" + COLUMN_2, headers); Response response = client.get("/" + TABLE + "/" + ROW_1 + "/" + COLUMN_2, headers);
assertEquals(response.getCode(), 404); assertEquals(response.getCode(), 404);
String contentEncoding = response.getHeader("Content-Encoding"); String contentEncoding = response.getHeader("Content-Encoding");
Expand All @@ -142,9 +143,9 @@ public void testErrorNotGzipped() throws Exception {


void testScannerResultCodes() throws Exception { void testScannerResultCodes() throws Exception {
Header[] headers = new Header[3]; Header[] headers = new Header[3];
headers[0] = new Header("Content-Type", Constants.MIMETYPE_XML); headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_XML);
headers[1] = new Header("Accept", Constants.MIMETYPE_JSON); headers[1] = new BasicHeader("Accept", Constants.MIMETYPE_JSON);
headers[2] = new Header("Accept-Encoding", "gzip"); headers[2] = new BasicHeader("Accept-Encoding", "gzip");
Response response = client.post("/" + TABLE + "/scanner", headers, Response response = client.post("/" + TABLE + "/scanner", headers,
"<Scanner/>".getBytes()); "<Scanner/>".getBytes());
assertEquals(response.getCode(), 201); assertEquals(response.getCode(), 201);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/ */
package org.apache.hadoop.hbase.rest; package org.apache.hadoop.hbase.rest;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
Expand Down Expand Up @@ -96,7 +97,7 @@ public TestMultiRowResource(Boolean csrf) {
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration(); conf = TEST_UTIL.getConfiguration();
conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled);
extraHdr = new Header(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, "");
TEST_UTIL.startMiniCluster(); TEST_UTIL.startMiniCluster();
REST_TEST_UTIL.startServletContainer(conf); REST_TEST_UTIL.startServletContainer(conf);
context = JAXBContext.newInstance( context = JAXBContext.newInstance(
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader;


import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
Expand Down Expand Up @@ -86,7 +87,7 @@ public TestSchemaResource(Boolean csrf) {
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration(); conf = TEST_UTIL.getConfiguration();
conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled);
extraHdr = new Header(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, "");
TEST_UTIL.startMiniCluster(); TEST_UTIL.startMiniCluster();
REST_TEST_UTIL.startServletContainer(conf); REST_TEST_UTIL.startServletContainer(conf);
client = new Client(new Cluster().add("localhost", client = new Client(new Cluster().add("localhost",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;


import org.apache.commons.httpclient.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
Expand Down Expand Up @@ -513,16 +514,16 @@ public void testResponse(){
Response response = new Response(200); Response response = new Response(200);
assertEquals(200, response.getCode()); assertEquals(200, response.getCode());
Header[] headers = new Header[2]; Header[] headers = new Header[2];
headers[0] = new Header("header1", "value1"); headers[0] = new BasicHeader("header1", "value1");
headers[1] = new Header("header2", "value2"); headers[1] = new BasicHeader("header2", "value2");
response = new Response(200, headers); response = new Response(200, headers);
assertEquals("value1", response.getHeader("header1")); assertEquals("value1", response.getHeader("header1"));
assertFalse(response.hasBody()); assertFalse(response.hasBody());
response.setCode(404); response.setCode(404);
assertEquals(404, response.getCode()); assertEquals(404, response.getCode());
headers = new Header[2]; headers = new Header[2];
headers[0] = new Header("header1", "value1.1"); headers[0] = new BasicHeader("header1", "value1.1");
headers[1] = new Header("header2", "value2"); headers[1] = new BasicHeader("header2", "value2");
response.setHeaders(headers); response.setHeaders(headers);
assertEquals("value1.1", response.getHeader("header1")); assertEquals("value1.1", response.getHeader("header1"));
response.setBody(Bytes.toBytes("body")); response.setBody(Bytes.toBytes("body"));
Expand Down
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@
<disruptor.version>3.3.0</disruptor.version> <disruptor.version>3.3.0</disruptor.version>
<!-- Do not use versions earlier than 3.2.2 due to a security vulnerability --> <!-- Do not use versions earlier than 3.2.2 due to a security vulnerability -->
<collections.version>3.2.2</collections.version> <collections.version>3.2.2</collections.version>
<httpclient.version>4.3.6</httpclient.version> <httpclient.version>4.5.2</httpclient.version>
<httpcore.version>4.4.4</httpcore.version> <httpcore.version>4.4.4</httpcore.version>
<metrics-core.version>3.1.2</metrics-core.version> <metrics-core.version>3.1.2</metrics-core.version>
<guava.version>12.0.1</guava.version> <guava.version>12.0.1</guava.version>
Expand Down Expand Up @@ -2194,6 +2194,10 @@
<artifactId>hadoop-common</artifactId> <artifactId>hadoop-common</artifactId>
<version>${hadoop-two.version}</version> <version>${hadoop-two.version}</version>
<exclusions> <exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>javax.servlet.jsp</groupId> <groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId> <artifactId>jsp-api</artifactId>
Expand Down Expand Up @@ -2224,6 +2228,10 @@
<artifactId>hadoop-minicluster</artifactId> <artifactId>hadoop-minicluster</artifactId>
<version>${hadoop-two.version}</version> <version>${hadoop-two.version}</version>
<exclusions> <exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>javax.servlet.jsp</groupId> <groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId> <artifactId>jsp-api</artifactId>
Expand Down Expand Up @@ -2360,6 +2368,10 @@
<artifactId>hadoop-common</artifactId> <artifactId>hadoop-common</artifactId>
<version>${hadoop-three.version}</version> <version>${hadoop-three.version}</version>
<exclusions> <exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>javax.servlet.jsp</groupId> <groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId> <artifactId>jsp-api</artifactId>
Expand Down Expand Up @@ -2395,6 +2407,10 @@
<artifactId>hadoop-minicluster</artifactId> <artifactId>hadoop-minicluster</artifactId>
<version>${hadoop-three.version}</version> <version>${hadoop-three.version}</version>
<exclusions> <exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>javax.servlet.jsp</groupId> <groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId> <artifactId>jsp-api</artifactId>
Expand Down

0 comments on commit 379b86c

Please sign in to comment.