You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jeremy Collins <je...@perfectsensedigital.com> on 2018/05/17 14:43:34 UTC

Issue with WebResource Caching

Hi,


We're seeing an issue with how WebResources are cached that started
occurring in Tomcat 8.0.39 (we're using Ubuntu Xenial but I don't believe
it's related to anything in the OS).


Some of the CSS/JS files that we serve are packed inside JAR files. These
files are served by a filter that listens for an allowed path, /_resource/*
in this case, and then uses Thread.currentThread().getContextClassLoader().
getResourceAsStream(path) to fetch them out of the appropriate jar file and
serve them.


The issue we're seeing in 8.0.39 and later is that the lookup using
getResourceAsStream(path) returns null. We've traced the issue

to this specific commit: https://github.
com/apache/tomcat80/commit/184703b966fab28a27eddf4a49014bf92e5a34eb.


This is the expected request flow:


- User requests /_resource/bootstrap/js/bootstrap.js which is embedded in a
JAR included in the WAR file

- ResourceFilter (our simple filter in the example project below) looks up
the resource using getResourceAsStream(path)

- If a stream is return it's copied to the response and processing stops


What we think is happening when the issue occurs in 8.0.39:


- User requests /_resource/bootstrap/js/bootstrap.js which is embedded in a
JAR included in the WAR file

- Tomcat Mapper looks for the resource and fails to find it and caches an
EmptyResource for that path

- ResourceFilter (our simple filter in the example project below) looks up
the resource using getResourceAsStream(path)

- The resource isn't found because the EmptyResource is cached


I've created a small example project that exhibits this behavior:
https://github.com/beetlebugorg/tomcat-8-cache-issue


At this point we're unsure if this is an actual bug in Tomcat or an
incorrect usage of getResourceAsStream(path) on our part so

we're looking for advice.


Thanks,

Jeremy


-- 

JEREMY COLLINS

PERFECTSENSE  //  BRIGHTSPOT

www.perfectsensedigital.com

www.brightspot.com

O 703-956-5815

Re: Issue with WebResource Caching

Posted by Jeremy Collins <je...@perfectsensedigital.com>.
>
>
> > Tomcat uses the same code for static and class loader resources but it
> > is meant to distinguish between the two. However, it looks like there is
> > a bug in Tomcat's resource handling that hides this resource once the
> > static look-up fails. I need to dig into this some more.
>
> Yes, there is a bug here. It has been fixed for the next set of releases
> (due early next month).
>
>
Thanks for the quick resolution and advice on using /META-INF/resources!

Re: Issue with WebResource Caching

Posted by Mark Thomas <ma...@apache.org>.
On 18/05/18 07:23, Mark Thomas wrote:

<snip/>

> Tomcat uses the same code for static and class loader resources but it
> is meant to distinguish between the two. However, it looks like there is
> a bug in Tomcat's resource handling that hides this resource once the
> static look-up fails. I need to dig into this some more.

Yes, there is a bug here. It has been fixed for the next set of releases
(due early next month).

Mark

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


Re: Issue with WebResource Caching

Posted by Mark Thomas <ma...@apache.org>.
On 17/05/2018 15:43, Jeremy Collins wrote:

<snip/>

> At this point we're unsure if this is an actual bug in Tomcat or an
> incorrect usage of getResourceAsStream(path) on our part so
> 
> we're looking for advice.

I think it is a bit of both.

ServletContext.getResourceAsStream(path) won't normally return a 
resource that is packaged in a JAR file. The exception to this is if the 
resource is packaged under META-INF/resources as per the 'package static 
resources in a JAR' feature that was added in Servlet 3.0.

It looks to me like META-INF/resources does everything you need it to - 
and will be supported by any Servlet 3.0 compliant container (7.0.x 
onwards in Tomcat's case). I'd look at using it.

ClassLoader.getResourceAsStream(path) is the way to retrieve a resource 
from a JAR but that isn't working in this case.

Tomcat uses the same code for static and class loader resources but it 
is meant to distinguish between the two. However, it looks like there is 
a bug in Tomcat's resource handling that hides this resource once the 
static look-up fails. I need to dig into this some more.

And thanks for the test case. Being able to reproduce this makes 
investigation a whole lot easier.

Mark

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