use of org.glassfish.jersey.server.model.Resource in project jersey by jersey.
the class App method create.
/**
* Create example application resource configuration.
*
* @return initialized resource configuration of the example application.
*/
public static ResourceConfig create() {
final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH);
resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(ContainerRequestContext data) {
getMethodCalled = true;
return Response.ok("Hello World!").build();
}
});
Inflector<ContainerRequestContext, Response> noContentResponder = new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(ContainerRequestContext data) {
headMethodCalled = true;
return Response.noContent().build();
}
};
resourceBuilder.addMethod("HEAD").handledBy(noContentResponder);
resourceBuilder.addMethod("OPTIONS").handledBy(noContentResponder);
return new ResourceConfig().registerResources(resourceBuilder.build());
}
use of org.glassfish.jersey.server.model.Resource in project graylog2-server by Graylog2.
the class RestTools method getPathFromResource.
public static String getPathFromResource(Resource resource) {
String path = resource.getPath();
Resource parent = resource.getParent();
while (parent != null) {
if (!path.startsWith("/")) {
path = "/" + path;
}
path = parent.getPath() + path;
parent = parent.getParent();
}
return path;
}
use of org.glassfish.jersey.server.model.Resource in project graylog2-server by Graylog2.
the class PrefixAddingModelProcessorTest method processResourceModelAddsPrefixToResourceClassInCorrectSubPackage.
@Test
public void processResourceModelAddsPrefixToResourceClassInCorrectSubPackage() throws Exception {
final ImmutableMap<String, String> packagePrefixes = ImmutableMap.of("org", "/generic", "org.graylog2", "/test/prefix", "org.graylog2.wrong", "/wrong");
final PrefixAddingModelProcessor modelProcessor = new PrefixAddingModelProcessor(packagePrefixes);
final ResourceModel originalResourceModel = new ResourceModel.Builder(false).addResource(Resource.from(TestResource.class)).build();
final ResourceModel resourceModel = modelProcessor.processResourceModel(originalResourceModel, new ResourceConfig());
assertThat(resourceModel.getResources()).hasSize(1);
final Resource resource = resourceModel.getResources().get(0);
assertThat(resource.getPath()).isEqualTo("/test/prefix/foobar/{test}");
}
use of org.glassfish.jersey.server.model.Resource in project graylog2-server by Graylog2.
the class PrintModelProcessor method processResourceModel.
@Override
public ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration) {
LOG.debug("Map for resource model <" + resourceModel + ">:");
final List<Resource> resources = new ArrayList<>();
for (Resource resource : resourceModel.getResources()) {
resources.add(resource);
resources.addAll(findChildResources(resource));
}
logResources(resources);
return resourceModel;
}
use of org.glassfish.jersey.server.model.Resource in project graylog2-server by Graylog2.
the class PrintModelProcessor method logResources.
private void logResources(List<Resource> resources) {
final List<ResourceDescription> resourceDescriptions = new ArrayList<>();
for (Resource resource : resources) {
for (ResourceMethod resourceMethod : resource.getAllMethods()) {
final String path = RestTools.getPathFromResource(resource);
resourceDescriptions.add(new ResourceDescription(resourceMethod.getHttpMethod(), path, resource.getHandlerClasses()));
}
}
Collections.sort(resourceDescriptions);
for (ResourceDescription resource : resourceDescriptions) {
LOG.debug(resource.toString());
}
}
Aggregations