Search in sources :

Example 51 with ApplicationHandler

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

the class HttpMethodOverrideFilterTest method test.

public String test(HttpMethodOverrideFilter.Source... sources) {
    ResourceConfig rc = new ResourceConfig(Resource.class);
    HttpMethodOverrideFilter.enableFor(rc, sources);
    ApplicationHandler handler = new ApplicationHandler(rc);
    try {
        ContainerResponse response = handler.apply(RequestContextBuilder.from("", "/?_method=DELETE", "POST").header("X-HTTP-Method-Override", "PUT").build()).get();
        if (Response.Status.OK.equals(response.getStatusInfo())) {
            return (String) response.getEntity();
        } else {
            return "" + response.getStatus();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 52 with ApplicationHandler

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

the class LayeredFiltersTest method testResourceMethod.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceMethod() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocator.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub", "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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with ApplicationHandler

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

the class LayeredFiltersTest method testResourceSubresourceMethod.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceSubresourceMethod() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocator.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub/submethod", "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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 54 with ApplicationHandler

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

the class LayeredFiltersTest method testResourceMethodOnClass.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceMethodOnClass() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocatorOnClass.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub", "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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 55 with ApplicationHandler

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

the class LayeredFiltersTest method testResourceSubresourceMethodOnClass.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceSubresourceMethodOnClass() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocatorOnClass.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub/submethod", "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) Ignore(org.junit.Ignore) Test(org.junit.Test)

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