Search in sources :

Example 11 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class InjectionServicesImpl method aroundInject.

@Override
public <T> void aroundInject(InjectionContext<T> injectionContext) {
    try {
        ServiceLocator serviceLocator = Globals.getDefaultHabitat();
        ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class);
        EjbContainerServices containerServices = serviceLocator.getService(EjbContainerServices.class);
        JndiNameEnvironment componentEnv = compEnvManager.getCurrentJndiNameEnvironment();
        if (componentEnv == null) {
            InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
            if (invMgr.getCurrentInvocation() != null) {
                componentEnv = (JndiNameEnvironment) invMgr.<ComponentInvocation>getCurrentInvocation().getJNDIEnvironment();
            }
        }
        ManagedBeanDescriptor mbDesc = null;
        JndiNameEnvironment injectionEnv = (JndiNameEnvironment) bundleContext;
        AnnotatedType annotatedType = injectionContext.getAnnotatedType();
        Class targetClass = annotatedType.getJavaClass();
        String targetClassName = targetClass.getName();
        Object target = injectionContext.getTarget();
        if (isInterceptor(targetClass) && (componentEnv != null && !componentEnv.equals(injectionEnv))) {
            // Resources injected into interceptors must come from the environment in which the interceptor is
            // intercepting, not the environment in which the interceptor resides (for everything else!)
            // Must use the injectionEnv to get the injection info to determine where in jndi to look for the objects to inject.
            // must use the current jndi component env to lookup the objects to inject
            injectionManager.inject(targetClass, target, injectionEnv, null, false);
        } else {
            if (componentEnv == null) {
                // throw new IllegalStateException("No valid EE environment for injection of " + targetClassName);
                System.err.println("No valid EE environment for injection of " + targetClassName);
                injectionContext.proceed();
                return;
            }
            if (componentEnv instanceof EjbDescriptor) {
                EjbDescriptor ejbDesc = (EjbDescriptor) componentEnv;
                if (containerServices.isEjbManagedObject(ejbDesc, targetClass)) {
                    injectionEnv = componentEnv;
                } else {
                    if (bundleContext instanceof EjbBundleDescriptor) {
                        // Check if it's a @ManagedBean class within an ejb-jar.  In that case,
                        // special handling is needed to locate the EE env dependencies
                        mbDesc = bundleContext.getManagedBeanByBeanClass(targetClassName);
                    }
                }
            }
            if (mbDesc != null) {
                injectionManager.injectInstance(target, mbDesc.getGlobalJndiName(), false);
            } else {
                if (injectionEnv instanceof EjbBundleDescriptor) {
                    // set the environment of the ejb bundle.
                    if (target == null) {
                        injectionManager.injectClass(targetClass, compEnvManager.getComponentEnvId(injectionEnv), false);
                    } else {
                        injectionManager.injectInstance(target, compEnvManager.getComponentEnvId(injectionEnv), false);
                    }
                } else {
                    if (target == null) {
                        injectionManager.injectClass(targetClass, injectionEnv, false);
                    } else {
                        injectionManager.injectInstance(target, injectionEnv, false);
                    }
                }
            }
        }
        injectionContext.proceed();
    } catch (InjectionException ie) {
        throw new IllegalStateException(ie.getMessage(), ie);
    }
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) EjbContainerServices(org.glassfish.ejb.api.EjbContainerServices) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException)

Example 12 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class NonModuleInjectionServices method aroundInject.

@Override
public <T> void aroundInject(InjectionContext<T> injectionContext) {
    try {
        ServiceLocator serviceLocator = Globals.getDefaultHabitat();
        ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class);
        JndiNameEnvironment componentEnv = compEnvManager.getCurrentJndiNameEnvironment();
        Object target = injectionContext.getTarget();
        String targetClass = target.getClass().getName();
        if (componentEnv == null) {
            // throw new IllegalStateException("No valid EE environment for injection of " + targetClass);
            System.err.println("No valid EE environment for injection of " + targetClass);
            injectionContext.proceed();
            return;
        }
        injectionManager.injectInstance(target, componentEnv, false);
        injectionContext.proceed();
    } catch (InjectionException ie) {
        throw new IllegalStateException(ie.getMessage(), ie);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager)

Example 13 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class WebModuleContextConfig method start.

/**
 * Process a "start" event for this Context - in background
 */
@Override
protected synchronized void start() throws LifecycleException {
    configureResource();
    context.setConfigured(false);
    ComponentEnvManager namingMgr = services.getService(com.sun.enterprise.container.common.spi.util.ComponentEnvManager.class);
    if (namingMgr != null) {
        try {
            boolean webBundleContainsEjbs = (webBundleDescriptor.getExtensionsDescriptors(EjbBundleDescriptor.class).size() > 0);
            // EjbDeployer, so just add the dependencies from outside the .war
            if (webBundleContainsEjbs) {
                namingMgr.addToComponentNamespace(webBundleDescriptor, envProps, resRefs);
            } else {
                namingMgr.bindToComponentNamespace(webBundleDescriptor);
            }
            String componentId = namingMgr.getComponentEnvId(webBundleDescriptor);
            ((WebModule) context).setComponentId(componentId);
        } catch (NamingException ne) {
            throw new LifecycleException(ne);
        }
    }
    try {
        TomcatDeploymentConfig.configureWebModule((WebModule) context, webBundleDescriptor);
        authenticatorConfig();
        managerConfig();
        context.setConfigured(true);
    } catch (Throwable t) {
        // clean up naming in case of errors
        unbindFromComponentNamespace(namingMgr);
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else if (t instanceof LifecycleException) {
            throw (LifecycleException) t;
        } else {
            throw new LifecycleException(t);
        }
    }
}
Also used : ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) String(java.lang.String) java.util(java.util) NamingException(javax.naming.NamingException)

Aggregations

ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)13 NamingException (javax.naming.NamingException)4 WebServiceException (javax.xml.ws.WebServiceException)3 ManagedBeanManager (com.sun.enterprise.container.common.spi.ManagedBeanManager)2 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 java.util (java.util)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)1 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)1 SystemHandlerDelegate (com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)1 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)1 String (java.lang.String)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1