Search in sources :

Example 6 with ResourceModel

use of org.glassfish.jersey.server.model.ResourceModel in project graylog2-server by Graylog2.

the class PrefixAddingModelProcessorTest method processSubResourceDoesNothing.

@Test
public void processSubResourceDoesNothing() throws Exception {
    final Map<String, String> packagePrefixes = ImmutableMap.of(PACKAGE_NAME, "/test/prefix");
    when(configuration.isCloud()).thenReturn(false);
    final PrefixAddingModelProcessor modelProcessor = new PrefixAddingModelProcessor(packagePrefixes, configuration);
    final ResourceModel originalResourceModel = new ResourceModel.Builder(false).addResource(Resource.from(TestResource.class)).build();
    final ResourceModel resourceModel = modelProcessor.processSubResource(originalResourceModel, new ResourceConfig());
    assertThat(originalResourceModel).isSameAs(resourceModel);
}
Also used : ResourceModel(org.glassfish.jersey.server.model.ResourceModel) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 7 with ResourceModel

use of org.glassfish.jersey.server.model.ResourceModel in project jersey by jersey.

the class MonitoringStatisticsTest method getProgStats.

private MonitoringStatisticsImpl.Builder getProgStats() {
    final Resource.Builder testBuilder = Resource.builder(TestResource.class);
    testBuilder.addChildResource("/prog-child").addMethod("GET").handledBy(MyInflector.class);
    final List<Resource> resources = new ArrayList<>();
    resources.add(testBuilder.build());
    resources.add(Resource.from(HelloResource.class));
    final Resource.Builder prog = Resource.builder("prog");
    prog.addMethod("GET").handledBy(MyInflector.class);
    resources.add(prog.build());
    ResourceModel model = new ResourceModel.Builder(resources, false).build();
    return new MonitoringStatisticsImpl.Builder(model);
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) ArrayList(java.util.ArrayList) ResourceModel(org.glassfish.jersey.server.model.ResourceModel)

Example 8 with ResourceModel

use of org.glassfish.jersey.server.model.ResourceModel in project jersey by jersey.

the class MonitoringStatisticsTest method getSimpleStats.

private MonitoringStatisticsImpl getSimpleStats() {
    final List<Resource> resources = Arrays.asList(Resource.from(TestResource.class), Resource.from(HelloResource.class));
    ResourceModel model = new ResourceModel.Builder(resources, false).build();
    MonitoringStatisticsImpl.Builder monBuilder = new MonitoringStatisticsImpl.Builder(model);
    return monBuilder.build();
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) ResourceModel(org.glassfish.jersey.server.model.ResourceModel)

Example 9 with ResourceModel

use of org.glassfish.jersey.server.model.ResourceModel 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 10 with ResourceModel

use of org.glassfish.jersey.server.model.ResourceModel in project graylog2-server by Graylog2.

the class PrefixAddingModelProcessorTest method processResourceModelAddsPrefixToResourceClassInCorrectPackage.

@Test
public void processResourceModelAddsPrefixToResourceClassInCorrectPackage() throws Exception {
    final ImmutableMap<String, String> packagePrefixes = ImmutableMap.of(PACKAGE_NAME, "/test/prefix");
    when(configuration.isCloud()).thenReturn(false);
    final PrefixAddingModelProcessor modelProcessor = new PrefixAddingModelProcessor(packagePrefixes, configuration);
    final ResourceModel originalResourceModel = new ResourceModel.Builder(false).addResource(Resource.from(TestResource.class)).addResource(Resource.from(HiddenTestResource.class)).build();
    final ResourceModel resourceModel = modelProcessor.processResourceModel(originalResourceModel, new ResourceConfig());
    assertThat(resourceModel.getResources()).hasSize(2);
    final Resource resource = resourceModel.getResources().get(0);
    assertThat(resource.getPath()).isEqualTo("/test/prefix/foobar/{test}");
    final Resource resource2 = resourceModel.getResources().get(1);
    assertThat(resource2.getPath()).isEqualTo("/test/prefix/hide-cloud/{test}");
}
Also used : Resource(org.glassfish.jersey.server.model.Resource) ResourceModel(org.glassfish.jersey.server.model.ResourceModel) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Aggregations

ResourceModel (org.glassfish.jersey.server.model.ResourceModel)13 Resource (org.glassfish.jersey.server.model.Resource)12 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)5 Test (org.junit.Test)5 RuntimeResource (org.glassfish.jersey.server.model.RuntimeResource)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Configuration (javax.ws.rs.core.Configuration)1 GenericType (javax.ws.rs.core.GenericType)1 Provider (javax.ws.rs.ext.Provider)1 CacheBuilder (org.glassfish.jersey.internal.guava.CacheBuilder)1 Ref (org.glassfish.jersey.internal.util.collection.Ref)1 MessageBodyWorkers (org.glassfish.jersey.message.MessageBodyWorkers)1 ComponentBag (org.glassfish.jersey.model.internal.ComponentBag)1 Inflector (org.glassfish.jersey.process.Inflector)1