3 Replies Latest reply on Jul 16, 2009 9:52 PM by Al Mathison

    Cant send emails out of my stateless component

    daniel rufibach Newbie
      Hi, i want to send reports from database as emails. I created a component EmailHandler that sends the mails..

      When i invoke the methods from a button out of a page

         <h:commandButton id="mailExample" value="send" action="#{emailHandler.sendEmail}"/>
         <h:commandButton id="mailExampleasync" value="sendasync" action="#{emailHandler.sendEmailAsync}"/>
                 

      everything works great and the emails are sent successfully.....


      but when i inject this EmailHandler into my Component that generates the reports, i always get the following exception

      any ideas??


      17:34:55,204 ERROR [EmailHandler] Error sending mail
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.ui.facelet.facesContextFactory
              at org.jboss.seam.Component.newInstance(Component.java:2106)
              at org.jboss.seam.Component.getInstance(Component.java:1988)
              at org.jboss.seam.Component.getInstance(Component.java:1967)
              at org.jboss.seam.Component.getInstance(Component.java:1961)
              at org.jboss.seam.Component.getInstance(Component.java:1934)
              at org.jboss.seam.Component.getInstance(Component.java:1929)
              at org.jboss.seam.ui.facelet.RendererFacesContextFactory.instance(RendererFacesContextFactory.java:72)
              at org.jboss.seam.ui.facelet.RendererRequest.init(RendererRequest.java:45)
              at org.jboss.seam.ui.facelet.RendererRequest.run(RendererRequest.java:72)
              at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:43)
              at org.domain.testspider.session.EmailHandler.sendEmailAsync(EmailHandler.java:43)
              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:597)
              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.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
              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.domain.testspider.session.EmailHandler_$$_javassist_2.sendEmailAsync(EmailHandler_$$_javassist_2.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:597)
              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:441)
              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
              at java.util.concurrent.FutureTask.run(FutureTask.java:138)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory
              at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:725)
              at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:239)
              at org.jboss.seam.ui.facelet.RendererFacesContextFactory.create(RendererFacesContextFactory.java:47)
              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:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
              at org.jboss.seam.Component.newInstance(Component.java:2094)
              ... 49 more






      my class..

      @Name("emailHandler")
      @Scope(ScopeType.APPLICATION)
      @Startup
      public class EmailHandler
      {
        
         @Logger
         private Log log;
        
         @In
         private FacesMessages facesMessages;
        
         @In
         private Renderer renderer;
        

         public void sendEmail() {
            try {
              renderer.render("/messages/simple.xhtml");
              facesMessages.add("Email sent successfully");
            } catch (Exception e) {
               log.error("Error sending mail", e);
               facesMessages.add("Could not send the Email " + e.getMessage());
            }
         }
        
         @Asynchronous
         public void sendEmailAsync() {
                    try {
                      renderer.render("/messages/simple.xhtml");
                      facesMessages.add("Email sent successfully");
                    } catch (Exception e) {
                       log.error("Error sending mail", e);
                       facesMessages.add("Could not send the Email " + e.getMessage());
                    }
                 }
        


      @Stateless
      @Name("searchResultSender")
      public class SearchResultSenderBean implements SearchResultSender {
              @Logger
              private Log log;

              @In
              StatusMessages statusMessages;

              @PersistenceContext
              EntityManager entityManager;
             
              @In
              EmailHandler emailHandler;

              @SuppressWarnings("unchecked")
              public void searchResultSender() {
                     
                      log.info("searchResultSender.searchResultSender() action called");
                      statusMessages.add("searchResultSender");

                      // get unsent resultsets

                      List<ResultSet> resultList =entityManager.createQuery(
                                      "select r from ResultSet r where r.sent = false ")
                                      .getResultList();
                     
                     
                     
                      if(resultList.size()>0){
                             
                              for (ResultSet resultSet : resultList) {
                                     
             
                                      List<KeywordResult> resultlist =  resultSet.getKeywordResultList();
                                     
                                      for (KeywordResult keywordResult : resultlist) {
                                             
                                              System.out.println("Keyword: "+keywordResult.getKeyword().getKeywordtext());
                                             
                                              List<Htmldata> htmldatalist =  keywordResult.getHtmldatalist();
                                             
                                              for (Htmldata htmldata : htmldatalist) {
                                                     
                                                      System.out.println("\u0009 Site Found: "+htmldata.getUrl());
                                                     
                                              }
                                      }
                                     
                                      emailHandler.sendEmailAsync();

                              }
                             
                             
             
                      }
                     

              }

              // add additional action methods

      }