use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class JsonProcessingExceptionMapperTest method returnsA500ForNonSerializableRepresentationClassesOutbound.
@Test
public void returnsA500ForNonSerializableRepresentationClassesOutbound() throws Exception {
Response response = target("/json/brokenOutbound").request(MediaType.APPLICATION_JSON).get();
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
}
use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class JsonProcessingExceptionMapperTest method returnsA500ForListNonDeserializableRepresentationClasses.
@Test
public void returnsA500ForListNonDeserializableRepresentationClasses() throws Exception {
final ImmutableList<BrokenRepresentation> ent = ImmutableList.of(new BrokenRepresentation(ImmutableList.of()), new BrokenRepresentation(ImmutableList.of("whoo")));
Response response = target("/json/brokenList").request(MediaType.APPLICATION_JSON).post(Entity.entity(ent, MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
}
use of javax.ws.rs.core.Response in project dropwizard by dropwizard.
the class JsonProcessingExceptionMapperTest method returnsA500ForNonDeserializableRepresentationClasses.
@Test
public void returnsA500ForNonDeserializableRepresentationClasses() throws Exception {
Response response = target("/json/broken").request(MediaType.APPLICATION_JSON).post(Entity.entity(new BrokenRepresentation(ImmutableList.of("whee")), MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
}
use of javax.ws.rs.core.Response in project druid by druid-io.
the class NamespaceLookupExtractorFactoryTest method validateNotFound.
private void validateNotFound(String method, LookupIntrospectHandler handler, Class<? extends LookupIntrospectHandler> clazz) throws Exception {
mockVerify();
mockReset();
expectEntryGetCacheStateOnce(versionedCache);
expectEmptyCache();
EasyMock.expect(versionedCache.getVersion()).andThrow(new ISE("some exception")).once();
mockReplay();
final Response response = (Response) clazz.getMethod(method).invoke(handler);
Assert.assertEquals(404, response.getStatus());
}
use of javax.ws.rs.core.Response in project druid by druid-io.
the class OverlordResource method taskPost.
@POST
@Path("/task")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response taskPost(final Task task, @Context final HttpServletRequest req) {
if (authConfig.isEnabled()) {
// This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
final String dataSource = task.getDataSource();
final AuthorizationInfo authorizationInfo = (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
Access authResult = authorizationInfo.isAuthorized(new Resource(dataSource, ResourceType.DATASOURCE), Action.WRITE);
if (!authResult.isAllowed()) {
return Response.status(Response.Status.FORBIDDEN).header("Access-Check-Result", authResult).build();
}
}
return asLeaderWith(taskMaster.getTaskQueue(), new Function<TaskQueue, Response>() {
@Override
public Response apply(TaskQueue taskQueue) {
try {
taskQueue.add(task);
return Response.ok(ImmutableMap.of("task", task.getId())).build();
} catch (EntryExistsException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ImmutableMap.of("error", String.format("Task[%s] already exists!", task.getId()))).build();
}
}
});
}
Aggregations