Search in sources :

Example 1 with Registry

use of org.jboss.resteasy.spi.Registry in project narayana by jbosstm.

the class BaseTest method startRestEasy.

protected static void startRestEasy(Class<?>... classes) throws Exception {
    server = new TJWSEmbeddedJaxrsServer();
    server.setPort(PORT);
    server.start();
    Registry registry = server.getDeployment().getRegistry();
    ResteasyProviderFactory factory = server.getDeployment().getDispatcher().getProviderFactory();
    if (classes != null)
        for (Class<?> clazz : classes) registry.addPerRequestResource(clazz);
    factory.registerProvider(TMUnavailableMapper.class);
    factory.registerProvider(TransactionStatusMapper.class);
    factory.registerProvider(HttpResponseMapper.class);
    factory.registerProvider(NotFoundMapper.class);
}
Also used : TJWSEmbeddedJaxrsServer(org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer) AfterClass(org.junit.AfterClass) Registry(org.jboss.resteasy.spi.Registry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 2 with Registry

use of org.jboss.resteasy.spi.Registry 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)

Example 3 with Registry

use of org.jboss.resteasy.spi.Registry in project activemq-artemis by apache.

the class RestMessagingBootstrapListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    ServletContext context = contextEvent.getServletContext();
    Registry registry = (Registry) context.getAttribute(Registry.class.getName());
    if (registry == null) {
        throw new RuntimeException("You must install RESTEasy as a Bootstrap Listener and it must be listed before this class");
    }
    String configfile = context.getInitParameter("rest.messaging.config.file");
    deserializationBlackList = context.getInitParameter(ObjectInputStreamWithClassLoader.BLACKLIST_PROPERTY);
    deserializationWhiteList = context.getInitParameter(ObjectInputStreamWithClassLoader.WHITELIST_PROPERTY);
    manager = new MessageServiceManager(this);
    if (configfile != null) {
        manager.setConfigResourcePath(configfile);
    }
    try {
        manager.start();
        registry.addSingletonResource(manager.getQueueManager().getDestination());
        registry.addSingletonResource(manager.getTopicManager().getDestination());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MessageServiceManager(org.apache.activemq.artemis.rest.MessageServiceManager) ServletContext(javax.servlet.ServletContext) Registry(org.jboss.resteasy.spi.Registry)

Example 4 with Registry

use of org.jboss.resteasy.spi.Registry in project candlepin by candlepin.

the class CandlepinContextListenerTest method prepareForInitialization.

private void prepareForInitialization() {
    evt = mock(ServletContextEvent.class);
    ctx = mock(ServletContext.class);
    Registry registry = mock(Registry.class);
    ResteasyProviderFactory rpfactory = mock(ResteasyProviderFactory.class);
    when(evt.getServletContext()).thenReturn(ctx);
    when(ctx.getAttribute(eq(Registry.class.getName()))).thenReturn(registry);
    when(ctx.getAttribute(eq(ResteasyProviderFactory.class.getName()))).thenReturn(rpfactory);
    when(ctx.getAttribute(eq(CandlepinContextListener.CONFIGURATION_NAME))).thenReturn(config);
}
Also used : ServletContext(javax.servlet.ServletContext) Registry(org.jboss.resteasy.spi.Registry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 5 with Registry

use of org.jboss.resteasy.spi.Registry in project HotswapAgent by HotswapProjects.

the class RefreshRegistryCommand method executeCommand.

@Override
public void executeCommand() {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    LOGGER.debug("Re-Loading class: {} , {} , {}", className, oldClassLoader, classLoader);
    Thread.currentThread().setContextClassLoader(classLoader);
    try {
        Registry registry = (Registry) context.getAttribute(Registry.class.getName());
        if (registry == null) {
            registry = servletContainerDispatcher.getDispatcher().getRegistry();
        }
        // Does original actually represent the... original class????
        if (original != null) {
            registry.removeRegistrations(original);
        }
        Class<?> c = classLoader.loadClass(className);
        // Remove all matching registrations (between old and new class..)
        registry.removeRegistrations(c);
        // Iterate over all known methods for this className
        if (registry instanceof ResourceMethodRegistry) {
            ResourceMethodRegistry rm = ResourceMethodRegistry.class.cast(registry);
            Map<String, List<ResourceInvoker>> bounded = rm.getBounded();
            for (Entry<String, List<ResourceInvoker>> e : bounded.entrySet()) {
                LOGGER.debug("Examining {}", e.getKey());
                for (ResourceInvoker r : e.getValue()) {
                    if (LOGGER.isLevelEnabled(Level.DEBUG)) {
                        LOGGER.debug("Examining {} for method {} in class {}", e.getKey(), r.getMethod().getName(), r.getMethod().getDeclaringClass());
                    }
                    if (r.getMethod().getDeclaringClass().getName().equals(className)) {
                        removeRegistration(rm, e.getKey(), r.getMethod());
                    }
                }
            }
        }
        // Add the new resource
        registry.addPerRequestResource(c);
    } catch (Exception e) {
        LOGGER.error("Could not reload rest class {}", e, className);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) List(java.util.List) Registry(org.jboss.resteasy.spi.Registry) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResourceInvoker(org.jboss.resteasy.core.ResourceInvoker)

Aggregations

Registry (org.jboss.resteasy.spi.Registry)5 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)3 ServletContext (javax.servlet.ServletContext)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 RestResource (com.peterphi.std.guice.serviceregistry.rest.RestResource)1 RestResourceRegistry (com.peterphi.std.guice.serviceregistry.rest.RestResourceRegistry)1 List (java.util.List)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 MessageServiceManager (org.apache.activemq.artemis.rest.MessageServiceManager)1 ResourceInvoker (org.jboss.resteasy.core.ResourceInvoker)1 ResourceMethodRegistry (org.jboss.resteasy.core.ResourceMethodRegistry)1 TJWSEmbeddedJaxrsServer (org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer)1 AfterClass (org.junit.AfterClass)1