Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build a Notification Servlet That E-mails Exceptions to App Developers : Page 2

Implement a mechanism that notifies the appropriate developer via e-mail whenever an exception occurs during application testing. With a little bit of effort, you can build a notification servlet that will enable such a mechanism.


advertisement
How the Servlet Determines Its Recipients
The most interesting part of this process is how the servlet determines the recipients of its notifications. To explain this process, I propose a very elementary mechanism: a list of developer profiles maintained in a database or other persistent media. Each user profile typically has attributes like the following:
  1. Name of developer
  2. Information about developer
  3. E-mail address of developer
  4. Wireless account information of developer
  5. Most importantly, a list of Java class names for which the developer is primarily responsible

I can make the UserDefinedException class sensitive to the context in which the exceptions occurred, by capturing the class name of the object wherein the exception occurred. You can see this clearly in the following listing:

public class UserDefinedException extends Exception { private String mExceptionSourceClassName; public UserDefinedException(Object sourceObject,Exception e, .....) { //capture the exception source's class name mExceptionSourceClassName = sourceObject.getClass().getName(); //do custom error handling, error logging etc //send out HTTP request to notification servlet } }



Usage:

{ try { //some application code } catch(Exception e) { throw new UserDefinedException(this,e,......) } }

Then I can send this Exception Source Class Name across to the notification servlet, which would go through the list of developer profiles to figure out the primary developer for that class name. The servlet would then load the primary developer's profile and fetch the developer's e-mail address and wireless account information.

The servlet has access to the generated application exception, its description, and its stack trace, as well as the primary developer's contact information. Depending on the severity of the exception, the servlet can then send out notifications about the exception, either through e-mail or on a wireless device, using appropriate Java APIs.

The following is a utility class listing, which can e-mail the exception details using SMTP protocol (click here for the notification servlets complete source code):

CE-mailer.java CNotificationServlet.java

The notification servlet spawns off a thread, CThreadHandleExceptions, which actually handles exception notifications. Utilizing this thread (with the CThreadHandleExceptions.java utility) improves the responsiveness of the notification servlet itself.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date