Search in sources :

Example 1 with Inflector

use of org.glassfish.jersey.process.Inflector 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 2 with Inflector

use of org.glassfish.jersey.process.Inflector in project jersey by jersey.

the class ChildResourceTest method createApplication.

private ApplicationHandler createApplication() {
    final Resource.Builder rootBuilder = Resource.builder("root");
    rootBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "root-get";
        }
    });
    rootBuilder.addChildResource("child").addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "sub-get";
        }
    }).build();
    Resource.Builder anotherChildBuilder = Resource.builder("another-child");
    anotherChildBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "another-child-get";
        }
    });
    rootBuilder.addChildResource(anotherChildBuilder.build());
    Resource resource = rootBuilder.build();
    ResourceConfig resourceConfig = new ResourceConfig().registerResources(resource);
    return new ApplicationHandler(resourceConfig);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) Resource(org.glassfish.jersey.server.model.Resource) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 3 with Inflector

use of org.glassfish.jersey.process.Inflector in project jersey by jersey.

the class App method create.

/**
     * Create example application resource configuration.
     *
     * @return initialized resource configuration of the example application.
     */
public static ResourceConfig create() {
    final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH);
    resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            getMethodCalled = true;
            return Response.ok("Hello World!").build();
        }
    });
    Inflector<ContainerRequestContext, Response> noContentResponder = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            headMethodCalled = true;
            return Response.noContent().build();
        }
    };
    resourceBuilder.addMethod("HEAD").handledBy(noContentResponder);
    resourceBuilder.addMethod("OPTIONS").handledBy(noContentResponder);
    return new ResourceConfig().registerResources(resourceBuilder.build());
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) Resource(org.glassfish.jersey.server.model.Resource) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 4 with Inflector

use of org.glassfish.jersey.process.Inflector in project jersey by jersey.

the class ProgrammaticResourceMethodsTest method testMultiple.

@Test
public void testMultiple() throws Exception {
    Inflector<ContainerRequestContext, Response> inflector = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.ok().build();
        }
    };
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("test");
    resourceBuilder.addMethod("GET").handledBy(inflector);
    resourceBuilder.addMethod("OPTIONS").handledBy(inflector);
    resourceBuilder.addMethod("HEAD").handledBy(inflector);
    rc.registerResources(resourceBuilder.build());
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatus(RequestContextBuilder.from("/test", "GET").build(), application);
    checkReturnedStatus(RequestContextBuilder.from("/test", "HEAD").build(), application);
    checkReturnedStatus(RequestContextBuilder.from("/test", "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)

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)4 Inflector (org.glassfish.jersey.process.Inflector)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)4 Response (javax.ws.rs.core.Response)3 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)3 Resource (org.glassfish.jersey.server.model.Resource)2 Test (org.junit.Test)2