Search in sources :

Example 26 with BundleDescriptor

use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.

the class ManagedBeanManagerImpl method destroyManagedBean.

public void destroyManagedBean(Object managedBean, boolean validate) {
    BundleDescriptor bundle = getBundle();
    JCDIService jcdiService = habitat.getService(JCDIService.class);
    if ((jcdiService != null) && jcdiService.isJCDIEnabled(bundle)) {
        Map<Object, JCDIService.JCDIInjectionContext> bundleNonManagedObjs = jcdiManagedBeanInstanceMap.get(bundle);
        // in a failure scenario it's possible that bundleNonManagedObjs is null
        if (bundleNonManagedObjs == null) {
            if (validate) {
                throw new IllegalStateException("Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
            }
            _logger.log(Level.FINE, "Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
        } else {
            JCDIService.JCDIInjectionContext context = bundleNonManagedObjs.remove(managedBean);
            if (context == null) {
                if (validate) {
                    throw new IllegalStateException("Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
                }
                _logger.log(Level.FINE, "Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
                return;
            }
            // Call PreDestroy and cleanup
            context.cleanup(true);
        }
    } else {
        Object managedBeanInstance = null;
        try {
            Field proxyField = managedBean.getClass().getDeclaredField("__ejb31_delegate");
            final Field finalF = proxyField;
            java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {

                public java.lang.Object run() throws Exception {
                    if (!finalF.isAccessible()) {
                        finalF.setAccessible(true);
                    }
                    return null;
                }
            });
            Proxy proxy = (Proxy) proxyField.get(managedBean);
            InterceptorInvoker invoker = (InterceptorInvoker) Proxy.getInvocationHandler(proxy);
            managedBeanInstance = invoker.getTargetInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException("invalid managed bean " + managedBean, e);
        }
        ManagedBeanDescriptor desc = bundle.getManagedBeanByBeanClass(managedBeanInstance.getClass().getName());
        if (desc == null) {
            throw new IllegalStateException("Could not retrieve managed bean descriptor for " + managedBean + " of class " + managedBean.getClass());
        }
        InterceptorInvoker invoker = (InterceptorInvoker) desc.getSupportingInfoForBeanInstance(managedBeanInstance);
        try {
            invoker.invokePreDestroy();
        } catch (Exception e) {
            _logger.log(Level.FINE, "Managed bean " + desc.getBeanClassName() + " PreDestroy", e);
        }
        desc.clearBeanInstanceInfo(managedBeanInstance);
    }
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) InterceptorInvoker(com.sun.enterprise.container.common.spi.InterceptorInvoker) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) Field(java.lang.reflect.Field) Proxy(java.lang.reflect.Proxy) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy)

Example 27 with BundleDescriptor

use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.

the class ManagedBeanManagerImpl method unloadManagedBeans.

public void unloadManagedBeans(Application app) {
    for (BundleDescriptor bundle : app.getBundleDescriptors()) {
        if (!bundleEligible(bundle)) {
            continue;
        }
        Map<Object, JCDIService.JCDIInjectionContext> jcdiInstances = jcdiManagedBeanInstanceMap.remove(bundle);
        if (jcdiInstances != null) {
            for (JCDIService.JCDIInjectionContext next : jcdiInstances.values()) {
                try {
                    next.cleanup(true);
                } catch (Exception e) {
                    _logger.log(Level.FINE, "Exception during JCDI cleanup for " + next, e);
                }
            }
        }
        for (ManagedBeanDescriptor next : bundle.getManagedBeans()) {
            for (Object instance : next.getBeanInstances()) {
                InterceptorInvoker invoker = (InterceptorInvoker) next.getSupportingInfoForBeanInstance(instance);
                try {
                    invoker.invokePreDestroy();
                } catch (Exception e) {
                    _logger.log(Level.FINE, "Managed bean " + next.getBeanClassName() + " PreDestroy", e);
                }
            }
            com.sun.enterprise.container.common.spi.util.ComponentEnvManager compEnvManager = habitat.getService(com.sun.enterprise.container.common.spi.util.ComponentEnvManager.class);
            try {
                compEnvManager.unbindFromComponentNamespace(next);
            } catch (javax.naming.NamingException ne) {
                _logger.log(Level.FINE, "Managed bean " + next.getBeanClassName() + " unbind", ne);
            }
            org.glassfish.api.naming.GlassfishNamingManager namingManager = habitat.getService(org.glassfish.api.naming.GlassfishNamingManager.class);
            String jndiName = next.getGlobalJndiName();
            if (processType.isServer()) {
                try {
                    namingManager.unpublishObject(jndiName);
                } catch (javax.naming.NamingException ne) {
                    _logger.log(Level.FINE, "Error unpubishing managed bean " + next.getBeanClassName() + " with jndi name " + jndiName, ne);
                }
            } else {
                appClientManagedBeans.remove(jndiName);
            }
            next.clearAllBeanInstanceInfo();
        }
    }
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) InterceptorInvoker(com.sun.enterprise.container.common.spi.InterceptorInvoker) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) GlassfishNamingManager(org.glassfish.api.naming.GlassfishNamingManager)

Example 28 with BundleDescriptor

use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.

the class InboundRecoveryHandler method getEjbDescriptors.

private Vector getEjbDescriptors(Application application, ApplicationRegistry appsRegistry) {
    Vector ejbDescriptors = new Vector();
    if (ResourcesUtil.createInstance().isEnabled(application)) {
        ApplicationInfo appInfo = appsRegistry.get(application.getName());
        // non java-ee apps do not have ejbs, and they dont't have Application entry, leading to NPE
        if (appInfo != null && appInfo.isJavaEEApp()) {
            com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
            Set<BundleDescriptor> descriptors = app.getBundleDescriptors();
            for (BundleDescriptor descriptor : descriptors) {
                if (descriptor instanceof EjbBundleDescriptor) {
                    EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) descriptor;
                    Set<? extends EjbDescriptor> ejbDescriptorsSet = ejbBundleDescriptor.getEjbs();
                    for (EjbDescriptor ejbDescriptor : ejbDescriptorsSet) {
                        ejbDescriptors.add(ejbDescriptor);
                    }
                }
            }
        } else {
            // application is enabled, but still not found in app-registry
            _logger.log(Level.WARNING, "application.not.started.skipping.recovery", application.getName());
        }
    }
    return ejbDescriptors;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 29 with BundleDescriptor

use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method detectReferredRARs.

/**
 * {@inheritDoc}
 */
public void detectReferredRARs(String appName) {
    ApplicationInfo appInfo = appRegistry.get(appName);
    // call to detectReferredRAs can be called only when appInfo is available
    if (appInfo == null) {
        throw new IllegalStateException("ApplicationInfo is not available for application [ " + appName + " ]");
    }
    Application app = appInfo.getMetaData(Application.class);
    if (!appInfo.isJavaEEApp()) {
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("Application [" + appName + "] is not a Java EE application, skipping " + "resource-adapter references detection");
        }
        return;
    }
    // Iterate through all bundle descriptors, ejb-descriptors, managed-bean descriptors
    // for references to resource-adapters
    // 
    // References can be via :
    // resource-ref
    // resource-env-ref
    // ra-mid
    // 
    // Resource definition can be found in :
    // domain.xml
    // sun-ra.xml
    // default connector resource
    // handle application.xml bundle descriptor
    processDescriptorForRAReferences(app, null, app);
    Collection<BundleDescriptor> bundleDescriptors = app.getBundleDescriptors();
    // bundle descriptors
    for (BundleDescriptor bundleDesc : bundleDescriptors) {
        String moduleName = getModuleName(bundleDesc, app);
        processDescriptorForRAReferences(app, bundleDesc, moduleName);
        Collection<RootDeploymentDescriptor> dds = bundleDesc.getExtensionsDescriptors();
        if (dds != null) {
            for (RootDeploymentDescriptor dd : dds) {
                processDescriptorForRAReferences(app, dd, moduleName);
            }
        }
    }
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Application(com.sun.enterprise.deployment.Application)

Example 30 with BundleDescriptor

use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.

the class ManagedBeanManagerImpl method loadManagedBeans.

public void loadManagedBeans(Application app) {
    JCDIService jcdiService = habitat.getService(JCDIService.class);
    for (BundleDescriptor bundle : app.getBundleDescriptors()) {
        if (!bundleEligible(bundle)) {
            continue;
        }
        boolean isCDIBundle = (jcdiService != null && jcdiService.isJCDIEnabled(bundle));
        for (ManagedBeanDescriptor next : bundle.getManagedBeans()) {
            try {
                Set<String> interceptorClasses = next.getAllInterceptorClasses();
                Class targetClass = bundle.getClassLoader().loadClass(next.getBeanClassName());
                InterceptorInfo interceptorInfo = new InterceptorInfo();
                interceptorInfo.setTargetClass(targetClass);
                interceptorInfo.setInterceptorClassNames(interceptorClasses);
                interceptorInfo.setAroundConstructInterceptors(next.getAroundConstructCallbackInterceptors(targetClass, getConstructor(targetClass, isCDIBundle)));
                interceptorInfo.setPostConstructInterceptors(next.getCallbackInterceptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT));
                interceptorInfo.setPreDestroyInterceptors(next.getCallbackInterceptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY));
                if (next.hasAroundInvokeMethod()) {
                    interceptorInfo.setHasTargetClassAroundInvoke(true);
                }
                Map<Method, List> interceptorChains = new HashMap<Method, List>();
                for (Method m : targetClass.getMethods()) {
                    interceptorChains.put(m, next.getAroundInvokeInterceptors(m));
                }
                interceptorInfo.setAroundInvokeInterceptorChains(interceptorChains);
                // TODO can optimize this out for the non-JAXRS, non-application specified interceptor case
                interceptorInfo.setSupportRuntimeDelegate(true);
                JavaEEInterceptorBuilderFactory interceptorBuilderFactory = habitat.getService(JavaEEInterceptorBuilderFactory.class);
                JavaEEInterceptorBuilder builder = interceptorBuilderFactory.createBuilder(interceptorInfo);
                next.setInterceptorBuilder(builder);
                compEnvManager.bindToComponentNamespace(next);
                String jndiName = next.getGlobalJndiName();
                ManagedBeanNamingProxy namingProxy = new ManagedBeanNamingProxy(next, habitat);
                if (processType.isServer()) {
                    namingManager.publishObject(jndiName, namingProxy, true);
                } else {
                    // Can't store them in server's global naming service so keep
                    // them in local map.
                    appClientManagedBeans.put(jndiName, namingProxy);
                }
            } catch (Exception e) {
                throw new RuntimeException("Error binding ManagedBean " + next.getBeanClassName() + " with name = " + next.getName(), e);
            }
        }
        jcdiManagedBeanInstanceMap.put(bundle, Collections.synchronizedMap(new HashMap<Object, JCDIService.JCDIInjectionContext>()));
    }
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) HashMap(java.util.HashMap) InterceptorInfo(com.sun.enterprise.container.common.spi.util.InterceptorInfo) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) Method(java.lang.reflect.Method) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) JavaEEInterceptorBuilderFactory(com.sun.enterprise.container.common.spi.JavaEEInterceptorBuilderFactory) JavaEEInterceptorBuilder(com.sun.enterprise.container.common.spi.JavaEEInterceptorBuilder) List(java.util.List)

Aggregations

BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)51 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)24 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)24 Application (com.sun.enterprise.deployment.Application)17 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)10 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)9 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)8 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)7 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)7 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)7 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)6 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)5 InterceptorInvoker (com.sun.enterprise.container.common.spi.InterceptorInvoker)4 HashSet (java.util.HashSet)4 JavaEEInterceptorBuilder (com.sun.enterprise.container.common.spi.JavaEEInterceptorBuilder)3 File (java.io.File)3 IOException (java.io.IOException)3