use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class TemplateModelProcessor method processTemplateAnnotatedInvocables.
/**
* Process all {@link Invocable invocables} and defines
* {@link org.glassfish.jersey.server.model.Invocable#getRoutingResponseType() routing response types}
* as {@link Viewable} for all methods annotated with {@link Template}.
*
* @param resourceModel resource model to process.
* @param subResourceModel determines whether the resource model represents sub-resource.
* @return Modified resource model.
*/
private ResourceModel.Builder processTemplateAnnotatedInvocables(ResourceModel resourceModel, final boolean subResourceModel) {
ResourceModel.Builder modelBuilder = new ResourceModel.Builder(subResourceModel);
for (Resource resource : resourceModel.getResources()) {
Resource newResource = processResource(resource);
modelBuilder.addResource(newResource);
}
return modelBuilder;
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method testChildResourceMerge.
@Test
public void testChildResourceMerge() {
final List<Resource> rootResources = createRootResources();
assertEquals(2, rootResources.size());
final Resource resourceAB = ResourceTestUtils.getResource(rootResources, "a");
assertEquals(2, resourceAB.getChildResources().size());
final Resource child = ResourceTestUtils.getResource(resourceAB.getChildResources(), "child");
final Resource child2 = ResourceTestUtils.getResource(resourceAB.getChildResources(), "child2");
ResourceTestUtils.containsExactMethods(child, true, "GET", "POST");
ResourceTestUtils.containsExactMethods(child2, false, "GET");
final Resource resourceC = ResourceTestUtils.getResource(rootResources, "different-path");
final List<Resource> childResourcesC = resourceC.getChildResources();
assertEquals(2, childResourcesC.size());
final Resource childC1 = ResourceTestUtils.getResource(childResourcesC, "child");
ResourceTestUtils.containsExactMethods(childC1, false, "PUT");
final Resource childC2 = ResourceTestUtils.getResource(childResourcesC, "locator");
ResourceTestUtils.containsExactMethods(childC2, true);
child.getResourceMethods().size();
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method programmaticTest.
@Test
public void programmaticTest() {
final List<Resource> rootResources = getResourcesFromProgrammatic();
assertEquals(1, rootResources.size());
final Resource root = ResourceTestUtils.getResource(rootResources, "root");
final List<Resource> childResources = root.getChildResources();
assertEquals(2, childResources.size());
final Resource child = ResourceTestUtils.getResource(childResources, "child");
ResourceTestUtils.containsExactMethods(child, true, "GET", "POST", "DELETE");
final Resource child2 = ResourceTestUtils.getResource(childResources, "child2");
ResourceTestUtils.containsExactMethods(child2, false, "PUT");
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class ResourceMergeTest method createRootResources.
private List<Resource> createRootResources() {
final Resource resourceA = Resource.from(ResourceA.class);
final Resource resourceB = Resource.from(ResourceB.class);
final ResourceBag.Builder builder = new ResourceBag.Builder();
builder.registerProgrammaticResource(resourceA);
builder.registerProgrammaticResource(resourceB);
builder.registerProgrammaticResource(Resource.from(ResourceC.class));
final ResourceBag bag = builder.build();
return bag.getRootResources();
}
use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class App method createApp.
/**
* Create example application resource configuration.
*
* @return initialized resource configuration of the example application.
*/
public static ResourceConfig createApp() {
MediaType[] jsonAndTextTypes = new MediaType[] { MediaType.APPLICATION_JSON_TYPE, MediaType.TEXT_PLAIN_TYPE };
final ResourceConfig resourceConfig = new ResourceConfig(ClipboardResource.class, ClipboardDataProvider.ApplicationJson.class, ClipboardDataProvider.TextPlain.class);
final Resource.Builder resourceBuilder = Resource.builder("echo");
ResourceMethod.Builder rmBuilder = resourceBuilder.addMethod("POST");
rmBuilder.consumes(jsonAndTextTypes).produces(jsonAndTextTypes).handledBy(new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(ContainerRequestContext request) {
ClipboardData data = (request != null) ? ((ContainerRequest) request).readEntity(ClipboardData.class) : null;
return Response.ok(data).build();
}
});
resourceConfig.registerResources(resourceBuilder.build());
return resourceConfig;
}
Aggregations