Search in sources :

Example 1 with SessionObjectReference

use of org.jboss.weld.ejb.api.SessionObjectReference 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;
}
Also used : SessionObjectReferenceImpl(org.glassfish.weld.ejb.SessionObjectReferenceImpl) SessionObjectReference(org.jboss.weld.ejb.api.SessionObjectReference) EjbContainerServices(org.glassfish.ejb.api.EjbContainerServices) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Aggregations

InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 EjbContainerServices (org.glassfish.ejb.api.EjbContainerServices)1 SessionObjectReferenceImpl (org.glassfish.weld.ejb.SessionObjectReferenceImpl)1 SessionObjectReference (org.jboss.weld.ejb.api.SessionObjectReference)1