You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2018/08/22 23:08:04 UTC
[2/4] hbase git commit: HBASE-20614 REST scan API with incorrect
filter text file throws HTTP 503 Service Unavailable error
HBASE-20614 REST scan API with incorrect filter text file throws HTTP 503 Service Unavailable error
Signed-off-by: Andrew Purtell <ap...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/343a0f67
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/343a0f67
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/343a0f67
Branch: refs/heads/branch-2.0
Commit: 343a0f675a75c2cb37463648e45bd5b04fbeeb73
Parents: 23556fb
Author: Nihal Jain <ni...@gmail.com>
Authored: Wed May 30 18:09:41 2018 +0530
Committer: Andrew Purtell <ap...@apache.org>
Committed: Wed Aug 22 16:07:57 2018 -0700
----------------------------------------------------------------------
.../hadoop/hbase/rest/ScannerResource.java | 8 ++++-
.../hbase/rest/model/TestScannerModel.java | 34 ++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/343a0f67/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
index d2b173f..9de033d 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java
@@ -38,6 +38,10 @@ import javax.ws.rs.core.UriInfo;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.rest.model.ScannerModel;
@@ -108,12 +112,14 @@ public class ScannerResource extends ResourceBase {
servlet.getMetrics().incrementSucessfulPutRequests(1);
return Response.created(uri).build();
} catch (Exception e) {
+ LOG.error("Exception occured while processing " + uriInfo.getAbsolutePath() + " : ", e);
servlet.getMetrics().incrementFailedPutRequests(1);
if (e instanceof TableNotFoundException) {
return Response.status(Response.Status.NOT_FOUND)
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
.build();
- } else if (e instanceof RuntimeException) {
+ } else if (e instanceof RuntimeException
+ || e instanceof JsonMappingException | e instanceof JsonParseException) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
http://git-wip-us.apache.org/repos/asf/hbase/blob/343a0f67/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestScannerModel.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestScannerModel.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestScannerModel.java
index 85c5588..fc9d8d1 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestScannerModel.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/model/TestScannerModel.java
@@ -21,12 +21,17 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.rest.ScannerResultGenerator;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
@Category({RestTests.class, SmallTests.class})
public class TestScannerModel extends TestModelBase<ScannerModel> {
@@ -117,4 +122,33 @@ public class TestScannerModel extends TestModelBase<ScannerModel> {
}
}
+ @Test
+ public void testExistingFilter() throws Exception {
+ final String CORRECT_FILTER = "{\"type\": \"PrefixFilter\", \"value\": \"cg==\"}";
+ verifyException(CORRECT_FILTER);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testNonExistingFilter() throws Exception {
+ final String UNKNOWN_FILTER = "{\"type\": \"UnknownFilter\", \"value\": \"cg==\"}";
+ verifyException(UNKNOWN_FILTER);
+ }
+
+ @Test(expected = JsonMappingException.class)
+ public void testIncorrectFilterThrowsJME() throws Exception {
+ final String JME_FILTER = "{\"invalid_tag\": \"PrefixFilter\", \"value\": \"cg==\"}";
+ verifyException(JME_FILTER);
+ }
+
+ @Test(expected = JsonParseException.class)
+ public void tesIncorrecttFilterThrowsJPE() throws Exception {
+ final String JPE_FILTER = "{\"type\": \"PrefixFilter\",, \"value\": \"cg==\"}";
+ verifyException(JPE_FILTER);
+ }
+
+ private void verifyException(final String FILTER) throws Exception {
+ ScannerModel model = new ScannerModel();
+ model.setFilter(FILTER);
+ ScannerResultGenerator.buildFilterFromModel(model);
+ }
}