Skip to main content
  1. Posts/

Suppressing Tomcat error messages for all applications on a host

·138 words·1 min
Author
Christopher Taylor
A collection of interesting things I’ve seen, as I’ve seen them.

Sometimes I write web applications for Tomcat where I don’t want to report any errors beyond the HTTP status code. The quickest method for disabling those messages is configuring a Valve on the host section of the server.xml configuration file.

If you subclass the org.apache.catalina.valves.ErrorReportValve class (it’s in your Tomcat’s lib/catalina.jar) and override the report method like this:

1public class ErrorSuppressorValve extends ErrorReportValve
2{
3    protected void report(Request request, 
4                          Response response,
5                          Throwable throwable) 
6    {
7        // Override the default behavior by doing nothing
8    }
9}

The client still receives the HTTP status code and anything already buffered, but it hides all of the automatically generated Tomcat error information.

To install it, just JAR up the class and put it in your Tomcat’s lib folder, then add the errorReportValveClass attribute to your Tomcat’s server.xml file.