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());
}
}
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 ApplicationHandler method bindProvidersAndResources.
private void bindProvidersAndResources(final Iterable<ComponentProvider> componentProviders, final ComponentBag componentBag, final Collection<Class<?>> resourceClasses, final Collection<Object> resourceInstances) {
JerseyResourceContext resourceContext = injectionManager.getInstance(JerseyResourceContext.class);
Set<Class<?>> registeredClasses = runtimeConfig.getRegisteredClasses();
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
java.util.function.Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), RuntimeType.SERVER, !registeredClasses.contains(componentClass), resourceClasses.contains(componentClass));
/*
* Check the {@code resource class} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
BiPredicate<Class<?>, ContractProvider> correctlyConfiguredResource = (resourceClass, model) -> Providers.checkProviderRuntime(resourceClass, model, RuntimeType.SERVER, !registeredClasses.contains(resourceClass), true);
Set<Class<?>> componentClassses = componentBag.getClasses(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(correctlyConfigured).collect(Collectors.toSet());
// Merge programmatic resource classes with component classes.
Set<Class<?>> classes = Collections.newSetFromMap(new IdentityHashMap<>());
classes.addAll(componentClassses);
classes.addAll(resourceClasses);
// Bind classes.
for (final Class<?> componentClass : classes) {
ContractProvider model = componentBag.getModel(componentClass);
if (bindWithComponentProvider(componentClass, model, componentProviders)) {
continue;
}
if (resourceClasses.contains(componentClass)) {
if (!Resource.isAcceptable(componentClass)) {
LOGGER.warning(LocalizationMessages.NON_INSTANTIABLE_COMPONENT(componentClass));
continue;
}
if (model != null && !correctlyConfiguredResource.test(componentClass, model)) {
model = null;
}
resourceContext.unsafeBindResource(componentClass, model, injectionManager);
} else {
ProviderBinder.bindProvider(componentClass, model, injectionManager);
}
}
// Merge programmatic resource instances with other component instances.
Set<Object> instances = componentBag.getInstances(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(instance -> correctlyConfigured.test(instance.getClass())).collect(Collectors.toSet());
instances.addAll(resourceInstances);
// Bind instances.
for (Object component : instances) {
ContractProvider model = componentBag.getModel(component.getClass());
if (resourceInstances.contains(component)) {
if (model != null && !correctlyConfiguredResource.test(component.getClass(), model)) {
model = null;
}
resourceContext.unsafeBindResource(component, model, injectionManager);
} else {
ProviderBinder.bindProvider(component, model, injectionManager);
}
}
}
Aggregations