Search in sources :

Example 11 with ApplicationHandler

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

the class ProgrammaticResourceMethodsTest method testTwoBindersSamePath.

@Test
public void testTwoBindersSamePath() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("/");
    final Resource.Builder childTest1Builder = resourceBuilder.addChildResource("test1");
    childTest1Builder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.created(URI.create("/foo")).build();
        }
    });
    Inflector<ContainerRequestContext, Response> inflector1 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.accepted().build();
        }
    };
    final Resource.Builder childTest2Builder = resourceBuilder.addChildResource("test2");
    childTest2Builder.addMethod("GET").handledBy(inflector1);
    childTest2Builder.addMethod("HEAD").handledBy(inflector1);
    Inflector<ContainerRequestContext, Response> inflector2 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.status(203).build();
        }
    };
    childTest1Builder.addMethod("OPTIONS").handledBy(inflector2);
    childTest1Builder.addMethod("HEAD").handledBy(inflector2);
    final Resource resource = resourceBuilder.build();
    rc.registerResources(resource);
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatusEquals(201, RequestContextBuilder.from("/test1", "GET").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "HEAD").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "OPTIONS").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "GET").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "HEAD").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "OPTIONS").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 12 with ApplicationHandler

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

the class RMBuilderTest method testHelloWorld.

@Test
public void testHelloWorld() throws Exception {
    ApplicationHandler app = createApplication(HelloWorldResource.class);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/helloworld", "GET").build()).get();
    assertEquals("hello", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 13 with ApplicationHandler

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

the class ConsumeProduceSimpleTest method testProduceSimpleBean.

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

Example 14 with ApplicationHandler

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

the class ConsumeProduceSimpleTest method testImplicitProduces.

@Test
public void testImplicitProduces() throws Exception {
    final ApplicationHandler application = createApplication(ImplicitProducesResource.class);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/", "GET").accept(MediaType.TEXT_PLAIN_TYPE).build()).get();
    assertEquals("text/plain", response.getEntity());
    assertEquals("text-plain", response.getHeaderString("HEAD"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 15 with ApplicationHandler

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

the class DynamicFeatureTest method testSubResourceFeature.

@Test
public void testSubResourceFeature() throws Exception {
    final ApplicationHandler application = createApplication(SubResourceDynamicFeature.class);
    ContainerResponse response;
    response = application.apply(RequestContextBuilder.from("/resource/sub", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("sub-get-filtered", response.getEntity());
    response = application.apply(RequestContextBuilder.from("/resource", "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) 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