use of com.peterphi.std.guice.serviceregistry.rest.RestResource in project stdlib by petergeneric.
the class GuiceCoreServicesRegistry method getServices.
public List<CoreService> getServices() {
List<CoreService> services = new ArrayList<>();
for (RestResource resource : RestResourceRegistry.getResources()) {
final Class<?> clazz = resource.getResourceClass();
if (clazz.isAnnotationPresent(Path.class) && clazz != GuiceCommonRestResources.class && clazz != GuiceRestCoreService.class) {
final Path path = clazz.getAnnotation(Path.class);
if (StringUtils.startsWith(path.value(), "/guice")) {
services.add(new CoreService(getName(clazz), path.value()));
}
}
}
// Sort the service list so it's stable across runs
services.sort(Comparator.comparing(CoreService::getName));
return services;
}
use of com.peterphi.std.guice.serviceregistry.rest.RestResource in project stdlib by petergeneric.
the class GuicedResteasy method configure.
/**
* Try to initialise a ServletContainerDispatcher with the connection to the Guice REST services
*/
protected void configure(ServletContainerDispatcher dispatcher) throws ServletException {
// Make sure we are registered with the Guice registry
registry.register(this, true);
// Configure the dispatcher
final Registry resteasyRegistry;
final ResteasyProviderFactory providerFactory;
{
final ResteasyRequestResponseFactory converter = new ResteasyRequestResponseFactory(dispatcher);
dispatcher.init(context, bootstrap, converter, converter);
if (filterConfig != null)
dispatcher.getDispatcher().getDefaultContextObjects().put(FilterConfig.class, filterConfig);
if (servletConfig != null)
dispatcher.getDispatcher().getDefaultContextObjects().put(ServletConfig.class, servletConfig);
resteasyRegistry = dispatcher.getDispatcher().getRegistry();
providerFactory = dispatcher.getDispatcher().getProviderFactory();
}
// Register the REST provider classes
for (Class<?> providerClass : ResteasyProviderRegistry.getClasses()) {
log.debug("Registering REST providers: " + providerClass.getName());
providerFactory.registerProvider(providerClass);
}
// Register the REST provider singletons
for (Object provider : ResteasyProviderRegistry.getSingletons()) {
log.debug("Registering REST provider singleton: " + provider);
providerFactory.registerProviderInstance(provider);
}
providerFactory.registerProviderInstance(new LogReportMessageBodyReader());
// Register the JAXBContext provider
providerFactory.registerProviderInstance(jaxbContextResolver);
// Register the exception mapper
{
// Register the ExceptionMapper for ApplicationException
providerFactory.register(this.exceptionMapper);
log.trace("ExceptionMapper registered for ApplicationException");
}
// Register the REST resources
for (RestResource resource : RestResourceRegistry.getResources()) {
log.debug("Registering REST resource: " + resource.getResourceClass().getName());
resteasyRegistry.addResourceFactory(new ResteasyGuiceResource(injector, resource.getResourceClass()));
}
}
Aggregations