0

Currently working on a legacy Java-web project (Java 8, Tomcat 7, mix of good ol' JSP's, JSF & various Servlet stuff e.g. web.xml v2.5)

I'd like to be able to let specific Java technical exceptions flow until Tomcat catches them, in order to use its built-in default error pages (btw I can't find them in the source code: https://github.com/apache/tomcat/find/7.0.x )

Note: i DO NOT want to customize these error pages.

The only hits I can find are either to redirect to some Servelt I have to develop & by myself e.g. https://www.tutorialspoint.com/servlets/servlets-exception-handling or using custom pages e.g. https://www.codejava.net/java-ee/servlet/how-to-handle-error-in-web-xml-for-java-web-applications

Also found this chapter from Red Hat's JBoss Seam platform, which seems really interesting, esp. the 2nd and 3rd code extracts:

<exception class="java.lang.UnsupportedOperationException">
    <http-error error-code="501">
        <message>The requested operation is not supported</message>
    </http-error>
</exception>

<exception class="my.CustomException" log="false">
    <http-error error-code="503">
        <message>Service not available: #{org.jboss.seam.handledException.message}</message>
    </http-error>
</exception>

https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Web_Platform/5/html/Seam_Reference_Guide/ch23s04s04.html

But hey, I can't use this... :-/

So how can I mimic this config?

maxxyme
  • 2,164
  • 5
  • 31
  • 48
  • 2
    Why not the `` in `web.xml` ? It's part of the ee spec and will work everywhere. – Svetlin Zarev Jul 15 '19 at 16:45
  • @SvetlinZarev because it maps a Java exception to a `` not an HTTP status code (see the example links I posted above) and I don't want that. – maxxyme Jul 16 '19 at 07:33
  • @SvetlinZarev 2nd page says: *Java EE allows you to handle errors (by HTTP error codes and Java exception types) easily by putting some pieces of configuration in the web deployment descriptor document (the web.xml file). **That means instead of showing the default error pages provided by the server, you can show your own error pages**.* I **want** to show default error pages provided by the server. – maxxyme Jul 16 '19 at 07:34
  • you can specify your own servlet in the `location` that will do the mapping to status code. Also it's a bad practice to rely on the default error page - very often it reveals sensitive information. – Svetlin Zarev Jul 16 '19 at 08:59
  • I know that, but 1/ the "sensitive information" is just the Tomcat version, 2/ it's an internal application in a network with very strong ACL's, so I don't have to deal with this. – maxxyme Jul 16 '19 at 10:00
  • So basically you're saying there is no way to either: set up your own JSP error page, or: code my own servlet to raise the status code...? nothing like the Seam stuff config I posted in the end? – maxxyme Jul 16 '19 at 10:01
  • @SvetlinZarev I tried using the `location` to redirect to a `Servlet`; unfortunately the Tomcat core stack (I checked the source code) expects the servlet to return a full response, not just modify response headers/status or so. – maxxyme Jul 23 '19 at 09:24

0 Answers0