Search in sources :

Example 1 with WebApplicationException

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);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) Admin(org.apache.hadoop.hbase.client.Admin) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) IOException(java.io.IOException)

Example 2 with WebApplicationException

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;
}
Also used : ProtobufMessageHandler(org.apache.hadoop.hbase.rest.ProtobufMessageHandler) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with WebApplicationException

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());
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)

Aggregations

WebApplicationException (org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TableExistsException (org.apache.hadoop.hbase.TableExistsException)1 TableName (org.apache.hadoop.hbase.TableName)1 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)1 Admin (org.apache.hadoop.hbase.client.Admin)1 RetriesExhaustedException (org.apache.hadoop.hbase.client.RetriesExhaustedException)1 NoSuchColumnFamilyException (org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)1 ProtobufMessageHandler (org.apache.hadoop.hbase.rest.ProtobufMessageHandler)1