Search in sources :

Example 1 with ResourceConfig

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

the class ResponseMediaTypeFromProvidersTest method testSubResource.

@Test
public void testSubResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(AnotherSubResource.class);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/resource/subresource/sub", "POST").header("Accept", "text/plain").build()).get();
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getHeaderString("Content-Type"), equalTo("text/plain"));
    assertThat((String) response.getEntity(), equalTo("AnotherSubResource"));
}
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 2 with ResourceConfig

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

the class SubResourceValidationTest method testDisable.

@Test
public void testDisable() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(RootResource.class);
    resourceConfig.property(ServerProperties.RESOURCE_VALIDATION_DISABLE, "true");
    ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/sub", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("get", 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 3 with ResourceConfig

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

the class SubResourceValidationTest method testEnable.

@Test
public void testEnable() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(RootResource.class);
    resourceConfig.property(ServerProperties.RESOURCE_VALIDATION_DISABLE, "false");
    ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    try {
        final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/sub", "GET").build()).get();
        // should throw an exception or return 500
        Assert.assertEquals(500, response.getStatus());
    } catch (Exception e) {
    // ok
    }
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with ResourceConfig

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

the class OptionsTest method testRequestTextPlain.

@Test
public void testRequestTextPlain() throws ExecutionException, InterruptedException {
    ApplicationHandler application = new ApplicationHandler(new ResourceConfig(WadlResource.class, ResponseTextFilter.class));
    final ContainerResponse response = testOptions(MediaType.TEXT_PLAIN_TYPE, application, "/resource");
    final String entity = (String) response.getEntity();
    Assert.assertTrue(entity.contains("GET"));
}
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 5 with ResourceConfig

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

the class OptionsTest method testNoHead.

@Test
public void testNoHead() throws ExecutionException, InterruptedException {
    ApplicationHandler application = new ApplicationHandler(new ResourceConfig(ResourceWithoutGetMethod.class));
    final ContainerResponse response = testOptions(MediaType.TEXT_PLAIN_TYPE, application, "/no-get");
    Assert.assertFalse(((String) response.getEntity()).contains("HEAD"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Aggregations

ResourceConfig (org.glassfish.jersey.server.ResourceConfig)357 Test (org.junit.Test)135 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)105 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)62 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)33 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)29 Response (javax.ws.rs.core.Response)28 HttpServer (org.glassfish.grizzly.http.server.HttpServer)28 Resource (org.glassfish.jersey.server.model.Resource)24 URI (java.net.URI)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)23 IOException (java.io.IOException)22 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)22 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)17 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 MetricRegistry (com.codahale.metrics.MetricRegistry)15 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)15