3 Replies Latest reply on Mar 15, 2007 7:16 PM by bsmithjj

    Email Listening MDB Accessing Seam Components

    djeverson

      We are getting a Null Pointer Exception in an MDB that is listening for emails.

      It appears that the Seam components are not being properly injected. We get errors when we attempt to use @Logger. We have changed these for the time being to System.out.printlns. Our service EJB components are not getting injected either.

      Our environment is Seam 1.1.7RC1, JBoss 4.0.5. The mail-ra.rar file has been placed in the server\default\deploy folder.

      The following is our MDB that is throwing the NPEs:

      package us.crimnet.iss.listeners;
      
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.ejb.Stateless;
      import javax.mail.Message;
      
      import org.jboss.annotation.ejb.ResourceAdapter;
      import org.jboss.mail.MailException;
      
      import org.jboss.resource.adapter.mail.inflow.MailListener;
      import org.jboss.seam.Component;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.ScopeType;
      
      import us.crimnet.iss.services.HistoryManagement;
      import us.crimnet.iss.services.impl.HistoryManagementImpl;
      
      @MessageDriven(activationConfig={
       @ActivationConfigProperty(propertyName="mailServer", propertyValue="domain.com"),
       @ActivationConfigProperty(propertyName="mailFolder", propertyValue="INBOX"),
       @ActivationConfigProperty(propertyName="storeProtocol", propertyValue="pop3"),
       @ActivationConfigProperty(propertyName="userName", propertyValue="uid"),
       @ActivationConfigProperty(propertyName="password", propertyValue="pwd")
      })
      
      @ResourceAdapter("mail-ra.rar")
      @Name("requestEmailListener")
      
      public class RequestEmailListener implements MailListener {
      
       @In(create=true)
       private HistoryManagement historyManagement;
      
       public void onMessage(Message message) {
       System.out.println("Can we inject the @Logger here???");
       System.out.println("RequestEmailListener.onMessage()");
       try {
       Long id = Long.parseLong(message.getSubject());
       System.out.println("History id [" + id + "]");
       //TODO : dj : The following line threw an NPE
       // was it not properly injected by Seam?
       historyManagement.sendRequest(id);
      
       System.out.println("back from HistoryManagement");
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      }
      


      Any suggestions as to what the causing the Seam Components not to be injected or initialized?

      Thanks!

        • 1. Re: Email Listening MDB Accessing Seam Components
          pmuir

          There is a bug in Jboss's ejb3 which means that interceptors aren't applied to non-jmx MDBs. This is fixed in AS 4.2. For now, you can get around it by putting a Lifecycle.beginCall and Lifecycle.endCall at the beginning and end of your onMessage method, and using Component.getInstance to access Seam components.

          • 2. Re: Email Listening MDB Accessing Seam Components
            smurfs

            Pete, I have come across this same problem using the EJB @Timeout annotation on a bean method. In my case the seam injected component was null within the scope of the annotated method only (the injected component worked perfectly in the other methods within the same bean!).

            By trial and error I established a workaround using an EJB jndi @Resource annotation, but this was a real hack as it bypasses Seam. Your tip works perfectly so thanks for sharing.

            Regards, Andrew

            • 3. Re: Email Listening MDB Accessing Seam Components

              Seam doesn't work with EJB Times (@Timeout methods) so yes, you need to use the EJB3 annotations like @Resource to inject your timer-bean dependencies.