AnsweredAssumed Answered

cdi-ejb integration problem

Question asked by knr on May 15, 2013
Latest reply on May 17, 2013 by ronnybr
Hi,
I'm facing problems accessing an ejb within a cdi bean. I want to call a delegate bean (as cdi defined) from a bpm process. This delegate bean should access an ejb. The ejb resolution results always as NULL.  How do I get the Ejb interface? Is there any workaround (through initialcontext or beanmanager) ?


Application-server: glassfish3.1.1
Activiti: 5.12.1
Java-EE: jee6
The ejb and cdi bean are in different jar's deployed

Here the code snipped

————————————————————————————
CustomerProfileBean
————————————————————————————
package ch.ti8m.channelBank.product.customerprofile;

import ch.ti8m.channelBank.product.customerprofile.jpa.CustomerProfile;
import ch.ti8m.channelBank.product.customerprofile.jpa.Persona;

import javax.inject.Named;

/**
* Interface defining the customerprofile interface.
* User: knr
* Date: 18.04.13
* Time: 11:17
*/
public interface CustomerprofileBean {

    /**
     * finds the CustomerProfile based on the login
     * @param login login information
     * @return the the customerprofile bean.
     */
    CustomerProfile findCustomerProfile(String login);

    /**
     * @param login user login name
     * @return the persona of the given user
     */
    Persona getPersona(final String login);
}


————————————————————————————
CustomerProfileTask
————————————————————————————

package ch.ti8m.channelBank.project.demo;

import ch.ti8m.channelBank.product.customerprofile.CustomerprofileBean;
import ch.ti8m.channelBank.product.customerprofile.jpa.CustomerProfile;
import ch.ti8m.channelBank.product.customerprofile.jpa.Persona;
import org.activiti.cdi.annotation.BusinessProcessScoped;

import javax.ejb.EJB;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.Serializable;

/**
* A delegate for {@link CustomerprofileBean} to activiti.
* User: ref
* Date: 13.05.13
* Time: 11:36
* <p/>
* {@see CustomerprofileBean}
*/
@Named
@BusinessProcessScoped
public class CustomerProfileTask implements Serializable{
// —————————— FIELDS ——————————

    private static final long serialVersionUID = 4555228521788025073L;
    @Inject
    BeanManager beanManager;
    @EJB(lookup = "java:global/complete-ear-glassfish.ear/customerprofile-impl-1.0-SNAPSHOT/CustomerprofileBeanImpl")
    CustomerprofileBean customerprofileBean;

// ————————– OTHER METHODS ————————–

    public CustomerProfile findCustomerProfile(final String login) {
        try {
            InitialContext context = new InitialContext();
            final Object customerProfileBean = context.lookup("customerProfileBean");
            return customerprofileBean.findCustomerProfile(login);
        } catch (NamingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            return null;
        }
    }

    /**
     * {@see CustomerprofileBean}
     */
    public Persona getPersona(final String login) {
        return customerprofileBean.getPersona(login);
    }
}


Outcomes