Search in sources :

Example 21 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project jersey by jersey.

the class ProgrammaticResourceMethodsTest method testHead.

@Test
public void testHead() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("test");
    resourceBuilder.addMethod("HEAD").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.ok().build();
        }
    });
    rc.registerResources(resourceBuilder.build());
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatus(RequestContextBuilder.from("/test", "HEAD").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 22 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext 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)

Example 23 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project jersey by jersey.

the class SingletonResourceTest method configure.

@Override
protected ResourceConfig configure() {
    final ResourceConfig resourceConfig = new ResourceConfig(SingletonResource.class, ChildInheritsParentAnnotation.class, ChildImplementsInterfaceAnnotation.class, TestResource.class, RequestScopeResource.class, PerLookupScopeResource.class, SingletonScopeResource.class);
    final Resource.Builder resourceBuilder1 = Resource.builder();
    resourceBuilder1.name("resource-programmatic/instance/").path("programmatic/instance/").addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        private int counter = 1;

        @Override
        public Response apply(ContainerRequestContext data) {
            return Response.ok("prg-instance:" + counter++).build();
        }
    });
    resourceConfig.registerResources(resourceBuilder1.build());
    final Resource.Builder resourceBuilder2 = Resource.builder();
    resourceBuilder2.name("resource-programmatic/singleton/").path("programmatic/singleton/").addMethod("GET").handledBy(SingletonProgrammatic.class);
    resourceConfig.registerResources(resourceBuilder2.build());
    final Resource.Builder resourceBuilder3 = Resource.builder();
    resourceBuilder3.name("resource-programmatic/reused-singleton/").path("programmatic/reused-singleton/").addMethod("GET").handledBy(SubResourceSingleton.class);
    resourceConfig.registerResources(resourceBuilder3.build());
    final Resource.Builder resourceBuilder4 = Resource.builder();
    resourceBuilder4.name("resource-programmatic/not-singleton/").path("programmatic/not-singleton/").addMethod("GET").handledBy(NotSingletonProgrammatic.class);
    resourceConfig.registerResources(resourceBuilder4.build());
    return resourceConfig;
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Resource(org.glassfish.jersey.server.model.Resource) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)23 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)22 Response (javax.ws.rs.core.Response)20 Resource (org.glassfish.jersey.server.model.Resource)15 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)12 Test (org.junit.Test)12 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)10 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)4 Inflector (org.glassfish.jersey.process.Inflector)4 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InputStream (java.io.InputStream)1 ContainerResponseContext (javax.ws.rs.container.ContainerResponseContext)1 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)1 MediaType (javax.ws.rs.core.MediaType)1 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)1