Search in sources :

Example 1 with RestResource

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;
}
Also used : Path(javax.ws.rs.Path) GuiceRestCoreService(com.peterphi.std.guice.web.rest.service.restcore.GuiceRestCoreService) RestResource(com.peterphi.std.guice.serviceregistry.rest.RestResource) ArrayList(java.util.ArrayList) GuiceRestCoreService(com.peterphi.std.guice.web.rest.service.restcore.GuiceRestCoreService)

Example 2 with RestResource

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()));
    }
}
Also used : RestResource(com.peterphi.std.guice.serviceregistry.rest.RestResource) Registry(org.jboss.resteasy.spi.Registry) MetricRegistry(com.codahale.metrics.MetricRegistry) GuiceRegistry(com.peterphi.std.guice.apploader.impl.GuiceRegistry) RestResourceRegistry(com.peterphi.std.guice.serviceregistry.rest.RestResourceRegistry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) LogReportMessageBodyReader(com.peterphi.std.guice.common.logging.logreport.jaxrs.LogReportMessageBodyReader)

Aggregations

RestResource (com.peterphi.std.guice.serviceregistry.rest.RestResource)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 GuiceRegistry (com.peterphi.std.guice.apploader.impl.GuiceRegistry)1 LogReportMessageBodyReader (com.peterphi.std.guice.common.logging.logreport.jaxrs.LogReportMessageBodyReader)1 RestResourceRegistry (com.peterphi.std.guice.serviceregistry.rest.RestResourceRegistry)1 GuiceRestCoreService (com.peterphi.std.guice.web.rest.service.restcore.GuiceRestCoreService)1 ArrayList (java.util.ArrayList)1 Path (javax.ws.rs.Path)1 Registry (org.jboss.resteasy.spi.Registry)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1