use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldSeBuilderTest method testPassingWeldSeContainerToWeldServlet.
@Test
public void testPassingWeldSeContainerToWeldServlet() throws Exception {
try (WeldContainer weld = new Weld().disableDiscovery().beanClasses(Cat.class).initialize()) {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addEventListener(Listener.using(weld));
test(context);
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldSeBuilderTest method testPassingWeldSeContainerToWeldServletViaParam.
@Test
public void testPassingWeldSeContainerToWeldServletViaParam() throws Exception {
try (WeldContainer weld = new Weld().disableDiscovery().beanClasses(Cat.class).initialize()) {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addEventListener(new Listener());
context.setAttribute(Listener.CONTAINER_ATTRIBUTE_NAME, weld);
test(context);
}
}
use of org.jboss.weld.environment.se.WeldContainer in project fabric8 by fabric8io.
the class NoNamespaceTest method createInstance.
void createInstance(Class type) {
WeldContainer weld = new Weld().disableDiscovery().extensions(new Fabric8Extension()).beanClasses(MyBean.class).initialize();
CreationalContext ctx = weld.getBeanManager().createCreationalContext(null);
for (Bean bean : weld.getBeanManager().getBeans(type)) {
weld.getBeanManager().getReference(bean, type, ctx);
}
}
use of org.jboss.weld.environment.se.WeldContainer in project wildfly-swarm by wildfly-swarm.
the class ServerBootstrapImpl method bootstrap.
@Override
public Server bootstrap() throws Exception {
try (AutoCloseable bootstrap = Performance.time("Bootstrap")) {
Module module = Module.getBootModuleLoader().loadModule("swarm.container");
return ClassLoading.withTCCL(new ExtensionPreventionClassLoaderWrapper(module.getClassLoader()), () -> {
try (AutoCloseable logFractionHandle = Performance.time("Log fractions")) {
logFractions();
}
RuntimeServer outerServer = LogSilencer.silently("org.jboss.weld", "ServiceLoader").execute(() -> {
Weld weld = new Weld(WELD_INSTANCE_ID);
weld.setClassLoader(module.getClassLoader());
ConfigViewProducingExtension configViewProducingExtension = new ConfigViewProducingExtension(this.configView);
DeploymentContext deploymentContext = new DeploymentContextImpl();
ConfigurableManager configurableManager = new ConfigurableManager(this.configView, deploymentContext);
// Add Extension that adds User custom bits into configurator
weld.addExtension(new FractionProducingExtension(explicitlyInstalledFractions, configurableManager));
weld.addExtension(new ConfigurableExtension(configurableManager));
weld.addExtension(new CommandLineArgsExtension(args));
weld.addExtension(configViewProducingExtension);
weld.addExtension(new XMLConfigProducingExtension(this.xmlConfigURL));
weld.addExtension(new InterfaceExtension(this.configView));
weld.addExtension(new OutboundSocketBindingExtension(this.outboundSocketBindings));
weld.addExtension(new SocketBindingExtension(this.socketBindings));
weld.addExtension(new DeploymentScopedExtension(deploymentContext));
weld.addExtension(new ImplicitArchiveExtension());
for (Class<?> each : this.userComponents) {
weld.addBeanClass(each);
}
weld.property("org.jboss.weld.se.shutdownHook", false);
WeldContainer weldContainer = null;
RuntimeServer server = null;
try (AutoCloseable weldRelated = Performance.time("Weld-related")) {
try (AutoCloseable weldInitHandle = Performance.time("Weld initialize")) {
weldContainer = weld.initialize();
}
try (AutoCloseable serverSelectHandle = Performance.time("Server construction")) {
server = weldContainer.select(RuntimeServer.class).get();
}
}
return server;
});
try (AutoCloseable weldInitHandle = Performance.time("Server start")) {
outerServer.start(true);
}
return outerServer;
});
} finally {
SwarmMetricsMessages.MESSAGES.bootPerformance(Performance.dump());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project Payara by payara.
the class ACCJCDIServiceImpl method createManagedObject.
@Override
public <T> JCDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) {
JCDIInjectionContext<T> context = null;
T managedObject = null;
try {
managedObject = createEEManagedObject(bundle.getManagedBeanByBeanClass(managedClass.getName()));
} catch (Exception e) {
e.printStackTrace();
}
WeldContainer wc = getWeldContainer();
if (wc != null) {
BeanManager beanManager = wc.getBeanManager();
AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(managedClass);
InjectionTarget<T> target = beanManager.createInjectionTarget(annotatedType);
CreationalContext<T> cc = beanManager.createCreationalContext(null);
target.inject(managedObject, cc);
if (invokePostConstruct) {
target.postConstruct(managedObject);
}
context = new JCDIInjectionContextImpl<>(target, cc, managedObject);
}
return context;
}
Aggregations