use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class ApplicationFilterTest method testFilterExceptionHandling.
@Test
public void testFilterExceptionHandling() throws Exception {
final List<ContainerRequestFilter> requestFilterList = new ArrayList<>();
requestFilterList.add(new ExceptionFilter());
final ResourceConfig resourceConfig = new ResourceConfig().register(new ProviderInstanceBindingBinder<>(requestFilterList, ContainerRequestFilter.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);
try {
application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus();
Assert.fail("should throw an exception");
} catch (final Exception e) {
// ok
}
}
use of org.glassfish.jersey.server.ApplicationHandler 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 org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class ApplicationFilterTest method testMultipleFiltersWithBindingPriority.
@Test
public void testMultipleFiltersWithBindingPriority() throws Exception {
final Filter1 filter1 = new Filter1();
final Filter10 filter10 = new Filter10();
final Filter100 filter100 = new Filter100();
filter1.setFilters(filter10, filter100);
filter10.setFilters(filter1, filter100);
filter100.setFilters(filter1, filter10);
final List<ContainerRequestFilter> requestFilterList = new ArrayList<>();
requestFilterList.add(filter100);
requestFilterList.add(filter1);
requestFilterList.add(filter10);
final ResourceConfig resourceConfig = new ResourceConfig().register(new ProviderInstanceBindingBinder<>(requestFilterList, ContainerRequestFilter.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());
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class JsonProcessingAutoDiscoverableServerTest method _test.
private void _test(final String response, final Boolean globalDisable, final Boolean serverDisable) throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(Resource.class, Filter.class);
if (globalDisable != null) {
resourceConfig.property(CommonProperties.JSON_PROCESSING_FEATURE_DISABLE, globalDisable);
}
if (serverDisable != null) {
resourceConfig.property(ServerProperties.JSON_PROCESSING_FEATURE_DISABLE, serverDisable);
}
final ApplicationHandler app = new ApplicationHandler(resourceConfig);
final URI baseUri = URI.create("/");
assertEquals(response, app.apply(new ContainerRequest(baseUri, baseUri, "GET", null, new MapPropertiesDelegate())).get().getEntity());
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class SubResourceProgrammaticTest method testComplex.
@Test
public void testComplex() throws ExecutionException, InterruptedException {
ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(RootResource.class));
int singletonCounter = 0;
_test(handler, "/root/complex/", "inflector");
_test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration/iteration", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration-class", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration-instance", "singleton:0");
_test(handler, "/root/complex/standard", "standard:0");
_test(handler, "/root/complex/standard/iteration", "standard:0");
_test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration/iteration-standard", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class/iteration-instance", "singleton:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex", "inflector");
}
Aggregations