Search in sources :

Example 6 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project hadoop by apache.

the class TestHsWebServicesAcls method testGetJobTaskAttemptIdCountersAcls.

@Test
public void testGetJobTaskAttemptIdCountersAcls() {
    HttpServletRequest hsr = mock(HttpServletRequest.class);
    when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);
    try {
        hsWebServices.getJobTaskAttemptIdCounters(hsr, this.jobIdStr, this.taskIdStr, this.taskAttemptIdStr);
        fail("enemy can access job");
    } catch (WebApplicationException e) {
        assertEquals(Status.UNAUTHORIZED, Status.fromStatusCode(e.getResponse().getStatus()));
    }
    when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
    hsWebServices.getJobTaskAttemptIdCounters(hsr, this.jobIdStr, this.taskIdStr, this.taskAttemptIdStr);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 7 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project hadoop by apache.

the class TimelineReaderWebServices method handleException.

private static void handleException(Exception e, String url, long startTime, String invalidNumMsg) throws BadRequestException, WebApplicationException {
    long endTime = Time.monotonicNow();
    LOG.info("Processed URL " + url + " but encountered exception (Took " + (endTime - startTime) + " ms.)");
    if (e instanceof NumberFormatException) {
        throw new BadRequestException(invalidNumMsg + " is not a numeric value.");
    } else if (e instanceof IllegalArgumentException) {
        throw new BadRequestException(e.getMessage() == null ? "Requested Invalid Field." : e.getMessage());
    } else if (e instanceof NotFoundException) {
        throw (NotFoundException) e;
    } else if (e instanceof TimelineParseException) {
        throw new BadRequestException(e.getMessage() == null ? "Filter Parsing failed." : e.getMessage());
    } else if (e instanceof BadRequestException) {
        throw (BadRequestException) e;
    } else {
        LOG.error("Error while processing REST request", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException)

Example 8 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project zookeeper by apache.

the class ZNodeResource method deleteZNode.

@DELETE
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @Context UriInfo ui) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    zk.delete(path, version);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 9 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project zookeeper by apache.

the class ZNodeResource method setZNodeAsOctet.

@PUT
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void setZNodeAsOctet(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    if (setNull.equals("true")) {
        data = null;
    }
    zk.setData(path, data, version);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 10 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project druid by druid-io.

the class ConfigResourceFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    if (getAuthConfig().isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String resourceName = "CONFIG";
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        final Access authResult = authorizationInfo.isAuthorized(new Resource(resourceName, ResourceType.CONFIG), getAction(request));
        if (!authResult.isAllowed()) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
        }
    }
    return request;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) AuthorizationInfo(io.druid.server.security.AuthorizationInfo)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)276 Produces (javax.ws.rs.Produces)77 GET (javax.ws.rs.GET)71 Path (javax.ws.rs.Path)69 IOException (java.io.IOException)47 POST (javax.ws.rs.POST)47 Consumes (javax.ws.rs.Consumes)44 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)43 Response (javax.ws.rs.core.Response)30 MediaType (javax.ws.rs.core.MediaType)26 URI (java.net.URI)25 HashMap (java.util.HashMap)20 JSONObject (org.codehaus.jettison.json.JSONObject)20 Test (org.junit.Test)19 JSONException (org.codehaus.jettison.json.JSONException)18 ApiOperation (io.swagger.annotations.ApiOperation)17 ArrayList (java.util.ArrayList)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)15 List (java.util.List)14