From 7beca5364483061b081b8a7f4eefb98abbad9314 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Wed, 2 Jan 2013 16:18:30 +0000 Subject: [PATCH] HBASE-7472. [REST] Support MIME type application/protobuf git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1427843 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/rest/Constants.java | 1 + .../hadoop/hbase/rest/ExistsResource.java | 2 +- .../hadoop/hbase/rest/MultiRowResource.java | 3 +- .../hadoop/hbase/rest/RegionsResource.java | 3 +- .../hadoop/hbase/rest/RootResource.java | 3 +- .../apache/hadoop/hbase/rest/RowResource.java | 9 +++-- .../hbase/rest/ScannerInstanceResource.java | 3 +- .../hadoop/hbase/rest/ScannerResource.java | 6 ++-- .../hadoop/hbase/rest/SchemaResource.java | 9 +++-- .../rest/StorageClusterStatusResource.java | 3 +- .../hadoop/hbase/rest/VersionResource.java | 3 +- .../consumer/ProtobufMessageBodyConsumer.java | 2 +- .../producer/ProtobufMessageBodyProducer.java | 2 +- .../hbase/rest/TestMultiRowResource.java | 2 ++ .../hadoop/hbase/rest/TestRowResource.java | 6 ++++ .../hbase/rest/TestScannerResource.java | 5 +++ .../hbase/rest/TestScannersWithFilters.java | 8 +++-- .../hadoop/hbase/rest/TestSchemaResource.java | 11 +++++++ .../hadoop/hbase/rest/TestStatusResource.java | 14 +++++--- .../hadoop/hbase/rest/TestTableResource.java | 33 ++++++++++++++----- .../hbase/rest/TestVersionResource.java | 18 ++++++++-- 21 files changed, 112 insertions(+), 34 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/Constants.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/Constants.java index 62dae0eb38a..43ff5fc1503 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/Constants.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/Constants.java @@ -39,6 +39,7 @@ public interface Constants { public static final String MIMETYPE_XML = "text/xml"; public static final String MIMETYPE_BINARY = "application/octet-stream"; public static final String MIMETYPE_PROTOBUF = "application/x-protobuf"; + public static final String MIMETYPE_PROTOBUF_IETF = "application/protobuf"; public static final String MIMETYPE_JSON = "application/json"; public static final String CRLF = "\r\n"; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ExistsResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ExistsResource.java index 016451359fd..f53a320b3e4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ExistsResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ExistsResource.java @@ -55,7 +55,7 @@ public class ExistsResource extends ResourceBase { @GET @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, - MIMETYPE_BINARY}) + MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY}) public Response get(final @Context UriInfo uriInfo) { try { if (!tableResource.exists()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java index 07e93e4a536..6d098fde161 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/MultiRowResource.java @@ -60,7 +60,8 @@ public class MultiRowResource extends ResourceBase { } @GET - @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { MultivaluedMap params = uriInfo.getQueryParameters(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java index 2f391d7ca75..03ec2787855 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java @@ -66,7 +66,8 @@ public class RegionsResource extends ResourceBase { } @GET - @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java index 8f82f863a64..b2e6cf49d09 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RootResource.java @@ -69,7 +69,8 @@ public class RootResource extends ResourceBase { } @GET - @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java index ec81c0f4b52..c0772e244cb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java @@ -80,7 +80,8 @@ public class RowResource extends ResourceBase { } @GET - @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); @@ -306,7 +307,8 @@ public class RowResource extends ResourceBase { } @PUT - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response put(final CellSetModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { @@ -327,7 +329,8 @@ public class RowResource extends ResourceBase { } @POST - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response post(final CellSetModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java index 51905e5b0e7..967c1400cb7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java @@ -68,7 +68,8 @@ public class ScannerInstanceResource extends ResourceBase { } @GET - @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo, @QueryParam("n") int maxRows, final @QueryParam("c") int maxValues) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java index 55404679874..dbc2e7d74d6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java @@ -120,7 +120,8 @@ public class ScannerResource extends ResourceBase { } @PUT - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response put(final ScannerModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { @@ -130,7 +131,8 @@ public class ScannerResource extends ResourceBase { } @POST - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response post(final ScannerModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java index 9391a6edaf6..09bc4cef586 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/SchemaResource.java @@ -86,7 +86,8 @@ public class SchemaResource extends ResourceBase { } @GET - @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); @@ -209,7 +210,8 @@ public class SchemaResource extends ResourceBase { } @PUT - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response put(final TableSchemaModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { @@ -220,7 +222,8 @@ public class SchemaResource extends ResourceBase { } @POST - @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response post(final TableSchemaModel model, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java index 1b66647434a..22295719441 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/StorageClusterStatusResource.java @@ -60,7 +60,8 @@ public class StorageClusterStatusResource extends ResourceBase { } @GET - @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java index 72294963793..aacb1eb7311 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/VersionResource.java @@ -71,7 +71,8 @@ public class VersionResource extends ResourceBase { * @return a response for a version request */ @GET - @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF}) + @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, + MIMETYPE_PROTOBUF_IETF}) public Response get(final @Context ServletContext context, final @Context UriInfo uriInfo) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/consumer/ProtobufMessageBodyConsumer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/consumer/ProtobufMessageBodyConsumer.java index 6114af29345..61d38b9d303 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/consumer/ProtobufMessageBodyConsumer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/consumer/ProtobufMessageBodyConsumer.java @@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler; * ProtobufMessageHandler interface capable handlers for decoding protobuf input. */ @Provider -@Consumes(Constants.MIMETYPE_PROTOBUF) +@Consumes({Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF}) @InterfaceAudience.Private public class ProtobufMessageBodyConsumer implements MessageBodyReader { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java index f4abe0587c6..93d458297e1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java @@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler; * sent, then writeTo to perform the actual I/O. */ @Provider -@Produces(Constants.MIMETYPE_PROTOBUF) +@Produces({Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF}) @InterfaceAudience.Private public class ProtobufMessageBodyProducer implements MessageBodyWriter { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java index 49fb8e59daf..e14336c82cb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java @@ -116,6 +116,7 @@ public class TestMultiRowResource { Response response = client.get(path.toString(), Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); client.delete(row_5_url); client.delete(row_6_url); @@ -142,6 +143,7 @@ public class TestMultiRowResource { Response response = client.get(path.toString(), Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); client.delete(row_5_url); client.delete(row_6_url); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java index 6b89469cd63..a4b0982021d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java @@ -210,6 +210,7 @@ public class TestRowResource { String value) throws IOException, JAXBException { Response response = getValueXML(table, row, column); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); RowModel rowModel = cellSet.getRows().get(0); @@ -222,6 +223,7 @@ public class TestRowResource { String column, String value) throws IOException, JAXBException { Response response = getValueXML(url); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); RowModel rowModel = cellSet.getRows().get(0); @@ -259,6 +261,7 @@ public class TestRowResource { String value) throws IOException { Response response = getValuePB(table, row, column); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); RowModel rowModel = cellSet.getRows().get(0); @@ -501,6 +504,7 @@ public class TestRowResource { response = client.get(path, Constants.MIMETYPE_BINARY); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type")); assertTrue(Bytes.equals(response.getBody(), body)); boolean foundTimestampHeader = false; for (Header header: response.getHeaders()) { @@ -524,6 +528,7 @@ public class TestRowResource { Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); response = deleteRow(TABLE, ROW_4); assertEquals(response.getCode(), 200); } @@ -537,6 +542,7 @@ public class TestRowResource { Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); response = deleteRow(TABLE, ROW_4); assertEquals(response.getCode(), 200); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java index b30f16ba8d1..5fe72fd30a1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java @@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel; import org.apache.hadoop.hbase.util.Bytes; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -124,6 +125,7 @@ public class TestScannerResource { response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertTrue(response.getCode() == 200 || response.getCode() == 204); if (response.getCode() == 200) { + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); Iterator rows = cellSet.getRows().iterator(); @@ -207,6 +209,7 @@ public class TestScannerResource { // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); // confirm batch size conformance @@ -250,6 +253,7 @@ public class TestScannerResource { // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); // confirm batch size conformance @@ -292,6 +296,7 @@ public class TestScannerResource { // get a cell response = client.get(scannerURI, Constants.MIMETYPE_BINARY); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type")); // verify that data was returned assertTrue(response.getBody().length > 0); // verify that the expected X-headers are present diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java index 284c852c677..ed39b893ba5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java @@ -63,6 +63,7 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel; import org.apache.hadoop.hbase.util.Bytes; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -216,7 +217,7 @@ public class TestScannersWithFilters { marshaller.marshal(model, writer); LOG.debug(writer.toString()); byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + TABLE + "/scanner", + Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body); assertEquals(response.getCode(), 201); String scannerURI = response.getLocation(); @@ -225,6 +226,7 @@ public class TestScannersWithFilters { // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cells = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); @@ -250,7 +252,7 @@ public class TestScannersWithFilters { marshaller.marshal(model, writer); LOG.debug(writer.toString()); byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + TABLE + "/scanner", + Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body); assertEquals(response.getCode(), 201); String scannerURI = response.getLocation(); @@ -259,6 +261,7 @@ public class TestScannersWithFilters { // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); @@ -312,6 +315,7 @@ public class TestScannersWithFilters { // get a cell set response = client.get(scannerURI, Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java index e997b1ff727..a25cd2072f5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java @@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel; import org.apache.hadoop.hbase.util.Bytes; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -109,6 +110,7 @@ public class TestSchemaResource { // retrieve the schema and validate it response = client.get(schemaPath, Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); model = fromXML(response.getBody()); TestTableSchemaModel.checkModel(model, TABLE1); @@ -147,6 +149,15 @@ public class TestSchemaResource { // retrieve the schema and validate it response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); + model = new TableSchemaModel(); + model.getObjectFromMessage(response.getBody()); + TestTableSchemaModel.checkModel(model, TABLE2); + + // retrieve the schema and validate it with alternate pbuf type + response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF); + assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); model = new TableSchemaModel(); model.getObjectFromMessage(response.getBody()); TestTableSchemaModel.checkModel(model, TABLE2); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java index d3190d33428..96ef4a9ab5e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java @@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel; import org.apache.hadoop.hbase.util.Bytes; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -94,6 +95,7 @@ public class TestStatusResource { public void testGetClusterStatusXML() throws IOException, JAXBException { Response response = client.get("/status/cluster", Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); StorageClusterStatusModel model = (StorageClusterStatusModel) context.createUnmarshaller().unmarshal( new ByteArrayInputStream(response.getBody())); @@ -102,13 +104,17 @@ public class TestStatusResource { @Test public void testGetClusterStatusPB() throws IOException { - Response response = client.get("/status/cluster", - Constants.MIMETYPE_PROTOBUF); + Response response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); StorageClusterStatusModel model = new StorageClusterStatusModel(); model.getObjectFromMessage(response.getBody()); validate(model); + response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF_IETF); + assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); + model = new StorageClusterStatusModel(); + model.getObjectFromMessage(response.getBody()); + validate(model); } - } - diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java index b88142425c7..08f6233a17a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.util.StringUtils; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -178,12 +179,14 @@ public class TestTableResource { public void testTableListText() throws IOException { Response response = client.get("/", Constants.MIMETYPE_TEXT); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); } @Test public void testTableListXML() throws IOException, JAXBException { Response response = client.get("/", Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); TableListModel model = (TableListModel) context.createUnmarshaller() .unmarshal(new ByteArrayInputStream(response.getBody())); @@ -194,29 +197,37 @@ public class TestTableResource { public void testTableListJSON() throws IOException { Response response = client.get("/", Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); } @Test public void testTableListPB() throws IOException, JAXBException { Response response = client.get("/", Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); TableListModel model = new TableListModel(); model.getObjectFromMessage(response.getBody()); checkTableList(model); + response = client.get("/", Constants.MIMETYPE_PROTOBUF_IETF); + assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); + model = new TableListModel(); + model.getObjectFromMessage(response.getBody()); + checkTableList(model); } @Test public void testTableInfoText() throws IOException { - Response response = client.get("/" + TABLE + "/regions", - Constants.MIMETYPE_TEXT); + Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_TEXT); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); } @Test public void testTableInfoXML() throws IOException, JAXBException { - Response response = client.get("/" + TABLE + "/regions", - Constants.MIMETYPE_XML); + Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_XML); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); TableInfoModel model = (TableInfoModel) context.createUnmarshaller() .unmarshal(new ByteArrayInputStream(response.getBody())); @@ -225,19 +236,25 @@ public class TestTableResource { @Test public void testTableInfoJSON() throws IOException { - Response response = client.get("/" + TABLE + "/regions", - Constants.MIMETYPE_JSON); + Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); } @Test public void testTableInfoPB() throws IOException, JAXBException { - Response response = client.get("/" + TABLE + "/regions", - Constants.MIMETYPE_PROTOBUF); + Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF); assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); TableInfoModel model = new TableInfoModel(); model.getObjectFromMessage(response.getBody()); checkTableInfo(model); + response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF_IETF); + assertEquals(response.getCode(), 200); + assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); + model = new TableInfoModel(); + model.getObjectFromMessage(response.getBody()); + checkTableInfo(model); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java index 6289674612b..ef680841e98 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.rest.model.VersionModel; import org.apache.hadoop.hbase.util.Bytes; import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -96,6 +97,7 @@ public class TestVersionResource { public void testGetStargateVersionText() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_TEXT); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); String body = Bytes.toString(response.getBody()); assertTrue(body.length() > 0); assertTrue(body.contains(RESTServlet.VERSION_STRING)); @@ -113,6 +115,7 @@ public class TestVersionResource { public void testGetStargateVersionXML() throws IOException, JAXBException { Response response = client.get("/version", Constants.MIMETYPE_XML); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); VersionModel model = (VersionModel) context.createUnmarshaller().unmarshal( new ByteArrayInputStream(response.getBody())); @@ -124,23 +127,30 @@ public class TestVersionResource { public void testGetStargateVersionJSON() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_JSON); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); } @Test public void testGetStargateVersionPB() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); VersionModel model = new VersionModel(); model.getObjectFromMessage(response.getBody()); validate(model); - LOG.info("success retrieving Stargate version as protobuf"); + response = client.get("/version", Constants.MIMETYPE_PROTOBUF_IETF); + assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); + model = new VersionModel(); + model.getObjectFromMessage(response.getBody()); + validate(model); } @Test public void testGetStorageClusterVersionText() throws IOException { - Response response = client.get("/version/cluster", - Constants.MIMETYPE_TEXT); + Response response = client.get("/version/cluster", Constants.MIMETYPE_TEXT); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); } @Test @@ -148,6 +158,7 @@ public class TestVersionResource { JAXBException { Response response = client.get("/version/cluster",Constants.MIMETYPE_XML); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); StorageClusterVersionModel clusterVersionModel = (StorageClusterVersionModel) context.createUnmarshaller().unmarshal( @@ -161,6 +172,7 @@ public class TestVersionResource { public void doTestGetStorageClusterVersionJSON() throws IOException { Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON); assertTrue(response.getCode() == 200); + assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); } }