aspose file tools*
The moose likes Servlets and the fly likes Exception logging from servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception logging from servlets" Watch "Exception logging from servlets" New topic
Author

Exception logging from servlets

J Brown
Greenhorn

Joined: Jan 03, 2006
Posts: 6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception logging from servlets