Search in sources :

Example 16 with ResourceConfig

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplateTroughSubResourceLocator2.

@Test
public void testPathParamOnAmbiguousTemplateTroughSubResourceLocator2() throws ExecutionException, InterruptedException {
    final ApplicationHandler applicationHandler = new ApplicationHandler(new ResourceConfig(SimpleLocator.class));
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/locator/abc/a", "GET").build()).get();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("a-abc:null", 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 17 with ResourceConfig

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

the class ConstrainedToServerTest method testFiltersAnnotated.

@Test
public void testFiltersAnnotated() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(MyServerFilter.class, MyClientFilter.class, MyServerWrongFilter.class, MyServerFilterWithoutConstraint.class, Resource.class);
    resourceConfig.registerInstances(new MyServerWrongFilter2(), new MyServerFilter2());
    ApplicationHandler handler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = handler.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
    assertEquals("called", response.getHeaderString("MyServerFilter"));
    assertEquals("called", response.getHeaderString("MyServerFilter2"));
    assertEquals("called", response.getHeaderString("MyServerFilterWithoutConstraint"));
}
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 18 with ResourceConfig

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

the class OptionsTest method testNoHeadInSub.

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

Example 19 with ResourceConfig

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

the class OptionsTest method testNoHeadWildcard.

@Test
public void testNoHeadWildcard() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithoutGetMethod.class);
    resourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true);
    ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerRequest request = RequestContextBuilder.from("/no-get", "OPTIONS").accept(MediaType.MEDIA_TYPE_WILDCARD).build();
    final ContainerResponse response = application.apply(request).get();
    Assert.assertEquals(200, response.getStatus());
    final List<String> strings = response.getStringHeaders().get(HttpHeaders.ALLOW);
    for (String allow : strings) {
        Assert.assertFalse(allow.contains("HEAD"));
    }
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 20 with ResourceConfig

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

the class AcceptWriterTest method testAcceptGet.

@Test
public void testAcceptGet() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource.class, FooStringWriter.class, BarStringWriter.class);
    final ApplicationHandler app = new ApplicationHandler(resourceConfig);
    _test(app, "foo: content", "GET", null, null, "application/foo");
    _test(app, "foo: content", "GET", null, null, "applcation/baz, application/foo;q=0.8");
    _test(app, "bar: content", "GET", null, null, "application/bar");
    _test(app, "bar: content", "GET", null, null, "applcation/baz, application/bar;q=0.8");
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Aggregations

ResourceConfig (org.glassfish.jersey.server.ResourceConfig)358 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 URI (java.net.URI)24 Resource (org.glassfish.jersey.server.model.Resource)24 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