Tuesday, January 15, 2013

ADF : How to create Exception / Error Page in the ADF Application ?

ADF : How to create Exception / Error Page in the ADF Application ?

We can create an Exception page on every bounded and unbounded taskflow.
The Exception page we have designed can handled, the not handled errors like java nullpointer exceptions.
Business logic exceptions are still displayed at the right place.
I have created a custom exception page where the stacktrace is displayed in an textarea and added a button to send a notification to the support team.

























public class Exception {
  private RichForm f1;
  private RichDocument d1;
  private ControllerContext cc;
  private String stacktrace;
 
    public Exception() { 
        cc = ControllerContext.getInstance(); 
    } 
     
    public String getStacktrace() { 
        if ( cc.getCurrentViewPort().getExceptionData()!=null ) { 
            StringWriter sw = new StringWriter(); 
            PrintWriter pw = new PrintWriter(sw);  
            cc.getCurrentViewPort().getExceptionData().printStackTrace(pw);  
            return sw.toString();             
        } 
        return null; 
    } 
     
 /*
    public String sendMail() 
    { 
      Properties p = System.getProperties(); 
      p.put("mail.transport.protocol","smtp"); 
      p.put("mail.smtp.host","mail.XXX.com"); 
 
      Session session = Session.getInstance(p); 
      MimeMessage message = new MimeMessage(session); 
      try { 
            message.setFrom(new InternetAddress(xxxx@xxxx.com)); 
            message.addRecipient(Message.RecipientType.TO,new InternetAddress(xxxx@xxxxx.com)); 
            message.setSubject(cc.getCurrentViewPort().getExceptionData().getMessage()); 
            message.setContent(getStacktrace(),"text/plain"); 
            Transport.send(message); 
        } catch (MessagingException e) { 
            // TODO 
           e.printStackTrace(); 
      } 
      System.out.println(message.toString()); 
      return null; 
    } 
*/
  public void setF1(RichForm f1) {
    this.f1 = f1;
  }

  public RichForm getF1() {
    return f1;
  }

  public void setD1(RichDocument d1) {
    this.d1 = d1;
  }

  public RichDocument getD1() {
    return d1;
  }

  public String sendMail() {
    // Add event code here...
    return null;
  }

  public void setStacktrace(String stacktrace) {
    this.stacktrace = stacktrace;
  }

//  public String getStacktrace() {
//    return stacktrace;
//  }