I have a web-app running on resin server. I have a filter in web.xml as:
<filter>
<filter-name>RequestLogger</filter-name>
<filter-class>app.RequestLogger</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestLogger</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
which does all the request logging into request.log file. The application have some 17
servlets all extend a base class BaseServlet which extends HttpServlet and has the doGet, doPost and the service method inside which cache related activity is done.
The BaseServlet is like this:
public class BaseServlet extends HttpServlet implements Serializable {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
try {
putProfileIntoCache(request);
}catch(Exception e){
AppsLogger.log(5,e);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
try {
putProfileIntoCache(request);
}catch(Exception e){
AppsLogger.log(5,e);
}
}
public void service(HttpServletRequest request, HttpServletResponse response){
try {
putProfileIntoCache(request);
}catch(Exception e){
AppsLogger.log(5,e);
}
}
private void putProfileIntoCache(HttpServletRequest request)throws Exception{
AppsLogger.log(5,"***Entered BaseServlet.putProfileIntoCache()***");
HttpSession session = request.getSession();
Profile profile = (Profile)session.getAttribute("Profile");
String currentThread = Thread.currentThread().getName();
AppsLogger.log(5,"Entered BaseServlet.putProfileIntoCache()-currentThread: "+currentThread);
if(profile != null){
profileCache.putUserProfile(currentThread, userProfile);
}
AppsLogger.log(5,"***Exited BaseServlet.putProfileIntoCache()***");
}
}
The servlets are written as:
public class UserServlet extends BaseServlet implements java.io.Serializable {
public void service(HttpServletRequest request, HttpServletResponse response) {
super.service(request,response);
String action = request.getParameter("Action");
try{
//some processing
}
catch (Exception e)
{
try{
String message = "Internal Server Error";
//going to error page
}catch(Exception e1){
//logging exception
}
}
}
}
How can I catch the exception that is thrown by any one of these servlets in the BaseServlet.