use of org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException in project hbase by apache.
the class SchemaResource method update.
private Response update(final TableSchemaModel model, final boolean replace, final UriInfo uriInfo) {
try {
TableName name = TableName.valueOf(tableResource.getName());
Admin admin = servlet.getAdmin();
if (replace || !admin.tableExists(name)) {
return replace(name, model, uriInfo, admin);
} else {
return update(name, model, uriInfo, admin);
}
} catch (Exception e) {
servlet.getMetrics().incrementFailedPutRequests(1);
// Avoid re-unwrapping the exception
if (e instanceof WebApplicationException) {
throw (WebApplicationException) e;
}
return processException(e);
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException in project hbase by apache.
the class ProtobufMessageBodyConsumer method readFrom.
@Override
public ProtobufMessageHandler readFrom(Class<ProtobufMessageHandler> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException, WebApplicationException {
ProtobufMessageHandler obj = null;
try {
obj = type.getDeclaredConstructor().newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int read;
do {
read = inputStream.read(buffer, 0, buffer.length);
if (read > 0) {
baos.write(buffer, 0, read);
}
} while (read > 0);
if (LOG.isTraceEnabled()) {
LOG.trace(getClass() + ": read " + baos.size() + " bytes from " + inputStream);
}
obj = obj.getObjectFromMessage(baos.toByteArray());
} catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new WebApplicationException(e);
}
return obj;
}
use of org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException in project hbase by apache.
the class ResourceBase method processException.
protected Response processException(Throwable exp) {
Throwable curr = exp;
if (accessDeniedClazz != null) {
// some access denied exceptions are buried
while (curr != null) {
if (accessDeniedClazz.isAssignableFrom(curr.getClass())) {
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
curr = curr.getCause();
}
}
// TableNotFound may also be buried one level deep
if (exp instanceof TableNotFoundException || exp.getCause() instanceof TableNotFoundException) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
if (exp instanceof NoSuchColumnFamilyException) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
if (exp instanceof RuntimeException) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
if (exp instanceof RetriesExhaustedException) {
RetriesExhaustedException retryException = (RetriesExhaustedException) exp;
processException(retryException.getCause());
}
throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
Aggregations