Search in sources :

Example 1 with LogReportMessageBodyReader

use of com.peterphi.std.guice.common.logging.logreport.jaxrs.LogReportMessageBodyReader 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

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 RestResource (com.peterphi.std.guice.serviceregistry.rest.RestResource)1 RestResourceRegistry (com.peterphi.std.guice.serviceregistry.rest.RestResourceRegistry)1 Registry (org.jboss.resteasy.spi.Registry)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1