You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daryl Stultz <da...@opentempo.com> on 2018/04/25 20:08:35 UTC

DefaultServlet subclass behavior change TC6 to 8

Hello,


We are upgrading from Tomcat 6 to Tomcat 8.5. We have a servlet that extends org.apache.catalina.servlets.DefaultServlet. We override getRelativePath(HttpServletRequest request), that's all.


The purpose of this servlet is to do a sort of redirect, the browser asks for a spreadsheet "my-site.css" which is mapped to our servlet. In getRelativePath we return "my-site-prod.css" or "my-site-test.css" for example depending on the environment the application is running in.


If I override doGet (calling super) I can see that doGet is called but getRelativePath is never called and the browser gets a 404 error for "my-site.css".


Anyone know what I need to change to restore the behavior as it was in Tomcat 6? I'm afraid I inherited this code so it's hard to say why it was done this way.


Thanks.


--

Daryl Stultz
Principal Software Developer
_____________________________________
OpenTempo, Inc
http://www.opentempo.com<http://www.opentempo.com/>
mailto:daryl.stultz@opentempo.com<ma...@opentempo.com>


Re: DefaultServlet subclass behavior change TC6 to 8

Posted by Daryl Stultz <da...@opentempo.com>.
> If you look at doGet() and follow the code you should be able to figure

out what you need to change to get things working in 8.5.x.

Thanks Mark, that did the trick, serveResource calls getRelativePath(request, true) now where we were overriding getRelativePath(request)

Chris, the Filter idea definitely looks like a better design, I'll keep that in mind if we rework the feature. Thanks.

/Daryl

Re: DefaultServlet subclass behavior change TC6 to 8

Posted by Mark Thomas <ma...@apache.org>.
On 25/04/18 21:08, Daryl Stultz wrote:
> Hello,
> 
> 
> We are upgrading from Tomcat 6 to Tomcat 8.5. We have a servlet that extends org.apache.catalina.servlets.DefaultServlet. We override getRelativePath(HttpServletRequest request), that's all.
> 
> 
> The purpose of this servlet is to do a sort of redirect, the browser asks for a spreadsheet "my-site.css" which is mapped to our servlet. In getRelativePath we return "my-site-prod.css" or "my-site-test.css" for example depending on the environment the application is running in.
> 
> 
> If I override doGet (calling super) I can see that doGet is called but getRelativePath is never called and the browser gets a 404 error for "my-site.css".
> 
> 
> Anyone know what I need to change to restore the behavior as it was in Tomcat 6? I'm afraid I inherited this code so it's hard to say why it was done this way.

Have you looked at the source code for the DefaultServlet in 8.5.x?

https://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?view=annotate

If you look at doGet() and follow the code you should be able to figure
out what you need to change to get things working in 8.5.x.

Mark

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


Re: DefaultServlet subclass behavior change TC6 to 8

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

Daryl,

On 4/25/18 4:08 PM, Daryl Stultz wrote:
> We are upgrading from Tomcat 6 to Tomcat 8.5. We have a servlet
> that extends org.apache.catalina.servlets.DefaultServlet. We
> override getRelativePath(HttpServletRequest request), that's all.
> 
> 
> The purpose of this servlet is to do a sort of redirect, the
> browser asks for a spreadsheet "my-site.css" which is mapped to our
> servlet. In getRelativePath we return "my-site-prod.css" or
> "my-site-test.css" for example depending on the environment the
> application is running in.
> 
> 
> If I override doGet (calling super) I can see that doGet is called
> but getRelativePath is never called and the browser gets a 404
> error for "my-site.css".
> 
> 
> Anyone know what I need to change to restore the behavior as it was
> in Tomcat 6? I'm afraid I inherited this code so it's hard to say
> why it was done this way.

This would be MUCH easier using url-rewriting than subclassing
DefaultServlet and changing the way it behaves.

I *highly* recommend that you check this out:

https://tomcat.apache.org/tomcat-8.5-doc/rewrite.html
or
http://tuckey.org/urlrewrite/

and ditch the DefaultServlet subclass.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlrg7iIACgkQHPApP6U8
pFgwlBAArR/EYd3uz9BTzATFJyP9OeJhj1g10SZU715lzJnP0grGR7YzuWDHYUcr
yFVVHCGdj3xZIXj3APFjbXMT1IhhSblBm0pr8lK8S6TDHW9z9em0xGF8KtKZapYd
qvzrN/xB0BSspG6zprgU2vrnQOTEVOFaEAjTOCDzULc5Y9GSjGbD3HRlF8bUbryo
i5f3aoinazrbF2gjIUCKBqh/ngB5ILy2i4pzey0uqyQ6E0are4sRgbqA9cwvpQxp
27F9JD9EZ51TYlNLys7kjtxisSZX9HR2v95YnwJWDjd//ZcpwOAytr+ZSpDBXw55
5qvvBzNXi/wwQMhNcKRvwI9yhThl8b3nCsayQtkDvUn+zrbOBxGJXQluKL//TCGf
oI4OW2v4Pjs1RP4eqKKmehI52aGcAeUNNVu4u54FfQwKS8+18ssDe5qJaYS5oW0T
sFXT6rzZN2kahcMaVBT1jzl8+UR5qdP+hO6xH92PcEUY/AHCHErPq/1WNzrkiV0e
6qHo2TToKdl7ZEGcX60y/h2B5ZrP9rtH4zFV5z0GhIZsj0AI3sU+1ehZZX3wV/Tv
AA4RjqAVbeHaU3IbvaZ5Z/m5Nben08HE5YSpG+A63jUiCbSapxV1EU9bQCyG5HQU
UzeNZ5ZKWLPYGx4lgAVjUogkNautSQmGLMnv04+8JZmWOFO5n3Q=
=zsh4
-----END PGP SIGNATURE-----

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