Search in sources :

Example 36 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class WeldDeployer method load.

/**
 * Processing in this method is performed for each module that is in the process of being loaded by
 * the container.
 *
 * <p>
 * This method will collect information from each archive (module) and produce
 * <code>BeanDeploymentArchive</code> information for each module.
 * </p>
 *
 * <p>
 * The
 * <code>BeanDeploymentArchive</code>s are stored in the <code>Deployment</code> (that will
 * eventually be handed off to <code>Weld</code>. Once this method is called for all modules (and
 * <code>BeanDeploymentArchive</code> information has been collected for all <code>Weld</code>
 * modules), a relationship structure is produced defining the accessiblity rules for the
 * <code>BeanDeploymentArchive</code>s.
 * </p>
 *
 * @param container
 * @param context
 * @return
 */
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
    DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
    ApplicationInfo applicationInfo = applicationRegistry.get(deployParams.name);
    ReadableArchive archive = context.getSource();
    boolean[] setTransientAppMetaData = { false };
    // See if a WeldBootsrap has already been created - only want one per app.
    WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData);
    EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
    EjbServices ejbServices = null;
    Set<EjbDescriptor> ejbs = new HashSet<>();
    if (ejbBundle != null) {
        ejbs.addAll(ejbBundle.getEjbs());
        ejbServices = new EjbServicesImpl(services);
    }
    // Create a deployment collecting information from the ReadableArchive (archive)
    // If the archive is a composite, or has version numbers per maven conventions, strip them out
    String archiveName = getArchiveName(context, applicationInfo, archive);
    DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
    if (deploymentImpl == null) {
        deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class));
        // Add services
        TransactionServices transactionServices = new TransactionServicesImpl(services);
        deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
        SecurityServices securityServices = new SecurityServicesImpl();
        deploymentImpl.getServices().add(SecurityServices.class, securityServices);
        ProxyServices proxyServices = new ProxyServicesImpl(services);
        deploymentImpl.getServices().add(ProxyServices.class, proxyServices);
        try {
            ExecutorServices executorServices = new ExecutorServicesImpl();
            deploymentImpl.getServices().add(ExecutorServices.class, executorServices);
        } catch (NamingException ex) {
            throw new RuntimeException(ex);
        }
        addWeldListenerToAllWars(context);
    } else {
        deploymentImpl.scanArchive(archive, ejbs, context, archiveName);
    }
    deploymentImpl.addDeployedEjbs(ejbs);
    if (ejbBundle != null && (!deploymentImpl.getServices().contains(EjbServices.class))) {
        // EJB Services is registered as a top-level service
        deploymentImpl.getServices().add(EjbServices.class, ejbServices);
    }
    ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
    externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
    externalConfiguration.setBeanIndexOptimization(!deployParams.isAvailabilityEnabled());
    externalConfiguration.setNonPortableMode(false);
    configureConcurrentDeployment(context, externalConfiguration);
    deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);
    BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
    if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
        if (setTransientAppMetaData[0]) {
            // Do this only if we have a root BDA
            appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap);
            applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
        }
        WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class);
        boolean developmentMode = isDevelopmentMode(context);
        if (webBundleDescriptor != null) {
            webBundleDescriptor.setExtensionProperty(WELD_EXTENSION, "true");
            // Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
            // able to do it.
            webBundleDescriptor.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
            // Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
            // for JSP's..
            webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_CONTEXT_LISTENER));
            // Weld 2.2.1.Final. There is a tck test for this:
            // org.jboss.cdi.tck.tests.context.session.listener.SessionContextHttpSessionListenerTest
            // This WeldTerminationListener must come after all application-defined listeners
            webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WeldTerminationListenerProxy.class.getName()));
            // Adding Weld ConverstationFilter if there is a filterMapping for it and it doesn't exist already.
            // However, it will be applied only if web.xml has a mapping for it.
            // Doing this here to make sure that its done only for CDI enabled web applications
            registerWeldConversationFilter(webBundleDescriptor);
            // every deployment
            if (developmentMode) {
                registerProbeFilter(webBundleDescriptor);
            }
        }
        if (developmentMode) {
            registerProbeExtension(externalConfiguration, deploymentImpl);
        }
        BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle;
        if (bundle != null) {
            if (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
                // Register EE injection manager at the bean deployment archive level.
                // We use the generic InjectionService service to handle all EE-style
                // injection instead of the per-dependency-type InjectionPoint approach.
                // Each InjectionServicesImpl instance knows its associated GlassFish bundle.
                InjectionServices injectionServices = new InjectionServicesImpl(deploymentImpl.injectionManager, bundle, deploymentImpl);
                ResourceInjectionServicesImpl resourceInjectionServices = new ResourceInjectionServicesImpl();
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, beanDeploymentArchive.getId() });
                }
                beanDeploymentArchive.getServices().add(InjectionServices.class, injectionServices);
                beanDeploymentArchive.getServices().add(ResourceInjectionServices.class, resourceInjectionServices);
                EEModuleDescriptor eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
                if (eeModuleDescriptor != null) {
                    beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
                }
                // Relevant in WAR BDA - WEB-INF/lib BDA scenarios
                for (BeanDeploymentArchive subBda : beanDeploymentArchive.getBeanDeploymentArchives()) {
                    if (logger.isLoggable(FINE)) {
                        logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, subBda.getId() });
                    }
                    subBda.getServices().add(InjectionServices.class, injectionServices);
                    // Should not be subBda?
                    eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
                    if (eeModuleDescriptor != null) {
                        beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
                    }
                }
            }
            bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
        }
    }
    context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
    applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
    return new WeldApplicationContainer();
}
Also used : ProxyServices(org.jboss.weld.serialization.spi.ProxyServices) SecurityServices(org.jboss.weld.security.spi.SecurityServices) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) InjectionServices(org.jboss.weld.injection.spi.InjectionServices) ResourceInjectionServices(org.jboss.weld.injection.spi.ResourceInjectionServices) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) NamingException(javax.naming.NamingException) HashSet(java.util.HashSet) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbServices(org.jboss.weld.ejb.spi.EjbServices) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) AppListenerDescriptorImpl(org.glassfish.web.deployment.descriptor.AppListenerDescriptorImpl) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor)

Example 37 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class JCDIServiceImpl method createManagedObject.

@Override
public <T> JCDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) {
    T managedObject;
    BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor();
    // First get BeanDeploymentArchive for this ejb
    BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc);
    WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
    BeanManager beanManager = bootstrap.getManager(bda);
    AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(managedClass);
    if (!invokePostConstruct) {
        annotatedType = new NoPostConstructPreDestroyAnnotatedType<>(annotatedType);
    }
    @SuppressWarnings("unchecked") InjectionTarget<T> it = (InjectionTarget<T>) ((BeanDeploymentArchiveImpl) bda).getInjectionTarget(annotatedType);
    if (it == null) {
        it = ((WeldManager) beanManager).fireProcessInjectionTarget(annotatedType);
    }
    CreationalContext<T> cc = beanManager.createCreationalContext(null);
    managedObject = it.produce(cc);
    it.inject(managedObject, cc);
    if (invokePostConstruct) {
        it.postConstruct(managedObject);
    }
    return new JCDIInjectionContextImpl<>(it, cc, managedObject);
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) WeldInjectionTarget(org.jboss.weld.manager.api.WeldInjectionTarget)

Example 38 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class JCDIServiceImpl method _createJCDIInjectionContext.

// instance could be null. If null, create a new one
@SuppressWarnings("unchecked")
private <T> JCDIInjectionContext<T> _createJCDIInjectionContext(EjbDescriptor ejb, T instance, Map<Class<?>, Object> ejbInfo) {
    BaseContainer baseContainer = null;
    EJBContextImpl ejbContext = null;
    JCDIInjectionContextImpl<T> jcdiCtx = null;
    CreationalContext<T> creationalContext = null;
    if (ejbInfo != null) {
        baseContainer = (BaseContainer) ejbInfo.get(BaseContainer.class);
        ejbContext = (EJBContextImpl) ejbInfo.get(EJBContextImpl.class);
    }
    BundleDescriptor topLevelBundleDesc = (BundleDescriptor) ejb.getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
    // First get BeanDeploymentArchive for this ejb
    BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName());
    WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication());
    WeldManager weldManager = bootstrap.getManager(bda);
    // when calling _createJCDIInjectionContext
    if (weldManager == null) {
        logger.severe("The reference for weldManager is not available, this is an un-sync state of the container");
        return null;
    }
    org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = weldManager.getEjbDescriptor(ejb.getName());
    // get or create the ejb's creational context
    if (null != ejbInfo) {
        jcdiCtx = (JCDIInjectionContextImpl<T>) ejbInfo.get(JCDIService.JCDIInjectionContext.class);
    }
    if (null != jcdiCtx) {
        creationalContext = jcdiCtx.getCreationalContext();
    }
    if (null != jcdiCtx && creationalContext == null) {
        // The creational context may have been created by interceptors because they are created first
        // (see createInterceptorInstance below.)
        // And we only want to create the ejb's creational context once or we will have a memory
        // leak there too.
        Bean<T> bean = weldManager.getBean(ejbDesc);
        creationalContext = weldManager.createCreationalContext(bean);
        jcdiCtx.setCreationalContext(creationalContext);
    }
    // Create the injection target
    InjectionTarget<T> it = null;
    if (ejbDesc.isMessageDriven()) {
        // message driven beans are non-contextual and therefore createInjectionTarget is not appropriate
        it = createMdbInjectionTarget(weldManager, ejbDesc);
    } else {
        it = weldManager.createInjectionTarget(ejbDesc);
    }
    if (null != jcdiCtx) {
        jcdiCtx.setInjectionTarget(it);
    }
    // JJS: 7/20/17 We must perform the around_construct interception because Weld does not know about
    // interceptors defined by descriptors.
    WeldCreationalContext<T> weldCreationalContext = (WeldCreationalContext<T>) creationalContext;
    weldCreationalContext.setConstructorInterceptionSuppressed(true);
    JCDIAroundConstructCallback<T> aroundConstructCallback = new JCDIAroundConstructCallback<>(baseContainer, ejbContext);
    weldCreationalContext.registerAroundConstructCallback(aroundConstructCallback);
    if (null != jcdiCtx) {
        jcdiCtx.setJCDIAroundConstructCallback(aroundConstructCallback);
    }
    T beanInstance = instance;
    if (null != jcdiCtx) {
        jcdiCtx.setInstance(beanInstance);
    }
    return jcdiCtx;
// Injection is not performed yet. Separate injectEJBInstance() call is required.
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) javax.enterprise.inject.spi(javax.enterprise.inject.spi) WeldManager(org.jboss.weld.manager.api.WeldManager) BaseContainer(com.sun.ejb.containers.BaseContainer) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 39 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class JCDIServiceImpl method injectManagedObject.

/**
 * Perform 299 style injection on the <code>managedObject</code> argument.
 * @param <T> instance type
 * @param managedObject the managed object
 * @param bundle  the bundle descriptor
 */
@Override
public <T> void injectManagedObject(T managedObject, BundleDescriptor bundle) {
    BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor();
    // First get BeanDeploymentArchive for this ejb
    BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc);
    // BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName());
    WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
    BeanManager beanManager = bootstrap.getManager(bda);
    @SuppressWarnings("unchecked") AnnotatedType<T> annotatedType = beanManager.createAnnotatedType((Class<T>) managedObject.getClass());
    InjectionTarget<T> it = beanManager.createInjectionTarget(annotatedType);
    CreationalContext<T> cc = beanManager.createCreationalContext(null);
    it.inject(managedObject, cc);
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 40 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class BeanDeploymentArchiveImpl method toString.

// A graphical representation of the BDA hierarchy to aid in debugging
// and to provide a better representation of how Weld treats the deployed
// archive.
@Override
public String toString() {
    String beanClassesString = ((getBeanClasses().size() > 0) ? getBeanClasses().toString() : "");
    String initVal = "|ID: " + getId() + ", bdaType= " + bdaType + ", accessibleBDAs #:" + getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(this) + ", Bean Classes #: " + getBeanClasses().size() + "," + beanClassesString + ", ejbs=" + getEjbs() + "\n";
    StringBuilder valBuff = new StringBuilder(initVal);
    Collection<BeanDeploymentArchive> bdas = getBeanDeploymentArchives();
    Iterator<BeanDeploymentArchive> iter = bdas.iterator();
    while (iter.hasNext()) {
        BeanDeploymentArchive bda = (BeanDeploymentArchive) iter.next();
        BDAType embedBDAType = BDAType.UNKNOWN;
        if (bda instanceof BeanDeploymentArchiveImpl) {
            embedBDAType = ((BeanDeploymentArchiveImpl) bda).getBDAType();
        }
        String embedBDABeanClasses = ((bda.getBeanClasses().size() > 0) ? bda.getBeanClasses().toString() : "");
        String val = "|---->ID: " + bda.getId() + ", bdaType= " + embedBDAType.toString() + ", accessibleBDAs #:" + bda.getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(bda) + ", Bean Classes #: " + bda.getBeanClasses().size() + "," + embedBDABeanClasses + ", ejbs=" + bda.getEjbs() + "\n";
        valBuff.append(val);
    }
    return valBuff.toString();
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)47 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)11 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 HashSet (java.util.HashSet)7 Deployment (org.jboss.weld.bootstrap.spi.Deployment)7 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)6 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)6 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)6 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)6 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)6 Test (org.testng.annotations.Test)6 BeanManager (javax.enterprise.inject.spi.BeanManager)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)4 Test (org.junit.Test)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2