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:
- Name of developer
- Information about developer
- E-mail address of developer
- Wireless account information of developer
- 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
//some application code
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):
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.