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