Search in sources :

Example 96 with Response

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);
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 97 with Response

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);
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 98 with Response

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);
}
Also used : Response(javax.ws.rs.core.Response) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 99 with Response

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());
}
Also used : Response(javax.ws.rs.core.Response) ISE(io.druid.java.util.common.ISE)

Example 100 with Response

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();
            }
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) TaskQueue(io.druid.indexing.overlord.TaskQueue) EntryExistsException(io.druid.metadata.EntryExistsException) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Response (javax.ws.rs.core.Response)3808 Test (org.junit.Test)2883 JerseyTest (org.glassfish.jersey.test.JerseyTest)849 Test (org.testng.annotations.Test)342 Builder (javax.ws.rs.client.Invocation.Builder)298 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)287 WebTarget (javax.ws.rs.client.WebTarget)278 BaseTest (org.xdi.oxauth.BaseTest)274 Parameters (org.testng.annotations.Parameters)271 DBUnitTest (org.orcid.test.DBUnitTest)270 JSONException (org.codehaus.jettison.json.JSONException)253 URI (java.net.URI)230 JSONObject (org.codehaus.jettison.json.JSONObject)181 Path (javax.ws.rs.Path)153 Matchers.containsString (org.hamcrest.Matchers.containsString)142 URISyntaxException (java.net.URISyntaxException)124 ResponseType (org.xdi.oxauth.model.common.ResponseType)120 Produces (javax.ws.rs.Produces)113 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)105 GET (javax.ws.rs.GET)104