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