4 Replies Latest reply on Feb 2, 2009 6:23 PM by Stephane DUCAS

    Email Problem

    Dylan Janeke Newbie
      Hi all, I am having some serious problems in sending email.. :-( not making me a happy guy - I want to just send out a test email messages to more than one recipient from the db , this is what I use:

      `

      @Name("emailService")
      @AutoCreate
      @Stateful
      @Scope(ScopeType.APPLICATION)
      public class EmailService implements EmailServiceLocal{
          @Logger Log log;
          @Remove public void remove(){}

          @In(create=true)
          Renderer renderer;

          @In(create=true)
          AuthenticatorLocal authenticator;

          @Out(required=true, value="eList",scope=ScopeType.APPLICATION)
          List<User_E> eList;

          @Asynchronous
          @Transactional
          public void sendMail(){
              if (eList == null || eList.size() < 1){
                  getMailUsers();
              }
              log.info("loading list into context");
              Contexts.getApplicationContext().set("eList", eList);
              log.info("--> outjected!");
              renderer.render("/statsEmailReport.xhtml");
          }

          @Factory("eList")
          public void getMailUsers() {
              List<User_E> allUsers = authenticator.fetchAllUsers();
              List<User_E> emailUsers=new ArrayList<User_E>();
              for(User_E user : allUsers){
                  if (user.getNotifyStats() == Boolean.TRUE){
                      emailUsers.add(user);
                  }
              }
              log.info("size of emailUsers -:" + eList.size());
              eList = emailUsers;
          }
      }

      `

      And the view I want to render is this one :

      =
      <ui:repeat xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:m="http://jboss.com/products/seam/mail"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 value="#{eList}" var="user">`
          <m:message>
          <m:from name="dylanjaneke" address="dylanjaneke@noreply.com" />
          <m:to name="#{user.fullname}" address="#{user.email}"/>
         
          <m:subject>Seam Email</m:subject>
          <m:body>
              <p><h:outputText value="Dear dude" /></p>
              <p>You can try out Seam by visiting<a href="http://labs.jboss.com/jbossseam">http://labs.jboss.com/jbossseam</a>.</p>
              <p>Regards,</p>
              <p> Dylan</p>
          </m:body>
      </m:message>
      </ui:repeat>
      =

      I keep getting the following error :


      `
      Caused by: java.lang.NullPointerException
           at util.EmailService.getMailUsers(EmailService.java:66)
           at util.EmailService.sendMail(EmailService.java:48)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
           at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:
      `

      I don't think that "eList" is actually outjected into the context? -or atleast the correct context , I once read something about a difference between the servlet context/ mock context. But I was sure that Contexts.getApplicationContext.set(...) would work, especially because I figured the view would be rendered before the variable get's outjected using the annotation.. that's just what I think.

      --> And sorry about the ugly formatting I couldn't get the view in here view backticks...

      Please let me know if you have any ideas.

      Thanks-
        • 1. Re: Email Problem
          Dylan Janeke Newbie

          Sorry guys I was being dumb there... I changed the class a bit :


              List<User_E> eList = new ArrayList<User_E>();
          
              @Asynchronous
              @Transactional
              public void sendMail(){
                  if (eList == null || eList.size() < 1){
                      getMailUsers();
                  }
                  log.info("loading list into context");
                  log.info("size before ojected -:" + eList.size());
                  Contexts.getApplicationContext().set("eList", eList);
                  log.info("--> outjected!");
                  renderer.render("/statsEmailReport.xhtml");
              }
          
              public void getMailUsers() {
                  List<User_E> allUsers = authenticator.fetchAllUsers();
                  List<User_E> emailUsers=new ArrayList<User_E>();
                  for(User_E user : allUsers){
                      log.info("check user -:" + user.getFullname() + ":" + user.getEmail() + ":" + user.getNotifyStats());
                      if (user.getNotifyStats() == Boolean.TRUE){
                          log.info("it want it!");
                          eList.add(user);
                      }
                  }
                  log.info("size of emailUsers -:" + eList.size());
              }
          
          



          And know I get


               at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
               at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
               at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
               at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
          Caused by: java.lang.NullPointerException
               at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:873)
               at javax.mail.internet.InternetAddress.validate(InternetAddress.java:856)
               at org.jboss.seam.mail.ui.AddressComponent.getInternetAddress(AddressComponent.java:39)
               at org.jboss.seam.mail.ui.RecipientAddressComponent.encodeBegin(RecipientAddressComponent.java:25)
               at org.jboss.seam.ui.util.JSF.renderChild(JSF.java:172)
               at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
               at org.jboss.seam.mail.ui.UIMessage.encodeChildren(UIMessage.java:192)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
               at com.sun.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:50)
               at com.sun.facelets.component.UIRepeat.process(UIRepeat.java:357)
               at com.sun.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:617)
               at org.jboss.seam.ui.util.JSF.renderChild(JSF.java:175)
               at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
          
          



          Before it get's outjected the list isnt null and it is populated!

          • 2. Re: Email Problem
            Daniel Roth Apprentice

            I think one of your users' email adress is Null. Break point and check that and/or just System.out every user.getEmail()

            • 3. Re: Email Problem
              Dylan Janeke Newbie

              Daniel Roth wrote on Jan 06, 2009 17:29:


              I think one of your users' email adress is Null. Break point and check that and/or just System.out every user.getEmail()


              HI Daniel ,


              Thanks for the reply - but I did check this :


                          log.info("check user -:" + user.getFullname() + ":" + user.getEmail() + ":" + user.getNotifyStats());
              
              



              And my user all had emails - but I managed a work around - I actually dropped the idea of trying to use the ui:repeat tag in the email facelet, and created a asynchronous method that loops through the list of users and re-renders the same email page with the single outjected user/ instead of passing a List of users and ui:repeating.. That actually solved it .. but once again thank you!

              • 4. Re: Email Problem
                Stephane DUCAS Newbie

                Hi all!


                It seems seam 2.1 definitly has problem with @Async, Email and ui:repeat tags:


                I try to log any activity on a session then email it to an administrator asynchronously when the session is terminated..


                When sending the email synchronously everything works find (WITH ui:repeat components in email template)..


                When sending the email asynchrnously WHTOUT any ui:repeat or datatable components everything works find..


                But when I had any ui:repeat component or datatables like that:


                <ui:repeat value="#{eMailData.viewRequests}" var="req">#{req.viewId}</ui:repeat>
                



                I have this:


                Caused by: java.lang.NullPointerException
                        at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:80)
                        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
                .....


                When debugging it appears that NPE is caused because Base is null when trying to evaluate the viewId property (Base is evaluation of req here).


                I haven't try to update to seam 2.1.1 yet...