Search in sources :

Example 66 with ContainerResponse

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

the class UriTest method testManagedClientInjection1.

@Test
public void testManagedClientInjection1() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource4.class);
    // TODO introduce new ResourceConfig.setClientProperty(Class<? extends Annotation>, String name, Object value) helper method
    resourceConfig.property(Managed.class.getName() + ".property.test-property", "test-value");
    initiateWebApplication(resourceConfig);
    final ContainerResponse response = apply(RequestContextBuilder.from("/test/1", "GET").build());
    assertEquals("test-value", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 67 with ContainerResponse

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

the class UriTest method testManagedClientInjection3.

@Test
public void testManagedClientInjection3() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource4.class);
    resourceConfig.property(Managed.class.getName() + ".property.test-property", "test-value");
    resourceConfig.property(Managed.class.getName() + ".baseUri", "http://oracle.com");
    initiateWebApplication(resourceConfig);
    final ContainerResponse response = apply(RequestContextBuilder.from("/test/3", "GET").build());
    assertEquals("http://oracle.com/relative", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 68 with ContainerResponse

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

the class HttpMethodOverrideFilterTest method test.

public String test(HttpMethodOverrideFilter.Source... sources) {
    ResourceConfig rc = new ResourceConfig(Resource.class);
    HttpMethodOverrideFilter.enableFor(rc, sources);
    ApplicationHandler handler = new ApplicationHandler(rc);
    try {
        ContainerResponse response = handler.apply(RequestContextBuilder.from("", "/?_method=DELETE", "POST").header("X-HTTP-Method-Override", "PUT").build()).get();
        if (Response.Status.OK.equals(response.getStatusInfo())) {
            return (String) response.getEntity();
        } else {
            return "" + response.getStatus();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 69 with ContainerResponse

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

the class LayeredFiltersTest method testResourceMethod.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceMethod() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocator.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("onetwo", response.getEntity());
    List<Object> xTest = response.getHeaders().get("X-TEST");
    assertEquals(2, xTest.size());
    assertEquals("two", xTest.get(0));
    assertEquals("one", xTest.get(1));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 70 with ContainerResponse

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

the class LayeredFiltersTest method testResourceSubresourceMethod.

@Test
@Ignore("JERSEY-2414 - not yet implemented")
public void testResourceSubresourceMethod() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(ResourceWithSubresourceLocator.class).register(FilterOne.class).register(FilterTwo.class);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/sub/submethod", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("onetwo", response.getEntity());
    List<Object> xTest = response.getHeaders().get("X-TEST");
    assertEquals(2, xTest.size());
    assertEquals("two", xTest.get(0));
    assertEquals("one", xTest.get(1));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Ignore(org.junit.Ignore) 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