Search in sources :

Example 1 with ContainerResponseContext

use of javax.ws.rs.container.ContainerResponseContext in project jersey by jersey.

the class ApplicationFilterTest method testSingleResponseFilter.

@Test
public void testSingleResponseFilter() throws Exception {
    final AtomicInteger called = new AtomicInteger(0);
    final List<ContainerResponseFilter> responseFilterList = new ArrayList<>();
    responseFilterList.add(new ContainerResponseFilter() {

        @Override
        public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException {
            called.incrementAndGet();
        }
    });
    final ResourceConfig resourceConfig = new ResourceConfig().register(new ProviderInstanceBindingBinder<>(responseFilterList, ContainerResponseFilter.class));
    final Resource.Builder rb = Resource.builder("test");
    rb.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(final ContainerRequestContext request) {
            return Response.ok().build();
        }
    });
    resourceConfig.registerResources(rb.build());
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    assertEquals(200, application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus());
    assertEquals(1, called.intValue());
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ArrayList(java.util.ArrayList) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) Resource(org.glassfish.jersey.server.model.Resource) IOException(java.io.IOException) ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Response(javax.ws.rs.core.Response) ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 2 with ContainerResponseContext

use of javax.ws.rs.container.ContainerResponseContext in project jersey by jersey.

the class ParamExceptionMappingTest method testFormParamPrimitiveValidation.

@Test
public void testFormParamPrimitiveValidation() throws ExecutionException, InterruptedException {
    initiateWebApplication(ParamExceptionMapperResource.class, FormExceptionMapper.class);
    Form f = new Form();
    f.param("x", "http://oracle.com");
    ContainerResponseContext responseContext = apply(RequestContextBuilder.from("/form-int", "POST").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).entity(f).build());
    assertEquals("form", responseContext.getEntity());
}
Also used : Form(javax.ws.rs.core.Form) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) Test(org.junit.Test)

Aggregations

ContainerResponseContext (javax.ws.rs.container.ContainerResponseContext)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)1 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)1 Form (javax.ws.rs.core.Form)1 Response (javax.ws.rs.core.Response)1 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)1 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 Resource (org.glassfish.jersey.server.model.Resource)1