1 Reply Latest reply on Apr 5, 2007 7:30 AM by Pete Muir

    Sending (Seam) mail from a scheduled service

    Fredrik Newbie

      Hi I am tryin to send seam mails from a service and I can't get it to work.

      My service checks my db every 1o minutes for updates and if it finds any a mail schould be sent.

      From my service I look up a stateless session bean using

      InitialContext ctx = new InitialContext();
      mailer = (se.test.Mailer) ctx.lookup("Camitz/Mailer");

      I now that I can't inject in a service so I have to do a lookup

      My session been is annotated like this:

      @Stateless
      @Name("mailerAction")
      @Interceptors(SeamInterceptor.class)
      @LocalBinding (jndiBinding="Camitz/Mailer")
      @Scope(ScopeType.CONVERSATION)


      The method for sending the mails :
      public void sendAlarm(String to, String subject, String message){

      AlarmMailBean mailBean = new AlarmMailBean(to,subject,message,link);
      Contexts.getConversationContext().set("alarmMail", mailBean);
      try {
      Renderer.instance().render("/mail/mailTemplate.xhtml");
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }

      When the renderer is called I strangely get 2 different kinds off exceptions.

      1.
      11:35:05,559 ERROR [AlarmService] java.lang.RuntimeException: java.lang.NoClassD
      efFoundError: org/jboss/seam/ui/JSF
      javax.ejb.EJBException: java.lang.RuntimeException: java.lang.NoClassDefFoundErr
      or: org/jboss/seam/ui/JSF
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.ja
      va:69)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java
      :191)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInt
      erceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(Stateles
      sInstanceInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(Authentic
      ationInterceptor.java:77)
      at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3Auth
      enticationInterceptor.java:102)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterce
      ptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(Asynchrono
      usInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:101)
      at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessCont
      ainer.java:211)
      at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalPro
      xy.java:79)
      at $Proxy186.test(Unknown Source)
      at se.camitz.admin.service.AlarmService.perform(AlarmService.java:59)


      2.
      12:32:36,647 ERROR [STDERR] -- nested exception start --
      java.lang.IllegalStateException: No application context active
      at org.jboss.seam.Component.forName(Component.java:1577)
      at org.jboss.seam.Component.getInstance(Component.java:1627)
      at org.jboss.seam.Component.getInstance(Component.java:1610)
      at org.jboss.seam.Component.getInstance(Component.java:1589)
      at org.jboss.seam.Component.getInstance(Component.java:1584)
      at org.jboss.seam.mail.MailSession.instance(MailSession.java:266)
      at org.jboss.seam.mail.ui.UIMessage.getMailSession(UIMessage.java:63)
      at org.jboss.seam.mail.ui.UIMessage.getMimeMessage(UIMessage.java:78)
      at org.jboss.seam.mail.ui.UIMessage.encodeBegin(UIMessage.java:101)
      at org.jboss.seam.ui.JSF.renderChild(JSF.java:171)
      at org.jboss.seam.ui.JSF.renderChildren(JSF.java:162)
      at org.jboss.seam.ui.facelet.FaceletsRenderer.renderFacelet(FaceletsRend
      erer.java:150)
      at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.ja
      va:112)
      at se.camitz.admin.mail.MailerAction.sendAlarm(MailerAction.java:77)



      Exception 1. I dont understand but exception 2 is because I am not in a seam context.
      How can I create a seam context or workaround this problem?
      I have tried to use org.jboss.seam.contexts.Lifecycle.beginCall(); in my method but it did not help.
      Or is it impossible to use seam mail from a service?

      Best Regards Fredrik