You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jacob Haverkost <jd...@gmail.com> on 2015/03/16 19:52:18 UTC

CGIServlet - Disregarding 404 error-page

Version: 6.0.43
OS: Win7 x64

Currently, the CGIServlet does not appear to support using the 404
error-page specified in the web.xml (ROOT). The error-pages work fine

This appears to be due to the line, res.setStatus(404);, inside of doGet().
According to the documentation for HttpServletResponse.setStatus(int), "If
this method is used to set an error code, then the container's error page
mechanism will not be triggered."

This line appears in all major versions of Tomcat that I have looked into
(8.0.20, 7.0.59).

Just for a quick test, I changed setStatus to sendError and the error-page
worked as expected. Is there a way to have the error-page work without
changing the source code? If not, should I submit a bug report to include a
configuration parameter for the CGIServlet to allow support for the
error-page?

Thanks for any feedback or help you can provide.
- Jake

Re: CGIServlet - Disregarding 404 error-page

Posted by Jacob Haverkost <jd...@gmail.com>.
That is exactly the line I am referring to.

Simply replacing the call to res.setStatus with res.sendError would
definitely be wrong due to what you described. That change is not what I am
suggesting. It is simply what I did for a quick test. I was thinking it
would be worth it to add a flag as a servlet init-param to allow support
for the error-pages. The default would maintain current functionality so as
not to break anything currently in place.

Something like:

        if (!cgiEnv.isValid()) {
            if (shouldTriggerErrorPage) {
                res.sendError(404);
            } else {
                res.setStatus(404);
            }
        }

There are also a few other calls to setStatus that would probably be
handled the same way in order to handle other error codes as well.

As for the "if (!cgiEnv.isValid())" condition, isValid() will return false
if a request is made for a file that does not exist. Since the file doesn't
exist, I actually wanted to show a proper 404 error page matching the error
pages for the rest of my server. Currently, all I see is a blank page from
the CGIServlet since my debug level doesn't meet the logging condition.

Thanks for the help,
Jake

On Mon, Mar 16, 2015 at 7:49 PM, Konstantin Kolinko <kn...@gmail.com>
wrote:

> 2015-03-16 21:52 GMT+03:00 Jacob Haverkost <jd...@gmail.com>:
> > Version: 6.0.43
> > OS: Win7 x64
> >
> > Currently, the CGIServlet does not appear to support using the 404
> > error-page specified in the web.xml (ROOT). The error-pages work fine
> >
> > This appears to be due to the line, res.setStatus(404);, inside of
> doGet().
> > According to the documentation for HttpServletResponse.setStatus(int),
> "If
> > this method is used to set an error code, then the container's error page
> > mechanism will not be triggered."
> >
> > This line appears in all major versions of Tomcat that I have looked into
> > (8.0.20, 7.0.59).
> >
> > Just for a quick test, I changed setStatus to sendError and the
> error-page
> > worked as expected. Is there a way to have the error-page work without
> > changing the source code? If not, should I submit a bug report to
> include a
> > configuration parameter for the CGIServlet to allow support for the
> > error-page?
> >
>
> If you are talking about the following: (lines 612-614 in CGIServlet
> of current Tomcat 6.0.x)
>
>         if (!cgiEnv.isValid()) {
>             res.setStatus(404);
>         }
>
>
> You cannot just change res.setStatus(404);  with res.sendError(404),
> as that will break the following code that generates a HTML page with
> a debug message.
>
> See the block starting with "if (debug >= 10)".
>
>
> My guess (without looking deep into this) is that "if
> (!cgiEnv.isValid())" condition is there to catch a configuration
> error. I mean that you would not see that with a properly configured
> CGIServlet.   If my guess is wrong, you need to provide a specific use
> case that demonstrates otherwise.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: CGIServlet - Disregarding 404 error-page

Posted by Konstantin Kolinko <kn...@gmail.com>.
2015-03-16 21:52 GMT+03:00 Jacob Haverkost <jd...@gmail.com>:
> Version: 6.0.43
> OS: Win7 x64
>
> Currently, the CGIServlet does not appear to support using the 404
> error-page specified in the web.xml (ROOT). The error-pages work fine
>
> This appears to be due to the line, res.setStatus(404);, inside of doGet().
> According to the documentation for HttpServletResponse.setStatus(int), "If
> this method is used to set an error code, then the container's error page
> mechanism will not be triggered."
>
> This line appears in all major versions of Tomcat that I have looked into
> (8.0.20, 7.0.59).
>
> Just for a quick test, I changed setStatus to sendError and the error-page
> worked as expected. Is there a way to have the error-page work without
> changing the source code? If not, should I submit a bug report to include a
> configuration parameter for the CGIServlet to allow support for the
> error-page?
>

If you are talking about the following: (lines 612-614 in CGIServlet
of current Tomcat 6.0.x)

        if (!cgiEnv.isValid()) {
            res.setStatus(404);
        }


You cannot just change res.setStatus(404);  with res.sendError(404),
as that will break the following code that generates a HTML page with
a debug message.

See the block starting with "if (debug >= 10)".


My guess (without looking deep into this) is that "if
(!cgiEnv.isValid())" condition is there to catch a configuration
error. I mean that you would not see that with a properly configured
CGIServlet.   If my guess is wrong, you need to provide a specific use
case that demonstrates otherwise.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: CGIServlet - Disregarding 404 error-page

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jacob,

On 3/16/15 2:52 PM, Jacob Haverkost wrote:
> Version: 6.0.43 OS: Win7 x64
> 
> Currently, the CGIServlet does not appear to support using the 404 
> error-page specified in the web.xml (ROOT). The error-pages work
> fine
> 
> This appears to be due to the line, res.setStatus(404);, inside of
> doGet(). According to the documentation for
> HttpServletResponse.setStatus(int), "If this method is used to set
> an error code, then the container's error page mechanism will not
> be triggered."
> 
> This line appears in all major versions of Tomcat that I have
> looked into (8.0.20, 7.0.59).
> 
> Just for a quick test, I changed setStatus to sendError and the
> error-page worked as expected. Is there a way to have the
> error-page work without changing the source code? If not, should I
> submit a bug report to include a configuration parameter for the
> CGIServlet to allow support for the error-page?
> 
> Thanks for any feedback or help you can provide.

It seems reasonable to me to file an enhancement request for this.

If you provide a patch, you can get your name into the changelog ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJVBzo3AAoJEBzwKT+lPKRYkdsP/iutPC4vdDO8LkuwoiXZXM4S
Gjh3rWAyqYgVzPq20B+sICkF1cFnovVJnCjdO8D1r2IdFyDcyJoTYDat28oEPqow
+3K9vAQUPa+vp0il5YQsi3OuUuna511rH0aEcC4c8M9FyzsMXKLbwZVQu3TQSU2Y
5rImG1K9DODNEVhZA/XbkiOkJunn75D/84FdE3abb1fK9/gn1G/WOJdogelxUhPP
FtwDdMK/TsgQM1hDOUF7ieGEYIKyZmzbrXIOnehd2zFAg/1smER9hHUvDGl4UXPd
9MorVWl7C0u74JVntBSrhHmfzUkqz96XG5JZc8mGAxZ9uFdJhvhQMQxCvttB9P7q
jEdzJ7t2ZtARH71s0KZya3+r3/F9lkw1OCcF7ITBhRpE4C8Z8vLQqd7puG1mxiUm
VIK/pNClVLG60a0L0fvjUJ1tLPEvY2p7SFf0TZ/7rBbGT9/xSqSWESflRLpNExiC
SyzlPvilhDsvhyUxKv7L/SqoOqjoiYUtsJyVwVH+jW3JSoayYdq/V9ikTc6bAKaK
6qdBAqm5BXKg8rdYZXQ3OOIVmR/OBnDOTM0GyeeuDYtlhTezYA6Utj/SLorz1OIG
viH90/rXWqSAbKrgt/L+YWBIWX4L9M7no+QRQeFKdnjeZpORg0MEkK6/s5pn7wFJ
isXMVqWeMk/u6iez4uZ0
=ONFn
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org