From 4b21f2e32be91888355450ca0d19cf1b37ccc93b Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Sat, 23 Jul 2011 19:04:08 +0000 Subject: [PATCH] HBASE-4105 Stargate does not support json and gzip in parallel git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1150190 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../rest/filter/GZIPResponseWrapper.java | 27 ++++++++++--------- .../hadoop/hbase/rest/TestGzipFilter.java | 17 ++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 26efdc6f1eb..281036f952e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -169,6 +169,8 @@ Release 0.91.0 - Unreleased HBASE-4118 method regionserver.MemStore#updateColumnValue: the check for qualifier and family is missing (N Keywal via Ted Yu) HBASE-4127 Don't modify table's name away in HBaseAdmin + HBASE-4105 Stargate does not support Content-Type: application/json and + Content-Encoding: gzip in parallel IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/rest/filter/GZIPResponseWrapper.java b/src/main/java/org/apache/hadoop/hbase/rest/filter/GZIPResponseWrapper.java index 84184e91709..08a976b32fd 100644 --- a/src/main/java/org/apache/hadoop/hbase/rest/filter/GZIPResponseWrapper.java +++ b/src/main/java/org/apache/hadoop/hbase/rest/filter/GZIPResponseWrapper.java @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponseWrapper; public class GZIPResponseWrapper extends HttpServletResponseWrapper { private HttpServletResponse response; - private GZIPResponseStream os; + private ServletOutputStream os; private PrintWriter writer; private boolean compress = true; @@ -40,6 +40,7 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper { @Override public void setStatus(int status) { + super.setStatus(status); if (status < 200 || status >= 300) { compress = false; } @@ -76,8 +77,8 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper { if (writer != null) { writer.flush(); } - if (os != null) { - os.finish(); + if (os != null && (os instanceof GZIPResponseStream)) { + ((GZIPResponseStream)os).finish(); } else { getResponse().flushBuffer(); } @@ -86,8 +87,8 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper { @Override public void reset() { super.reset(); - if (os != null) { - os.resetBuffer(); + if (os != null && (os instanceof GZIPResponseStream)) { + ((GZIPResponseStream)os).resetBuffer(); } writer = null; os = null; @@ -97,8 +98,8 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper { @Override public void resetBuffer() { super.resetBuffer(); - if (os != null) { - os.resetBuffer(); + if (os != null && (os instanceof GZIPResponseStream)) { + ((GZIPResponseStream)os).resetBuffer(); } writer = null; os = null; @@ -124,14 +125,14 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper { @Override public ServletOutputStream getOutputStream() throws IOException { - if (!response.isCommitted() && compress) { - if (os == null) { - os = new GZIPResponseStream(response); + if (os == null) { + if (!response.isCommitted() && compress) { + os = (ServletOutputStream)new GZIPResponseStream(response); + } else { + os = response.getOutputStream(); } - return os; - } else { - return response.getOutputStream(); } + return os; } @Override diff --git a/src/test/java/org/apache/hadoop/hbase/rest/TestGzipFilter.java b/src/test/java/org/apache/hadoop/hbase/rest/TestGzipFilter.java index 18300c4eae1..cd9d3e30481 100644 --- a/src/test/java/org/apache/hadoop/hbase/rest/TestGzipFilter.java +++ b/src/test/java/org/apache/hadoop/hbase/rest/TestGzipFilter.java @@ -132,4 +132,21 @@ public class TestGzipFilter { contentEncoding = response.getHeader("Content-Encoding"); assertTrue(contentEncoding == null || !contentEncoding.contains("gzip")); } + + @Test + public void testScannerResultCodes() throws Exception { + Header[] headers = new Header[3]; + headers[0] = new Header("Content-Type", Constants.MIMETYPE_XML); + headers[1] = new Header("Accept", Constants.MIMETYPE_JSON); + headers[2] = new Header("Accept-Encoding", "gzip"); + Response response = client.post("/" + TABLE + "/scanner", headers, + "".getBytes()); + assertEquals(response.getCode(), 201); + String scannerUrl = response.getLocation(); + assertNotNull(scannerUrl); + response = client.get(scannerUrl); + assertEquals(response.getCode(), 200); + response = client.get(scannerUrl); + assertEquals(response.getCode(), 204); + } } \ No newline at end of file