HBASE-7464. [REST] Sending HTML for errors is unhelpful
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1427567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bca9450cf2
commit
74a23195f8
|
@ -40,4 +40,6 @@ public interface Constants {
|
|||
public static final String MIMETYPE_BINARY = "application/octet-stream";
|
||||
public static final String MIMETYPE_PROTOBUF = "application/x-protobuf";
|
||||
public static final String MIMETYPE_JSON = "application/json";
|
||||
|
||||
public static final String CRLF = "\r\n";
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -60,10 +59,14 @@ public class ExistsResource extends ResourceBase {
|
|||
public Response get(final @Context UriInfo uriInfo) {
|
||||
try {
|
||||
if (!tableResource.exists()) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
ResponseBuilder response = Response.ok();
|
||||
response.cacheControl(cacheControl);
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -75,9 +74,12 @@ public class MultiRowResource extends ResourceBase {
|
|||
rowSpec.setMaxVersions(this.versions);
|
||||
}
|
||||
|
||||
ResultGenerator generator = ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null);
|
||||
ResultGenerator generator =
|
||||
ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null);
|
||||
if (!generator.hasNext()) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
KeyValue value = null;
|
||||
|
@ -94,8 +96,9 @@ public class MultiRowResource extends ResourceBase {
|
|||
return Response.ok(model).build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -91,11 +90,14 @@ public class RegionsResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (TableNotFoundException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -83,8 +82,9 @@ public class RootResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -41,6 +40,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.KeyValue;
|
||||
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||
import org.apache.hadoop.hbase.client.Delete;
|
||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.HTablePool;
|
||||
|
@ -90,7 +90,9 @@ public class RowResource extends ResourceBase {
|
|||
ResultGenerator generator =
|
||||
ResultGenerator.fromRowSpec(tableResource.getName(), rowspec, null);
|
||||
if (!generator.hasNext()) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
int count = 0;
|
||||
CellSetModel model = new CellSetModel();
|
||||
|
@ -113,10 +115,21 @@ public class RowResource extends ResourceBase {
|
|||
model.addRow(rowModel);
|
||||
servlet.getMetrics().incrementSucessfulGetRequests(1);
|
||||
return Response.ok(model).build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
} catch (RuntimeException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
if (e.getCause() instanceof TableNotFoundException) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,13 +143,17 @@ public class RowResource extends ResourceBase {
|
|||
// doesn't make sense to use a non specific coordinate as this can only
|
||||
// return a single cell
|
||||
if (!rowspec.hasColumns() || rowspec.getColumns().length > 1) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
try {
|
||||
ResultGenerator generator =
|
||||
ResultGenerator.fromRowSpec(tableResource.getName(), rowspec, null);
|
||||
if (!generator.hasNext()) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
KeyValue value = generator.next();
|
||||
ResponseBuilder response = Response.ok(value.getValue());
|
||||
|
@ -145,15 +162,18 @@ public class RowResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Response update(final CellSetModel model, final boolean replace) {
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
if (CHECK_PUT.equalsIgnoreCase(check)) {
|
||||
|
@ -175,7 +195,9 @@ public class RowResource extends ResourceBase {
|
|||
key = rowspec.getRow();
|
||||
}
|
||||
if (key == null) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
Put put = new Put(key);
|
||||
int i = 0;
|
||||
|
@ -187,7 +209,9 @@ public class RowResource extends ResourceBase {
|
|||
col = null;
|
||||
}
|
||||
if (col == null) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
byte [][] parts = KeyValue.parseColumn(col);
|
||||
if (parts.length == 2 && parts[1].length > 0) {
|
||||
|
@ -209,8 +233,9 @@ public class RowResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
if (table != null) try {
|
||||
table.close();
|
||||
|
@ -223,7 +248,9 @@ public class RowResource extends ResourceBase {
|
|||
final boolean replace) {
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
HTablePool pool = servlet.getTablePool();
|
||||
HTableInterface table = null;
|
||||
|
@ -248,7 +275,9 @@ public class RowResource extends ResourceBase {
|
|||
timestamp = Long.valueOf(vals.get(0));
|
||||
}
|
||||
if (column == null) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
Put put = new Put(row);
|
||||
byte parts[][] = KeyValue.parseColumn(column);
|
||||
|
@ -266,8 +295,9 @@ public class RowResource extends ResourceBase {
|
|||
return Response.ok().build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
if (table != null) try {
|
||||
table.close();
|
||||
|
@ -324,7 +354,9 @@ public class RowResource extends ResourceBase {
|
|||
}
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
Delete delete = null;
|
||||
if (rowspec.hasTimestamp())
|
||||
|
@ -359,8 +391,9 @@ public class RowResource extends ResourceBase {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
if (table != null) try {
|
||||
table.close();
|
||||
|
@ -381,7 +414,9 @@ public class RowResource extends ResourceBase {
|
|||
HTableInterface table = null;
|
||||
try {
|
||||
if (model.getRows().size() != 1) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
RowModel rowModel = model.getRows().get(0);
|
||||
|
@ -393,7 +428,9 @@ public class RowResource extends ResourceBase {
|
|||
List<CellModel> cellModels = rowModel.getCells();
|
||||
int cellModelCount = cellModels.size();
|
||||
if (key == null || cellModelCount <= 1) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
Put put = new Put(key);
|
||||
|
@ -413,10 +450,14 @@ public class RowResource extends ResourceBase {
|
|||
put.add(valueToPutParts[0], valueToPutParts[1], valueToPutCell
|
||||
.getTimestamp(), valueToPutCell.getValue());
|
||||
} else {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
} else {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
table = pool.getTable(this.tableResource.getName());
|
||||
|
@ -432,7 +473,9 @@ public class RowResource extends ResourceBase {
|
|||
}
|
||||
return response.build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e, Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
if (table != null) try {
|
||||
table.close();
|
||||
|
@ -453,7 +496,9 @@ public class RowResource extends ResourceBase {
|
|||
Delete delete = null;
|
||||
try {
|
||||
if (model.getRows().size() != 1) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
RowModel rowModel = model.getRows().get(0);
|
||||
byte[] key = rowModel.getKey();
|
||||
|
@ -461,7 +506,9 @@ public class RowResource extends ResourceBase {
|
|||
key = rowspec.getRow();
|
||||
}
|
||||
if (key == null) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
delete = new Delete(key);
|
||||
|
@ -471,14 +518,18 @@ public class RowResource extends ResourceBase {
|
|||
try {
|
||||
valueToDeleteColumn = rowspec.getColumns()[0];
|
||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
byte[][] parts = KeyValue.parseColumn(valueToDeleteColumn);
|
||||
if (parts.length == 2 && parts[1].length > 0) {
|
||||
delete.deleteColumns(parts[0], parts[1]);
|
||||
} else {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
}
|
||||
|
||||
table = pool.getTable(tableResource.getName());
|
||||
|
@ -495,7 +546,9 @@ public class RowResource extends ResourceBase {
|
|||
}
|
||||
return response.build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e, Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
if (table != null) try {
|
||||
table.close();
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.ws.rs.DELETE;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -55,10 +54,12 @@ public class ScannerInstanceResource extends ResourceBase {
|
|||
cacheControl.setNoTransform(false);
|
||||
}
|
||||
|
||||
ResultGenerator generator;
|
||||
String id;
|
||||
ResultGenerator generator = null;
|
||||
String id = null;
|
||||
int batch = 1;
|
||||
|
||||
public ScannerInstanceResource() throws IOException { }
|
||||
|
||||
public ScannerInstanceResource(String table, String id,
|
||||
ResultGenerator generator, int batch) throws IOException {
|
||||
this.id = id;
|
||||
|
@ -74,6 +75,12 @@ public class ScannerInstanceResource extends ResourceBase {
|
|||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (generator == null) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
CellSetModel model = new CellSetModel();
|
||||
RowModel rowModel = null;
|
||||
byte[] rowKey = null;
|
||||
|
@ -93,7 +100,9 @@ public class ScannerInstanceResource extends ResourceBase {
|
|||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||
}
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(Response.Status.GONE);
|
||||
return Response.status(Response.Status.GONE)
|
||||
.type(MIMETYPE_TEXT).entity("Gone" + CRLF)
|
||||
.build();
|
||||
}
|
||||
if (value == null) {
|
||||
LOG.info("generator exhausted");
|
||||
|
@ -162,7 +171,9 @@ public class ScannerInstanceResource extends ResourceBase {
|
|||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||
}
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(Response.Status.GONE);
|
||||
return Response.status(Response.Status.GONE)
|
||||
.type(MIMETYPE_TEXT).entity("Gone" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +184,9 @@ public class ScannerInstanceResource extends ResourceBase {
|
|||
}
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
if (ScannerResource.delete(id)) {
|
||||
servlet.getMetrics().incrementSucessfulDeleteRequests(1);
|
||||
|
|
|
@ -30,7 +30,6 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
@ -78,7 +77,9 @@ public class ScannerResource extends ResourceBase {
|
|||
final UriInfo uriInfo) {
|
||||
servlet.getMetrics().incrementRequests(1);
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
|
||||
RowSpec spec = new RowSpec(model.getStartRow(), endRow,
|
||||
|
@ -100,19 +101,21 @@ public class ScannerResource extends ResourceBase {
|
|||
URI uri = builder.path(id).build();
|
||||
servlet.getMetrics().incrementSucessfulPutRequests(1);
|
||||
return Response.created(uri).build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
} catch (RuntimeException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
if (e.getCause() instanceof TableNotFoundException) {
|
||||
throw new WebApplicationException(e, Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
}
|
||||
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,11 +141,11 @@ public class ScannerResource extends ResourceBase {
|
|||
|
||||
@Path("{scanner: .+}")
|
||||
public ScannerInstanceResource getScannerInstanceResource(
|
||||
final @PathParam("scanner") String id) {
|
||||
final @PathParam("scanner") String id) throws IOException {
|
||||
ScannerInstanceResource instance = scanners.get(id);
|
||||
if (instance == null) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return new ScannerInstanceResource();
|
||||
} else {
|
||||
servlet.getMetrics().incrementSucessfulGetRequests(1);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -101,18 +100,23 @@ public class SchemaResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (TableNotFoundException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
private Response replace(final byte[] name, final TableSchemaModel model,
|
||||
final UriInfo uriInfo, final HBaseAdmin admin) {
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
try {
|
||||
HTableDescriptor htd = new HTableDescriptor(name);
|
||||
|
@ -136,19 +140,24 @@ public class SchemaResource extends ResourceBase {
|
|||
servlet.getMetrics().incrementSucessfulPutRequests(1);
|
||||
} catch (TableExistsException e) {
|
||||
// race, someone else created a table with the same name
|
||||
throw new WebApplicationException(e, Response.Status.NOT_MODIFIED);
|
||||
return Response.status(Response.Status.NOT_MODIFIED)
|
||||
.type(MIMETYPE_TEXT).entity("Not modified" + CRLF)
|
||||
.build();
|
||||
}
|
||||
return Response.created(uriInfo.getAbsolutePath()).build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
private Response update(final byte[] name, final TableSchemaModel model,
|
||||
final UriInfo uriInfo, final HBaseAdmin admin) {
|
||||
if (servlet.isReadOnly()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
return Response.status(Response.Status.FORBIDDEN)
|
||||
.type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
|
||||
.build();
|
||||
}
|
||||
try {
|
||||
HTableDescriptor htd = admin.getTableDescriptor(name);
|
||||
|
@ -166,16 +175,18 @@ public class SchemaResource extends ResourceBase {
|
|||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.INTERNAL_SERVER_ERROR);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
} finally {
|
||||
admin.enableTable(tableResource.getName());
|
||||
}
|
||||
servlet.getMetrics().incrementSucessfulPutRequests(1);
|
||||
return Response.ok().build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,8 +202,9 @@ public class SchemaResource extends ResourceBase {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,11 +253,14 @@ public class SchemaResource extends ResourceBase {
|
|||
return Response.ok().build();
|
||||
} catch (TableNotFoundException e) {
|
||||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
|
||||
.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -101,8 +100,9 @@ public class StorageClusterStatusResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -72,8 +71,9 @@ public class StorageClusterVersionResource extends ResourceBase {
|
|||
return response.build();
|
||||
} catch (IOException e) {
|
||||
servlet.getMetrics().incrementFailedGetRequests(1);
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue