3 Replies Latest reply on May 12, 2009 3:25 PM by Fabrice Sommavilla

    Send email from Webservice on glassfish

    Fabrice Sommavilla Newbie

      Hi all,


      I'm runnning my web application on Glassfish. Some functionalities are used in a Webservices way. Everything works find, excepted that on webservice facade, I don't have access to seam session object and I can't send email.
      To perform all database access, I use simple DAO object.

      The MailDAO which is supposed to send ashyncrohous email is the following:



      @AutoCreate
      @Name("mailDao")
      @Scope(CONVERSATION)
      public class MailDAO {
      
           @Logger
           Log log;
      
           @In(create = true)
           private Renderer renderer;
      
           @Asynchronous
           public void sendMailRegister(@Duration long delay, User user,
                     UserAccount userAccount) {
                try {
                     Contexts.getEventContext().set("username", userAccount.getUsername());
                     Contexts.getEventContext().set("firstname", userAccount.getFirstname());
                     Contexts.getEventContext().set("email", user.getEmail());
                     renderer.render("/mails/confirm-register-mail.xhtml");
                } catch (Exception e) {
                     e.printStackTrace();
                }
           }
      
      }




      And I get the following error:


      java.lang.NullPointerException
           at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:887)
           at javax.mail.internet.InternetAddress.validate(InternetAddress.java:870)
           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 org.jboss.seam.ui.util.JSF.renderChild(JSF.java:175)
           at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
           at org.jboss.seam.ui.facelet.RendererRequest.renderFacelet(RendererRequest.java:103)
           at org.jboss.seam.ui.facelet.RendererRequest.run(RendererRequest.java:73)
           at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:43)
           at org.mobyview.platform.crm.entity.dao.MailDAO.sendMailRegister(MailDAO.java:40)
           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.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at org.mobyview.platform.crm.entity.dao.MailDAO_$$_javassist_22.sendMailRegister(MailDAO_$$_javassist_22.java)
           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.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
           at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
           at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
           at org.jboss.seam.async.ThreadPoolDispatcher$RunnableAsynchronous.run(ThreadPoolDispatcher.java:136)
           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
           at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
           at java.util.concurrent.FutureTask.run(FutureTask.java:123)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:65)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:168)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
           at java.lang.Thread.run(Thread.java:613)




      I use Glassfish v2ur2 and seam 2.1.


      Thanks in advance


      Fabrice

        • 2. Re: Send email from Webservice on glassfish
          Tomaz Cerar Master

          are you sure email address is not null?

          • 3. Re: Send email from Webservice on glassfish
            Fabrice Sommavilla Newbie

            solved with a DAO:



            @AutoCreate
            @Name("mailDao")
            @Scope(CONVERSATION)
            public class MailDAO implements Serializable {
            
                 
                 private static final long serialVersionUID = 1L;
            
                 @Logger
                 Log log;
            
                 @In
                 private Renderer renderer;
            
                 @In
                 private FacesMessages facesMessages;
            
                 @Asynchronous
                 public void sendMailRegister(@Duration long delay, User user,
                           UserAccount userAccount, String password, boolean isWS) {
                      try {
                           Contexts.getEventContext().set("username",
                                     userAccount.getUsername());
                           Contexts.getEventContext().set("firstname",
                                     userAccount.getFirstname());
                           Contexts.getEventContext().set("email", user.getEmail());
                           Contexts.getEventContext().set("password", password);
                           
                           renderer.render("/mails/confirm-register-mail.xhtml");
                           
                           if(!isWS)
                                facesMessages.add("Email sent successfully");
                           
                      } catch (Exception e) {
                           e.printStackTrace();
                           if(!isWS)
                                facesMessages.add("Email sending failed: " + e.getMessage());
                      }
                 }
            }