Search in sources :

Example 46 with WeldContainer

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);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 47 with WeldContainer

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);
    }
}
Also used : Listener(org.jboss.weld.environment.servlet.Listener) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 48 with WeldContainer

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);
    }
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Fabric8Extension(io.fabric8.cdi.Fabric8Extension) Bean(javax.enterprise.inject.spi.Bean)

Example 49 with WeldContainer

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());
    }
}
Also used : InterfaceExtension(org.wildfly.swarm.container.runtime.cdi.InterfaceExtension) OutboundSocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.OutboundSocketBindingExtension) FractionProducingExtension(org.wildfly.swarm.container.runtime.cdi.FractionProducingExtension) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ConfigViewProducingExtension(org.wildfly.swarm.container.runtime.cdi.ConfigViewProducingExtension) Weld(org.jboss.weld.environment.se.Weld) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) DeploymentScopedExtension(org.wildfly.swarm.container.runtime.cdi.DeploymentScopedExtension) DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) XMLConfigProducingExtension(org.wildfly.swarm.container.runtime.cdi.XMLConfigProducingExtension) ImplicitArchiveExtension(org.wildfly.swarm.container.runtime.cdi.ImplicitArchiveExtension) CommandLineArgsExtension(org.wildfly.swarm.container.runtime.cli.CommandLineArgsExtension) ConfigurableExtension(org.wildfly.swarm.container.runtime.cdi.configurable.ConfigurableExtension) Module(org.jboss.modules.Module) OutboundSocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.OutboundSocketBindingExtension) SocketBindingExtension(org.wildfly.swarm.container.runtime.cdi.SocketBindingExtension)

Example 50 with WeldContainer

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;
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) NamingException(javax.naming.NamingException)

Aggregations

WeldContainer (org.jboss.weld.environment.se.WeldContainer)115 Weld (org.jboss.weld.environment.se.Weld)100 Test (org.junit.Test)98 CountDownLatch (java.util.concurrent.CountDownLatch)8 Bean (javax.enterprise.inject.spi.Bean)8 BeanManager (javax.enterprise.inject.spi.BeanManager)8 Type (java.lang.reflect.Type)7 URLClassLoader (java.net.URLClassLoader)7 ArrayList (java.util.ArrayList)7 URL (java.net.URL)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)6 Fabric8Extension (io.fabric8.cdi.Fabric8Extension)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)4 CreationalContext (javax.enterprise.context.spi.CreationalContext)4 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 PrintStream (java.io.PrintStream)3 ServiceRegistry (org.jboss.weld.bootstrap.api.ServiceRegistry)3