Search in sources :

Example 31 with ApplicationHandler

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

the class ConsumeProduceSimpleTest method testConsumeSimpleBean.

@Test
public void testConsumeSimpleBean() throws Exception {
    ApplicationHandler app = createApplication(ConsumeSimpleBean.class);
    assertEquals("HTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/html").build()).get().getEntity());
    assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/xhtml").build()).get().getEntity());
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 32 with ApplicationHandler

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

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

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

the class AcceptTest method testAcceptMultiple2.

@Test
public void testAcceptMultiple2() throws Exception {
    ApplicationHandler app = createApplication(MultipleResource.class);
    MediaType foo = MediaType.valueOf("application/foo");
    ContainerResponse response;
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("*/*").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 35 with ApplicationHandler

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

the class AcceptTest method testQualityErrorGreaterThanOne.

@Test
public void testQualityErrorGreaterThanOne() throws Exception {
    ApplicationHandler app = createApplication(Resource.class);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=1.1").build()).get();
    assertEquals(400, response.getStatus());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) 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