wood burning stoves 2.0*
The moose likes Servlets and the fly likes Catching Servlet Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Catching Servlet Exceptions" Watch "Catching Servlet Exceptions" New topic
Author

Catching Servlet Exceptions

Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
Hi,
I need help in ctahing the exceptions thrown by a servlet that is used in the following manner:

<img src=/webapp//abhijit/servlet/<ServletName>?&<params/>
The problem is that the servlet specified is a third party servlet, hence the exceptions thrown by the servlet are not logged in the log file. I need to catch the exception thrown by the servlet or log it using Log4j logging. Can anybody help me in this regard. Any help will be appreciated.

Regards
Abhijit
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Depending on how the servlet is written (ie whether it needs special configuration) you may be able to get away wiuth th wrapping it in your own servlet and treating their servlet as a class:



Dave
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Write a wrapper around it that does log the exceptions...


42
Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
Hi,
The servlet is a thoird party servlet. I don't have its source code and hence can't catch the exception. Can you help me in handling such a servlet.

Regards
Abhijit
Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
Have you tried the example presented from David O'Meara. You don't need
that servlets source code to at least try what he suggested, since, in
order for it to be a servlet at all, it must implement the Servlet
interface. Wrap those methods in a class of your own calling the other
servlet as a normal class and redirect the server configuartion to point to
your new servlet instead of the original.
Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
Hi David,
It solved my problems. Thanks.

Regards
Abhijit
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Jeroen T Wenting:
Write a wrapper around it that does log the exceptions...


Great minds

Glad it worked.
Note that the example given was quicjk and dirt and there are improvements that can be made. BUT if it isn't a problem it's it's only woirth spending enough time to get it done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catching Servlet Exceptions