We are using a custom servlet in Tomcat via the
org.apache.catalina.servlets.CGIServlet class. Everything seems to be going fine so far - we can access the required endpoint.
However, the program referenced by the servlet is used for a JSON REST API, and will be responsible for setting the
Content-Type and response body correctly. For example, if a HTTP 401 is raised, the request body would be (as an example):
error: "401 - Forbidden"
When this response is received back through Tomcat, however, it is being replaced with a HTML page for the 401 response.
Short of creating individual
<error></error> tags for each response code that could be raised, how can I tell Tomcat to let the CGI program control the response body, mime type and Content Type for the response?
We have the same process working through IIS, and it works okay.
Edit: We found that IIS has the option of
<httpErrors existingResponse="Passthrough">, which will use the response provided by the CGI program for any HTTP errors. I can't seem to find an equivalent of this option in Tomcat.