5 Replies Latest reply on Jun 11, 2009 6:52 PM by daniele campanini

    How to send exceptions through email

    Bogdan Minciu Newbie

      Hello guys,


      I am using Seam Mail (and I am loving it), and I was wondering if there is any way to send the exceptions that a Seam application generates through the email.


      I was more interested in sending the whole content of the generated debug.xhtml page, because I have there all the information about the state of my beans, that I need to investigate (and hopefully solve) the exception.


      Thank you in advance,


      Bogdan.

        • 1. Re: How to send exceptions through email
          Daniel Roth Apprentice

          Just some copy-paste I use during devel:


          pages.xml.


          <exception>
            <end-conversation />
            <redirect view-id="/error.xhtml">
          </exception>
          
          <page view-id="/error.xhtml" login-required="false">
             <action execute="#{error.sendMail}" />
          </page>
          
          



          @Name("error")
          @Scope(ScopeType.EVENT)
          public class ErrorAction implements Serializable {
          
              @In(value = "org.jboss.seam.handledException")
              private Exception e;
          
              @In
              private MailService mailService;
          
              public void sendMail() {
                  mailService.sendErrorMail(e, "exception");
              }
          }
          



          Mailservice thingy



              public void sendErrorMail(Throwable throwable, String message) {
                  StringBuffer err = new StringBuffer();
                  if (throwable != null) {
                      err.append(throwable.getLocalizedMessage()).append("\n");
                      err.append(throwable.getMessage()).append("\n");
                      for (StackTraceElement elem : throwable.getStackTrace()) {
                          err.append(elem.getFileName()).append(":").append(elem.getLineNumber()).append(":").append(elem.getClassName()).append(":").append(
                                  elem.getMethodName()).append("\n");
                      }
                  }
                  Contexts.getEventContext().set("subject", message);
                  Contexts.getEventContext().set("body", err.toString());
                  Contexts.getEventContext().set("to", developer);
                  renderer.render("/mail/error.xhtml");
              }
          




          It just prints the stack in a way I like to see it. I guess you you just do something like


          StringWriter content = new StringWriter();
          throwable.printStackTrace(new PrintWriter(content));
          String body = content.getBuffer().toString();
          
          



          to get the ordinary stacktrace.

          • 2. Re: How to send exceptions through email
            Tom Goring Apprentice

            You can set Log4J to send exceptions to an email address... but this is generic (i.e. it won't do the debug.xhtml stuff)

            • 3. Re: How to send exceptions through email
              Bogdan Minciu Newbie

              Thank you for the reply Daniel. This is good starting point for what I need.

              • 4. Re: How to send exceptions through email
                Indu Sukumar Newbie

                Hi,


                    Currently i am in need to send an email notification on complete of some event in my application, can you help me with the steps to configure for it in Seam.


                Thanks in advance...


                Indu


                • 5. Re: How to send exceptions through email
                  daniele campanini Newbie

                  Hi daniel,
                  i am a newbie with seam, i dont have sendErrorMail method on class MailService!
                  What's wrong?


                  thankyou in advance