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);
}
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()));
}
}
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);
}
}
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);
}
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);
}
}
Aggregations