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);
}
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);
}
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;
}
Aggregations