So what I do is that I email myself a tapestry exception page. It has
been incredibly usefull for tracking bugs!

  /**
   * Sets the Exception page's exception property, then renders the Exception
   * page.
   * <p>
   * If the render throws an exception, then copious output is sent to
   * <code>System.err</code> and a [EMAIL PROTECTED] ServletException} is 
thrown.
   */
  @Override
  protected void activateExceptionPage(IRequestCycle cycle,
ResponseOutputStream output,
      Throwable cause) throws ServletException {
    try {
      Throwable realcause = cause.getCause();
      if (realcause != null)
        s_logger.error("Error processing request:", cause.getCause());
      else
        s_logger.error("Error processing request:", cause);

      String expPage;
      if (doDebug())
        expPage = getExceptionPageName();
      else
        expPage = "ErreurGenerale";

      if (!doDebug()) {
        String pageName = "-";
        if (cycle.getPage()!= null)
          pageName = cycle.getPage().getPageName();
        IPage defaultPage = cycle.getPage(getExceptionPageName());
        String message = cause.toString();
        if (cause.getMessage() != null)
          message = cause.getMessage();
        defaultPage.setProperty("exception", cause);
        Email.sendEmail(null, defaultPage, cycle, "[EMAIL PROTECTED]",
            "[EMAIL PROTECTED]", "Page:" + pageName + " " + message);
      }

      IPage exceptionPage = cycle.getPage(expPage);

      exceptionPage.setProperty("exception", cause);
      cycle.activate(exceptionPage);
      renderResponse(cycle, output);
    } catch (Throwable ex) {
      // Worst case scenario. The exception page itself is broken, leaving
      // us with no option but to write the cause to the output.

      reportException(Tapestry
          .getMessage("AbstractEngine.unable-to-process-client-request"),
cause);

      // Also, write the exception thrown when redendering the exception
      // page, so that can get fixed as well.

      reportException(Tapestry
          .getMessage("AbstractEngine.unable-to-present-exception-page"), ex);

      // And throw the exception.

      throw new ServletException(ex.getMessage(), ex);
    }
  }

and
 /**
   * @param cycle
   * @param from
   * @param recipient
   * @param subject
   */
  public static void sendEmail(IPage source, IPage page, IRequestCycle cycle,
      String from, String recipient, String subject) {
    IForm cform = Form.get(cycle);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    HTMLWriter writer = new HTMLWriter(baos);
    cycle.activate(page);
    cycle.renderPage(writer);
    writer.flush();
    String semail = baos.toString();
    semail = semail.replaceAll("img src=\"/", "img src=\"http://";
        + cycle.getRequestContext().getServerName()
        + ((cycle.getRequestContext().getServerPort() == 80) ? "" : (":" + cycle
            .getRequestContext().getServerPort())) + "/");
    semail = semail.replaceAll("href=\"/", "href=\"http://";
        + cycle.getRequestContext().getServerName()
        + ((cycle.getRequestContext().getServerPort() == 80) ? "" : (":" + cycle
            .getRequestContext().getServerPort())) + "/");
    Context initCtx;
    try {
      initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      Session session = (Session) envCtx.lookup("mail/Session");

      MimeMultipart content = new MimeMultipart("mixed/alternative");
      MimeBodyPart html = new MimeBodyPart();

      content.addBodyPart(html);

      Message message = new MimeMessage(session);
      message.setContent(semail, "text/html;charset=\"UTF-8\"");
      message.setFrom(new InternetAddress(from));
      InternetAddress to[] = new InternetAddress[1];
      to[0] = new InternetAddress(recipient);
      message.setRecipients(Message.RecipientType.TO, to);
      message.setSubject(subject);
      message.setSentDate(new Date());

      Transport.send(message);
      s_logger.debug("Message sent from " + from + " to " + recipient
+ ":" + subject);

    } catch (NamingException e) {
      s_logger.debug(e);
    } catch (AddressException e) {
      s_logger.debug(e);
    } catch (MessagingException e) {
      s_logger.warn(e);
    }
    page.detach();

    if (source != null) {
      cycle.activate(source);
      cycle.setAttribute(IForm.ATTRIBUTE_NAME, cform);
    }
  }

On 9/23/05, Andrey Tkach <[EMAIL PROTECTED]> wrote:
> Yep, it's interesting. Could you please post your code here (with an ant
> build file)
>
> Andrey
>
> >
> > We are using that with Tapestry 3. I can post my code if you are
> > interested.
> > I have configured our ant build with 2 targets dev and production, on
> > dev the exceptions are showed normally but on prod, another page is
> > displayed and an email is sent.
> >
> > Henri.
> >
> > On 9/22/05, Sergiy Kyrylkov <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > Is it possible to extend Tapestry exception handling mechanism in an
> > easy
> > > way to send exception report by e-mail to a specified address every time
> > an
> > > exception occurs?
> > >
> > > Sergiy
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Thanks,
> >
> > Henri.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


--
Thanks,

Henri.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to