Search in sources :

Example 31 with Resource

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;
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) RuntimeResource(org.glassfish.jersey.server.model.RuntimeResource) ResourceModel(org.glassfish.jersey.server.model.ResourceModel)

Example 32 with Resource

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();
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) Test(org.junit.Test)

Example 33 with Resource

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");
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) Test(org.junit.Test)

Example 34 with Resource

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();
}
Also used : Resource(org.glassfish.jersey.server.model.Resource)

Example 35 with Resource

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;
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Resource(org.glassfish.jersey.server.model.Resource) Response(javax.ws.rs.core.Response) MediaType(javax.ws.rs.core.MediaType) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod)

Aggregations

Resource (org.glassfish.jersey.server.model.Resource)44 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)12 ResourceModel (org.glassfish.jersey.server.model.ResourceModel)12 Test (org.junit.Test)10 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)9 ArrayList (java.util.ArrayList)7 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)7 Response (javax.ws.rs.core.Response)6 HashSet (java.util.HashSet)4 RuntimeResource (org.glassfish.jersey.server.model.RuntimeResource)4 Inflector (org.glassfish.jersey.process.Inflector)3 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)3 Type (java.lang.reflect.Type)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Configuration (javax.ws.rs.core.Configuration)2 ComponentBag (org.glassfish.jersey.model.internal.ComponentBag)2 ModelProcessor (org.glassfish.jersey.server.model.ModelProcessor)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1