From a6afa7b49f3c8a1ede0d715d35a7cba2988cd000 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Wed, 6 Oct 2010 22:28:58 +0000 Subject: [PATCH] HBASE-2907 [rest/stargate] Improve error response when trying to create a scanner on a nonexistant table git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1005279 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/hadoop/hbase/rest/ScannerResource.java | 6 ++++++ .../hadoop/hbase/rest/TestScannerResource.java | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 75bd335f9d7..4013218b65a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -976,6 +976,8 @@ Release 0.21.0 - Unreleased HBASE-3070 Add to hbaseadmin means of shutting down a regionserver HBASE-2996 Fix and clean up Maven (Lars Francke via Stack) HBASE-2917 Reseek directly to next row (Pranav Khaitan) + HBASE-2907 [rest/stargate] Improve error response when trying to create a + scanner on a nonexistant table NEW FEATURES HBASE-1961 HBase EC2 scripts diff --git a/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java b/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java index 6ee7230c90d..5bb90ef6419 100644 --- a/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java +++ b/src/main/java/org/apache/hadoop/hbase/rest/ScannerResource.java @@ -40,6 +40,7 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.rest.model.ScannerModel; @@ -92,6 +93,11 @@ public class ScannerResource extends ResourceBase { } catch (IOException e) { throw new WebApplicationException(e, Response.Status.SERVICE_UNAVAILABLE); + } catch (RuntimeException e) { + if (e.getCause() instanceof TableNotFoundException) { + throw new WebApplicationException(e, Response.Status.NOT_FOUND); + } + throw new WebApplicationException(e, Response.Status.BAD_REQUEST); } catch (Exception e) { throw new WebApplicationException(e, Response.Status.BAD_REQUEST); } diff --git a/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java b/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java index bc9fb8b7d06..4c6a9d6f95e 100644 --- a/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java +++ b/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java @@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.util.Bytes; public class TestScannerResource extends HBaseRESTClusterTestBase { static final String TABLE = "TestScannerResource"; + static final String NONEXISTENT_TABLE = "ThisTableDoesNotExist"; static final String CFA = "a"; static final String CFB = "b"; static final String COLUMN_1 = CFA + ":1"; @@ -265,10 +266,21 @@ public class TestScannerResource extends HBaseRESTClusterTestBase { assertEquals(fullTableScan(model), expectedRows2); } + void doTestTableDoesNotExist() throws IOException, JAXBException { + ScannerModel model = new ScannerModel(); + StringWriter writer = new StringWriter(); + marshaller.marshal(model, writer); + byte[] body = Bytes.toBytes(writer.toString()); + Response response = client.put("/" + NONEXISTENT_TABLE + + "/scanner", MIMETYPE_XML, body); + assertEquals(response.getCode(), 404); + } + public void testScannerResource() throws Exception { doTestSimpleScannerXML(); doTestSimpleScannerPB(); doTestSimpleScannerBinary(); doTestFullTableScan(); + doTestTableDoesNotExist(); } }