Exception logging from servlets
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   James_Brown
Posted On:   Monday, January 23, 2006 09:44 AM

I have a web-app running on resin server. I have a filter in web.xml as: RequestLogger app.RequestLogger RequestLogger /* 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 {    More>>

I have a web-app running on resin server. I have a filter in web.xml as:



RequestLogger

app.RequestLogger





RequestLogger

/*





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.

   <<Less
About | Sitemap | Contact