• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Exception logging from servlets

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic