Search in sources :

Example 6 with BeanDeploymentArchive

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

the class DeploymentImpl method createModuleBda.

private void createModuleBda(ReadableArchive archive, Collection<EjbDescriptor> ejbs, DeploymentContext context, String moduleName) {
    RootBeanDeploymentArchive rootBda = new RootBeanDeploymentArchive(archive, ejbs, context, moduleName);
    BeanDeploymentArchive moduleBda = rootBda.getModuleBda();
    BeansXml moduleBeansXml = moduleBda.getBeansXml();
    if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
        addBdaToDeploymentBdas(rootBda);
        addBdaToDeploymentBdas(moduleBda);
        addBeanDeploymentArchives(rootBda);
    }
    // first check if the parent is an ear and if so see if there are app libs defined there.
    if (!earContextAppLibBdasProcessed && context instanceof DeploymentContextImpl) {
        DeploymentContextImpl deploymentContext = (DeploymentContextImpl) context;
        DeploymentContext parentContext = deploymentContext.getParentContext();
        if (parentContext != null) {
            processBdasForAppLibs(parentContext.getSource(), parentContext);
            parentContext.getSource();
            earContextAppLibBdasProcessed = true;
        }
    }
    // then check the module
    processBdasForAppLibs(archive, context);
}
Also used : DeploymentContext(org.glassfish.api.deployment.DeploymentContext) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 7 with BeanDeploymentArchive

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

the class ValidationNamingProxy method obtainBeanManager.

/**
 * Obtain the BeanManagerNamingProxy from hk2, so the BeanManager can be looked up
 *
 * @throws NamingException
 */
private synchronized BeanManager obtainBeanManager() throws NamingException {
    BeanManager beanManager = null;
    // Use invocation context to find applicable BeanDeploymentArchive.
    ComponentInvocation inv = invocationManager.getCurrentInvocation();
    if (inv != null) {
        JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId());
        if (componentEnv != null) {
            BundleDescriptor bundle = null;
            if (componentEnv instanceof EjbDescriptor) {
                bundle = (BundleDescriptor) ((EjbDescriptor) componentEnv).getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
            } else if (componentEnv instanceof WebBundleDescriptor) {
                bundle = (BundleDescriptor) componentEnv;
            }
            if (bundle != null) {
                BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
                if (bda != null) {
                    WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
                    beanManager = bootstrap.getManager(bda);
                }
            }
        }
    }
    return beanManager;
}
Also used : WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) BeanManager(javax.enterprise.inject.spi.BeanManager) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 8 with BeanDeploymentArchive

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

the class WeldDeployer method processApplicationLoaded.

private void processApplicationLoaded(ApplicationInfo applicationInfo) {
    WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
    if (bootstrap != null) {
        DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
        deploymentImpl.buildDeploymentGraph();
        List<BeanDeploymentArchive> archives = deploymentImpl.getBeanDeploymentArchives();
        addResourceLoaders(archives);
        addCdiServicesToNonModuleBdas(deploymentImpl.getLibJarRootBdas(), services.getService(InjectionManager.class));
        addCdiServicesToNonModuleBdas(deploymentImpl.getRarRootBdas(), services.getService(InjectionManager.class));
        // Get current TCL
        ClassLoader oldTCL = Thread.currentThread().getContextClassLoader();
        invocationManager.pushAppEnvironment(() -> applicationInfo.getName());
        ComponentInvocation componentInvocation = createComponentInvocation(applicationInfo);
        try {
            bootstrap.startExtensions(postProcessExtensions(deploymentImpl.getExtensions(), archives));
            bootstrap.startContainer(deploymentImpl.getContextId() + ".bda", SERVLET, deploymentImpl);
            bootstrap.startInitialization();
            fireProcessInjectionTargetEvents(bootstrap, deploymentImpl);
            bootstrap.deployBeans();
            bootstrap.validateBeans();
            invocationManager.preInvoke(componentInvocation);
            bootstrap.endInitialization();
        } catch (Throwable t) {
            doBootstrapShutdown(applicationInfo);
            throw new DeploymentException(getDeploymentErrorMsgPrefix(t) + t.getMessage(), t);
        } finally {
            invocationManager.postInvoke(componentInvocation);
            invocationManager.popAppEnvironment();
            // The TCL is originally the EAR classloader and is reset during Bean deployment to the
            // corresponding module classloader in BeanDeploymentArchiveImpl.getBeans
            // for Bean classloading to succeed.
            // The TCL is reset to its old value here.
            Thread.currentThread().setContextClassLoader(oldTCL);
            deploymentComplete(deploymentImpl);
        }
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) DeploymentException(org.glassfish.deployment.common.DeploymentException) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 9 with BeanDeploymentArchive

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

the class JCDIServiceImpl method createInterceptorInstance.

/**
 * @param <T> interceptor type
 * @param interceptorClass The interceptor class.
 * @param ejb The ejb descriptor.
 * @param ejbContext The ejb jcdi context.  This context is only used to store any contexts for interceptors
 *                   not bound to the ejb.  Nothing else in this context will be used in this method as they are
 *                   most likely null.
 * @param ejbInterceptors All of the ejb interceptors for the ejb.
 *
 * @return The interceptor instance.
 */
@Override
@SuppressWarnings("unchecked")
public <T> T createInterceptorInstance(Class<T> interceptorClass, EjbDescriptor ejb, JCDIService.JCDIInjectionContext<T> ejbContext, Set<EjbInterceptor> ejbInterceptors) {
    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 beanManager = bootstrap.getManager(bda);
    org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = beanManager.getEjbDescriptor(ejb.getName());
    // get or create the ejb's creational context
    CreationalContext<T> creationalContext = ejbContext.getCreationalContext();
    if (creationalContext == null) {
        // We have to do this because interceptors are created before the ejb but in certain cases we must associate
        // the interceptors with the ejb so that they are cleaned up correctly.
        // And we only want to create the ejb's creational context once or we will have a memory
        // leak there too.
        Bean<T> bean = beanManager.getBean(ejbDesc);
        creationalContext = beanManager.createCreationalContext(bean);
        ejbContext.setCreationalContext(creationalContext);
    }
    // first see if there's an Interceptor object defined for the interceptorClass
    // This happens when @Interceptor or @InterceptorBinding is used.
    Interceptor<T> interceptor = findEjbInterceptor(interceptorClass, ejbInterceptors);
    if (interceptor != null) {
        // using the ejb's creationalContext so we don't have to do any cleanup.
        // the cleanup will be handled by weld when it clean's up the ejb.
        Object instance = beanManager.getReference(interceptor, interceptorClass, creationalContext);
        return (T) instance;
    }
    // Check to see if the interceptor was defined as a Bean.
    // This can happen when using @Interceptors to define the interceptors.
    Set<Bean<?>> availableBeans = beanManager.getBeans(interceptorClass);
    if (availableBeans != null && !availableBeans.isEmpty()) {
        // using the ejb's creationalContext so we don't have to do any cleanup.
        // the cleanup will be handled by weld when it clean's up the ejb.
        Bean<?> interceptorBean = beanManager.resolve(availableBeans);
        Object instance = beanManager.getReference(interceptorBean, interceptorClass, creationalContext);
        return (T) instance;
    }
    // There are other interceptors like SessionBeanInterceptor that are
    // defined via code and they are not beans.
    // Cannot use the ejb's creationalContext.
    creationalContext = beanManager.createCreationalContext(null);
    AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(interceptorClass);
    InjectionTarget<T> it = beanManager.getInjectionTargetFactory(annotatedType).createInterceptorInjectionTarget();
    T interceptorInstance = it.produce(creationalContext);
    it.inject(interceptorInstance, creationalContext);
    // make sure the interceptor's cdi objects get cleaned up when the ejb is cleaned up.
    ejbContext.addDependentContext(new JCDIInjectionContextImpl<>(it, creationalContext, interceptorInstance));
    return interceptorInstance;
}
Also used : WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) javax.enterprise.inject.spi(javax.enterprise.inject.spi) WeldManager(org.jboss.weld.manager.api.WeldManager) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 10 with BeanDeploymentArchive

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

the class BeanDeploymentArchiveImpl method formatAccessibleBDAs.

private String formatAccessibleBDAs(BeanDeploymentArchive bda) {
    StringBuffer sb = new StringBuffer("[");
    for (BeanDeploymentArchive accessibleBDA : bda.getBeanDeploymentArchives()) {
        if (accessibleBDA instanceof BeanDeploymentArchiveImpl) {
            sb.append(((BeanDeploymentArchiveImpl) accessibleBDA).getFriendlyId()).append(",");
        }
    }
    sb.append("]");
    return sb.toString();
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)22 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)9 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 javax.enterprise.inject.spi (javax.enterprise.inject.spi)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 InjectionServicesImpl (org.glassfish.weld.services.InjectionServicesImpl)2 WeldManager (org.jboss.weld.manager.api.WeldManager)2 BaseContainer (com.sun.ejb.containers.BaseContainer)1 EJBContextImpl (com.sun.ejb.containers.EJBContextImpl)1 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)1 Application (com.sun.enterprise.deployment.Application)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1