ApplicationHandler implements ContainerLifecycleListener { public Future<ContainerResponse> apply(final ContainerRequest requestContext) { return apply(requestContext, new NullOutputStream()); } ApplicationHandler();  ApplicationHandler(final Class<? extends Application> jaxrsApplicationClass);  ApplicationHandler(final Application application);  ApplicationHandler(final Application application, final Binder customBinder);  ApplicationHandler(final Application application, final Binder customBinder, final Object parentManager); Future<ContainerResponse> apply(final ContainerRequest requestContext); Future<ContainerResponse> apply(final ContainerRequest request,
                                           final OutputStream outputStream); void handle(final ContainerRequest request); InjectionManager getInjectionManager(); ResourceConfig getConfiguration(); @Override void onStartup(final Container container); @Override void onReload(final Container container); @Override void onShutdown(final Container container);  }
@Test public void testReturnBadRequestOnIllHeaderValue() throws Exception { ApplicationHandler app = createApplication(Resource.class); assertEquals(400, app.apply(RequestContextBuilder.from("/", "GET").header(HttpHeaders.CONTENT_LENGTH, "text").build()) .get().getStatus()); }
@Test public void testMergedResources() throws Exception { ApplicationHandler app = createApplication(MergedA.class, MergedB.class); ContainerResponse response; response = app.apply(RequestContextBuilder.from("/merged", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals(MergedA.RESPONSE, response.getEntity()); response = app.apply(RequestContextBuilder.from("/merged", "POST").build()).get(); assertEquals(200, response.getStatus()); assertEquals(MergedB.RESPONSE, response.getEntity()); }
@Test public void testProviderAsServerProperty() throws Exception { final ResourceConfig resourceConfig = new ResourceConfig(ProviderPropertyResource.class).property(ServerProperties .WADL_FEATURE_DISABLE, true); resourceConfig.property(ServerProperties.PROVIDER_CLASSNAMES, CustomFeature.class.getName()); final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig); ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/property", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("get-filtered", response.getEntity()); }
@Test public void testRuntimeResourceConfig() throws Exception { final ResourceConfig resourceConfig = new ResourceConfig(RuntimeConfigResource.class).property(ServerProperties .WADL_FEATURE_DISABLE, true); resourceConfig.register(CustomFeature.class); final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig); ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/runtimeConfig", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("get-filtered", response.getEntity()); }
@Test public void testSingletonResourceAndProviderClass() throws Exception { ApplicationHandler ah = new ApplicationHandler(new ResourceConfig(SingletonResourceAndProvider.class)); ContainerResponse response = ah.apply(RequestContextBuilder.from("/singleton", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("passed", response.getEntity()); }
@Test public void testSingletonResourceClass() throws Exception { ApplicationHandler ah = new ApplicationHandler(new ResourceConfig(SingletonResource.class)); ContainerResponse response = ah.apply(RequestContextBuilder.from("/singleton", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("1", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/singleton", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("2", response.getEntity()); }
@Test public void testProgrammaticSingletonResourceClass() throws Exception { ResourceConfig rc = new ResourceConfig(); org.glassfish.jersey.server.model.Resource.Builder rb; rb = org.glassfish.jersey.server.model.Resource.builder(); rb.path("singleton").addMethod("GET").handledBy(ProgrammaticSingleton.class); rc.registerResources(rb.build()); rb = org.glassfish.jersey.server.model.Resource.builder(); rb.path("default").addMethod("GET").handledBy(ProgrammaticDefault.class); rc.registerResources(rb.build()); rb = org.glassfish.jersey.server.model.Resource.builder(); rb.path("defaultinstance").addMethod("GET").handledBy(new ProgrammaticDefault()); rc.registerResources(rb.build()); ApplicationHandler ah = new ApplicationHandler(rc); ContainerResponse response = ah.apply(RequestContextBuilder.from("/singleton", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("1", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/singleton", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("2", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/default", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("1", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/default", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("1", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/defaultinstance", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("1", response.getEntity()); response = ah.apply(RequestContextBuilder.from("/defaultinstance", "GET").build()).get(); assertEquals(200, response.getStatus()); assertEquals("2", response.getEntity()); }
@Test public void testPropagationOfPropertiesToFeatures() throws Exception { final ApplicationHandler handler = new ApplicationHandler(Jersey2402.class); final ContainerResponse response = handler.apply(RequestContextBuilder.from("/", "POST").build()).get(); assertEquals(200, response.getStatus()); assertEquals("bar", response.getEntity()); }
@Test public void testMapResponseErrorForMbw() throws Exception { final ApplicationHandler handler = new ApplicationHandler(MapResponseErrorApplication.class); final ContainerRequest context = RequestContextBuilder.from("/", "GET").build(); final ContainerResponse response = handler.apply(context).get(); assertEquals(200, response.getStatus()); assertEquals("bar", response.getEntity()); }
@Test(expected = ExecutionException.class) public void testMapCyclicResponseErrorForMbw() throws Exception { final ApplicationHandler handler = new ApplicationHandler(MapResponseErrorApplication.class); final ContainerRequest context = RequestContextBuilder.from("/foobar", "GET").build(); handler.apply(context).get(); }