Search in sources :

Example 36 with ContainerResponse

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

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

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

Example 39 with ContainerResponse

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

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

Aggregations

ContainerResponse (org.glassfish.jersey.server.ContainerResponse)211 Test (org.junit.Test)190 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)95 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)58 MediaType (javax.ws.rs.core.MediaType)16 Form (javax.ws.rs.core.Form)14 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)14 Cookie (javax.ws.rs.core.Cookie)7 Response (javax.ws.rs.core.Response)5 Ignore (org.junit.Ignore)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)2 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)2 ContainerException (org.glassfish.jersey.server.ContainerException)2 RequestContextBuilder (org.glassfish.jersey.server.RequestContextBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1