10 Replies Latest reply on Dec 11, 2009 9:51 AM by michael tang

    Email any exception

    michael tang Newbie

      When using email in seam, how to email any exception that occured?

        • 1. Re: Email any exception
          itays100 Newbie

          If i read you right. You want to know how to catch excption while sending email. Try this:
          wrap the raise event with try and catch and enter invalid email adress.

          • 2. Re: Email any exception
            michael tang Newbie

            michael tang wrote on Nov 30, 2009 10:02:

            My App based on JBoss AS, JSF, EJB and Seam, the current solution for error handing is just show a common error page. Now I want to send detailed error messages to a mail account, How to implement this in the application gracefully with the least code? Do I need to catch every excpetion in session bean, then sending the mail, Or just a few code changes to email any exception that occured in the system?

            Click HELP for text formatting instructions. Then edit this text and check the preview.

            • 3. Re: Email any exception
              itays100 Newbie

              Do you want to send an email for every exception that accured in the application ?

              If this is the case i'm afraid you've to do some work (i'm not sure seam has solution for collecting error messages). Basically you'll need a seam component
              (application scope) that all he does is collecting error messsages. But you have to inject it to
              each component that might throw an excption and add messages in the catch clause.

              once in a while you can send an email to a user with the content and clean.

              Hope it helps.

              • 4. Re: Email any exception
                Tim Evers Master

                There's no need to create an Application scoped component (unless you want to store exceptions until you have say 20 of them before you email).

                Just write yourself an interceptor like this.

                public class ExceptionInterceptor extends AbstractInterceptor {
                    public boolean isInterceptorEnabled()
                       return true;
                    public Object aroundInvoke(InvocationContext ctx) throws Exception {         
                        Object result = null;
                        try {
                           result = ctx.proceed();
                        catch( RuntimeException e ){
                            //Create and email your exception report here!!!!!!
                            throw e;
                        return result;

                Assuming your exception is raised somewhere withing a Seam execution then this interceptor will be able to handle it.

                • 5. Re: Email any exception
                  itays100 Newbie

                  Tim, what about excption throw directly from jsf and not seam. In this case the Interceptor won't fire
                  right ?

                  Is Interceptor work on non ejb entities ?

                  • 6. Re: Email any exception
                    Tim Evers Master

                    Well, if you want to catch the exceptions that are thrown from JSF the application scoped bean isn't going to help either. JSF code happens earlier in the stack then our Seam code so it doesn't matter that you have injected an application scoped component into things or not because you don't have any hooks into the JSF code directly.

                    I'm guessing you could try a rule in the pages.xml to catch the JSF exceptions, But at the end of the day if you want to handle every exception you will probably have to write a filter and put it in your web.xml.

                    But, the original poster is talking about Seam email, so he's already within the Seam framework when his code is executing so an interceptor should actually work fine... I think :P

                    Not sure any of this made sense..... but maybe it did

                    • 7. Re: Email any exception
                      Aboo salimon Newbie


                      Map this jsp page in pages.xml
                      like this:

                       <exception class="org.jboss.seam.framework.EntityNotFoundException">
                              <redirect view-id="/error.jsp">
                                  <message>Not found</message>

                      (this is to show the error in jsp page)
                      Create error.jsp in your application
                        In this page


                      Step2:(this step to send mail the exception you got)
                      Example: keep one action button like this


                      from this method you can send mail.


                      • 8. Re: Email any exception
                        Matt Drees Master

                        This, in my opinion, is an open problem.  I haven't yet seen a good solution.

                        One option is configuring a log4j SMTPAppender, but this is fairly primitive.  You get the error message and stacktrace in the email, and that's it.  No additional context information.  Plus, depending on how the various layers log exceptions, you may get multiple emails with the same stacktrace.  But this is a great way to get started; not much extra configuration is required. 

                        What I'd like to see (and may get around to finishing sometime) is a mechanism somewhat similar to Rails' Exception Notifier Plugin, but better and more configurable.  Something that would give all kinds of context info (request params, previous requests, session info, blah blah). 

                        • 9. Re: Email any exception
                          michael tang Newbie

                          I use seam interceptor to handle the exception. It works. but I need to annotate every action bean as Interceptted by that interceptor. I need to add to many action beans.

                          • 10. Re: Email any exception
                            michael tang Newbie

                            I tried log4j smtp, It logged many errors like below:
                            ERROR STDERR Dec 11, 2009 4:26:20 PM com.sun.facelets.compiler.TagLibraryConfig loadImplicit.

                            The above error did not impact the app running, but will confused the support team.

                            how to remove it?.