Search in sources :

Example 36 with ApplicationHandler

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

the class AcceptTest method testAcceptNoProduces.

@Test
public void testAcceptNoProduces() throws Exception {
    ApplicationHandler app = createApplication(NoProducesResource.class);
    // media type order in the accept header does not impose output media type!
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept("image/png, text/plain;q=0.9").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.valueOf("image/png"), response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("text/plain;q=0.5, text/html").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.TEXT_HTML_TYPE, response.getMediaType());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 37 with ApplicationHandler

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

the class AcceptTest method test.

private void test(Class<?> c) throws Exception {
    ApplicationHandler app = createApplication(c);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.valueOf("application/foo"), response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/bar").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.valueOf("application/bar"), response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo", "application/bar").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.valueOf("application/foo"), response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/bar", "application/foo").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(MediaType.valueOf("application/bar"), response.getMediaType());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler)

Example 38 with ApplicationHandler

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

the class AcceptTest method testAcceptMultiple.

@Test
public void testAcceptMultiple() throws Exception {
    ApplicationHandler app = createApplication(MultipleResource.class);
    MediaType foo = MediaType.valueOf("application/foo");
    MediaType bar = MediaType.valueOf("application/bar");
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept(foo).build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept(bar).build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(bar, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("*/*").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/*").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.1", "application/bar").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(bar, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.5", "application/bar;q=0.1").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 39 with ApplicationHandler

use of org.glassfish.jersey.server.ApplicationHandler 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)

Example 40 with ApplicationHandler

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplate3.

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

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