Search in sources :

Example 11 with ResourceConfig

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

the class AcceptQsTest method testProducesTwoMethodsBarFooResourceProgrammatic.

@Test
public void testProducesTwoMethodsBarFooResourceProgrammatic() throws Exception {
    final Resource.Builder rb = Resource.builder("/");
    rb.addMethod("GET").produces(MediaType.valueOf("application/bar")).handledBy(stringResponse("BAR"));
    rb.addMethod("GET").produces(MediaType.valueOf("application/foo;qs=0.1")).handledBy(stringResponse("FOO"));
    ResourceConfig rc = new ResourceConfig();
    rc.registerResources(rb.build());
    runTestFooBar(new ApplicationHandler(rc), "FOO", "BAR");
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 12 with ResourceConfig

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

the class AcceptQsTest method testProducesOneMethodFooBarResourceProgrammatic.

@Test
public void testProducesOneMethodFooBarResourceProgrammatic() throws Exception {
    final Resource.Builder rb = Resource.builder("/");
    rb.addMethod("GET").produces(MediaType.valueOf("application/foo;qs=0.1"), MediaType.valueOf("application/bar")).handledBy(stringResponse("FOOBAR"));
    ResourceConfig rc = new ResourceConfig();
    rc.registerResources(rb.build());
    runTestFooBar(new ApplicationHandler(rc), "FOOBAR", "FOOBAR");
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 13 with ResourceConfig

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplateTroughSubResourceLocator3.

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

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplate.

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

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

the class AmbiguousTemplateTest method testOptionsOnChild.

@Test
public void testOptionsOnChild() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(ResourceA.class, ResourceB.class, ResourceQ.class);
    ApplicationHandler app = new ApplicationHandler(resourceConfig);
    final ContainerResponse containerResponse = app.apply(RequestContextBuilder.from("/resq/c", "OPTIONS").accept(MediaType.TEXT_PLAIN).build()).get();
    Assert.assertEquals(200, containerResponse.getStatus());
    final List<String> methods = Arrays.asList(containerResponse.getEntity().toString().split(", "));
    assertThat(methods, hasItems("PUT", "GET", "OPTIONS", "HEAD"));
    assertThat(methods.size(), is(4));
}
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)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