Search in sources :

Example 26 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class TransactionalInterceptorBase method resetTransactionOperationsManager.

void resetTransactionOperationsManager() {
    if (testTransactionManager != null) {
        // test
        return;
    }
    ComponentInvocation currentInvocation = getCurrentInvocation();
    if (currentInvocation == null) {
        // There should always be a currentInvocation and so this would seem a bug
        // but not a fatal one as app should not be relying on this, so log warning only
        _logger.log(WARNING, "TransactionalInterceptorBase.markThreadAsTransactional currentInvocation==null");
        return;
    }
    currentInvocation.setTransactionOperationsManager(preexistingTransactionOperationsManager);
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 27 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class BeanManagerNamingProxy method handle.

@Override
public Object handle(String name) throws NamingException {
    Object beanManager = null;
    if (BEAN_MANAGER_CONTEXT.equals(name)) {
        try {
            // 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());
                            // System.out.println("BeanManagerNamingProxy:: getting BeanManagerImpl for" + bda);
                            beanManager = bootstrap.getManager(bda);
                        }
                    }
                    if (beanManager == null) {
                        throw new IllegalStateException("Cannot resolve bean manager");
                    }
                } else {
                    throw new IllegalStateException("No invocation context found");
                }
            }
        } catch (Throwable t) {
            NamingException ne = new NamingException("Error retrieving java:comp/BeanManager");
            ne.initCause(t);
            throw ne;
        }
    }
    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) NamingException(javax.naming.NamingException) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 28 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation 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 29 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation 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 30 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class JCDIServiceImpl method isCurrentModuleJCDIEnabled.

@Override
public boolean isCurrentModuleJCDIEnabled() {
    BundleDescriptor bundle = null;
    ComponentInvocation inv = invocationManager.getCurrentInvocation();
    if (inv == null) {
        return false;
    }
    JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId());
    if (componentEnv != null) {
        if (componentEnv instanceof BundleDescriptor) {
            bundle = (BundleDescriptor) componentEnv;
        } else if (componentEnv instanceof EjbDescriptor) {
            bundle = ((EjbDescriptor) componentEnv).getEjbBundleDescriptor();
        }
    }
    return (bundle != null) ? isJCDIEnabled(bundle) : false;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)67 InvocationManager (org.glassfish.api.invocation.InvocationManager)13 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)8 EjbInvocation (com.sun.ejb.EjbInvocation)7 InvocationException (org.glassfish.api.invocation.InvocationException)7 SecurityContext (com.sun.enterprise.security.SecurityContext)6 WebModule (com.sun.enterprise.web.WebModule)6 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)5 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)5 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)4 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)4 RemoteException (java.rmi.RemoteException)4 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)4 ArrayList (java.util.ArrayList)3 NamingException (javax.naming.NamingException)3 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)3 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)3