Search in sources :

Example 16 with ContainerResponse

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

the class ResponseMediaTypeFromProvidersTest method testSubResource.

@Test
public void testSubResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(AnotherSubResource.class);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/resource/subresource/sub", "POST").header("Accept", "text/plain").build()).get();
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getHeaderString("Content-Type"), equalTo("text/plain"));
    assertThat((String) response.getEntity(), equalTo("AnotherSubResource"));
}
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 ContainerResponse

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

the class SubResourceLocatorCachingTest method _test.

private void _test(final String requestUri, final int subResourceCalls, final boolean sleep) throws InterruptedException, ExecutionException {
    final ApplicationHandler applicationHandler = new ApplicationHandler(config);
    ContainerResponse response = null;
    for (int i = 0; i < INVOCATION_COUNT; i++) {
        response = applicationHandler.apply(RequestContextBuilder.from(requestUri, "GET").build()).get();
        if (sleep) {
            Thread.sleep(1100);
        }
    }
    assertThat(response.getStatus(), is(200));
    assertThat((String) response.getEntity(), is("sub"));
    // Test how many times model processors method has been called.
    assertThat(processor.resourceMehtodCalls, is(1));
    assertThat(processor.subresourceMehtodCalls, is(subResourceCalls));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler)

Example 18 with ContainerResponse

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

the class SubResourceValidationTest method testDisable.

@Test
public void testDisable() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(RootResource.class);
    resourceConfig.property(ServerProperties.RESOURCE_VALIDATION_DISABLE, "true");
    ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/sub", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("get", 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 19 with ContainerResponse

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

the class SubResourceValidationTest method testEnable.

@Test
public void testEnable() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(RootResource.class);
    resourceConfig.property(ServerProperties.RESOURCE_VALIDATION_DISABLE, "false");
    ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    try {
        final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/sub", "GET").build()).get();
        // should throw an exception or return 500
        Assert.assertEquals(500, response.getStatus());
    } catch (Exception e) {
    // ok
    }
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 20 with ContainerResponse

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

the class OptionsTest method testRequestTextPlain.

@Test
public void testRequestTextPlain() throws ExecutionException, InterruptedException {
    ApplicationHandler application = new ApplicationHandler(new ResourceConfig(WadlResource.class, ResponseTextFilter.class));
    final ContainerResponse response = testOptions(MediaType.TEXT_PLAIN_TYPE, application, "/resource");
    final String entity = (String) response.getEntity();
    Assert.assertTrue(entity.contains("GET"));
}
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

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