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
This commit is contained in:
Andrew Kyle Purtell 2010-10-06 22:28:58 +00:00
parent b2bff276ab
commit a6afa7b49f
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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();
}
}