Search in sources :

Example 56 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.

the class LayeredFiltersTest method testResourceMethodMultiple.

@Test
public void testResourceMethodMultiple() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithMethodMultiple.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("onetwo", response.getEntity());
    List<Object> xTest = response.getHeaders().get("X-TEST");
    assertEquals(2, xTest.size());
    assertEquals("two", xTest.get(0));
    assertEquals("one", xTest.get(1));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 57 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.

the class UriConnegFilterTest method setUp.

@Before
public void setUp() {
    Map<String, MediaType> mediaTypes = new HashMap<>();
    mediaTypes.put("foo", MediaType.valueOf("application/foo"));
    mediaTypes.put("bar", MediaType.valueOf("application/bar"));
    ResourceConfig rc = new ResourceConfig(Resource.class);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, mediaTypes);
    handler = new ApplicationHandler(rc);
}
Also used : HashMap(java.util.HashMap) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) MediaType(javax.ws.rs.core.MediaType) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Before(org.junit.Before)

Example 58 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.

the class UriModificationFilterTest method testWithInstance.

@Test
public void testWithInstance() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource.class).register(UriModifyFilter.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/a/b/c", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("/a/b?filter=c", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 59 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.

the class ResourceContextTest method testGetResource.

@Test
public void testGetResource() throws Exception {
    ApplicationHandler app = createApplication(ResourceA.class, ResourceB.class);
    assertEquals("B: c", app.apply(RequestContextBuilder.from("/a/b/c", "GET").build()).get().getEntity());
    assertEquals("SR: foo", app.apply(RequestContextBuilder.from("/a/foo", "GET").build()).get().getEntity());
    assertEquals("null", app.apply(RequestContextBuilder.from("/a/is-null", "GET").build()).get().getEntity());
    assertEquals(404, app.apply(RequestContextBuilder.from("/a/non-instantiable", "GET").build()).get().getStatus());
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 60 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.

the class CsrfProtectionFilterTest method setUp.

@Before
public void setUp() {
    ResourceConfig rc = new ResourceConfig(Resource.class, CsrfProtectionFilter.class);
    handler = new ApplicationHandler(rc);
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Before(org.junit.Before)

Aggregations

ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)162 Test (org.junit.Test)142 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)104 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)99 ApplicationInfoListener (org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener)17 MonitoringEventListener (org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener)17 MBeanExposer (org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)17 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)12 Response (javax.ws.rs.core.Response)10 MediaType (javax.ws.rs.core.MediaType)8 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)7 MonitoringFeature (org.glassfish.jersey.server.internal.monitoring.MonitoringFeature)6 Resource (org.glassfish.jersey.server.model.Resource)6 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)5 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)4 IOException (java.io.IOException)3 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)3 Inflector (org.glassfish.jersey.process.Inflector)3 Before (org.junit.Before)3