use of org.glassfish.ejb.api.EjbContainerServices in project Payara by payara.
the class EjbServicesImpl method resolveEjb.
/**
* Request a reference to an EJB session object from the container. If the
* EJB being resolved is a stateful session bean, the container should
* ensure the session bean is created before this method returns.
*
* @param ejbDescriptor the ejb to resolve
* @return a reference to the session object
*/
@Override
public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor) {
SessionObjectReference sessionObj = null;
// All we need to do is create a reference based on one of the beans'
// client views, so just choose one and get its corresponding portable
// JNDI name.
String globalJndiName = getDefaultGlobalJndiName(ejbDescriptor);
if (globalJndiName != null) {
try {
InitialContext ic = new InitialContext();
Object ejbRef = ic.lookup(globalJndiName);
EjbContainerServices containerServices = services.getService(EjbContainerServices.class);
sessionObj = new SessionObjectReferenceImpl(containerServices, ejbRef);
} catch (NamingException ne) {
throw new IllegalStateException("Error resolving session object reference for ejb name " + ejbDescriptor.getBeanClass() + " and jndi name " + globalJndiName, ne);
}
} else {
throw new IllegalArgumentException("Not enough type information to resolve ejb for " + " ejb name " + ejbDescriptor.getBeanClass());
}
return sessionObj;
}
use of org.glassfish.ejb.api.EjbContainerServices 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);
}
}
Aggregations