use of javax.ws.rs.container.ContainerRequestContext in project jersey by jersey.
the class ProgrammaticResourceMethodsTest method testOptions.
@Test
public void testOptions() throws Exception {
final ResourceConfig rc = new ResourceConfig();
final Resource.Builder resourceBuilder = Resource.builder("test");
resourceBuilder.addMethod("OPTIONS").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", "OPTIONS").build(), application);
}
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;
}
use of javax.ws.rs.container.ContainerRequestContext in project nifi by apache.
the class TestRedirectResourceFilter method testUnmatched.
@Test
public void testUnmatched() throws Exception {
String path = "unmatched";
String baseUri = "http://example.com:8080/nifi-api/";
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getPath()).thenReturn(path);
when(uriInfo.getBaseUri()).thenReturn(new URI(baseUri));
when(uriInfo.getRequestUri()).thenReturn(new URI(baseUri + path));
ContainerRequestContext request = mock(ContainerRequestContext.class);
when(request.getUriInfo()).thenReturn(uriInfo);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
fail("setUris shouldn't be called");
return null;
}
}).when(request).setRequestUri(any(URI.class), any(URI.class));
RedirectResourceFilter filter = new RedirectResourceFilter();
filter.filter(request);
}
Aggregations