use of javax.ws.rs.NotFoundException in project metrics by dropwizard.
the class SingletonMetricsJerseyTest method testResourceNotFound.
@Test
public void testResourceNotFound() {
final Response response = target().path("not-found").request().get();
assertThat(response.getStatus()).isEqualTo(404);
try {
target().path("not-found").request().get(ClientResponse.class);
failBecauseExceptionWasNotThrown(NotFoundException.class);
} catch (NotFoundException e) {
assertThat(e.getMessage()).isEqualTo("HTTP 404 Not Found");
}
}
use of javax.ws.rs.NotFoundException in project jersey by jersey.
the class JerseyInvocation method convertToException.
private ProcessingException convertToException(final Response response) {
try {
// Buffer and close entity input stream (if any) to prevent
// leaking connections (see JERSEY-2157).
response.bufferEntity();
final WebApplicationException webAppException;
final int statusCode = response.getStatus();
final Response.Status status = Response.Status.fromStatusCode(statusCode);
if (status == null) {
final Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
webAppException = createExceptionForFamily(response, statusFamily);
} else {
switch(status) {
case BAD_REQUEST:
webAppException = new BadRequestException(response);
break;
case UNAUTHORIZED:
webAppException = new NotAuthorizedException(response);
break;
case FORBIDDEN:
webAppException = new ForbiddenException(response);
break;
case NOT_FOUND:
webAppException = new NotFoundException(response);
break;
case METHOD_NOT_ALLOWED:
webAppException = new NotAllowedException(response);
break;
case NOT_ACCEPTABLE:
webAppException = new NotAcceptableException(response);
break;
case UNSUPPORTED_MEDIA_TYPE:
webAppException = new NotSupportedException(response);
break;
case INTERNAL_SERVER_ERROR:
webAppException = new InternalServerErrorException(response);
break;
case SERVICE_UNAVAILABLE:
webAppException = new ServiceUnavailableException(response);
break;
default:
final Response.Status.Family statusFamily = response.getStatusInfo().getFamily();
webAppException = createExceptionForFamily(response, statusFamily);
}
}
return new ResponseProcessingException(response, webAppException);
} catch (final Throwable t) {
return new ResponseProcessingException(response, LocalizationMessages.RESPONSE_TO_EXCEPTION_CONVERSION_FAILED(), t);
}
}
use of javax.ws.rs.NotFoundException in project jersey by jersey.
the class CombinedFeedResource method notFoundException.
private NotFoundException notFoundException(String feedId) {
String message = "No Combined Feed was found with ID: " + feedId;
Response response = Response.status(NOT_FOUND).entity(new ValidationError(message, null, null, feedId)).build();
return new NotFoundException(message, response);
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class GroupResource method deleteGroup.
/**
* Delete a group
*
* @excludeParams automationClient
* @param name Group name to delete
*
* @responseMessage 204 Group deleted
* @responseMessage 404 Group not found
*/
@Timed
@ExceptionMetered
@DELETE
@Path("{name}")
public Response deleteGroup(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Group group = groupDAOReadWrite.getGroup(name).orElseThrow(NotFoundException::new);
// Group memberships are deleted automatically by DB cascading.
groupDAOReadWrite.deleteGroup(group);
auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_DELETE, automationClient.getName(), group.getName()));
return Response.noContent().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationEnrollClientGroupResource method enrollClientInGroup.
/**
* Enroll Client in Group
*
* @param clientId the ID of the Client to assign
* @param groupId the ID of the Group to be assigned to
* @excludeParams automationClient
* @description Assigns the Client specified by the clientID to the Group specified by the
* groupID
* @responseMessage 200 Successfully enrolled Client in Group
* @responseMessage 404 Could not find Client or Group
*/
@Timed
@ExceptionMetered
@PUT
public Response enrollClientInGroup(@Auth AutomationClient automationClient, @PathParam("clientId") LongParam clientId, @PathParam("groupId") LongParam groupId) {
try {
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
aclDAO.findAndEnrollClient(clientId.get(), groupId.get(), auditLog, automationClient.getName(), extraInfo);
} catch (IllegalStateException e) {
throw new NotFoundException();
}
return Response.ok().build();
}
Aggregations