tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Web resource By-pass
Date Fri, 05 Feb 2010 15:42:50 GMT
Mihalakakos, Demetri wrote:
> Hi,
> 
> I have a question about the best way of doing something.
> 
> I'm writing an application where all requests would get routed to a Filter (mapping:
"/*").  So when I get a requests like "/some/page/in/the/web/" (which does not actually live
in the file system) I would forward to a Servlet or handle appropriately.  The problem is
all web resources are being routed there as well (js, css, images), is it possible to have
all files and folders that do exist on the file system get served normally and not through
my Filter.  I know I can do a simple io check in the filter, but I was wondering if that's
actually the best/only way (one of my concerns is optimization)
> 
> For example in PHP or Python I would put something like this in the vhost: (which is
technically happening out side the application)
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule ^(.*)$ /index.php [L]
> 
> Also I prefer not use 'Apache httpd' with 'tomcat'
> 

I don't know what the precise point of your filter is, but
I'll give you a slightly different answer than Pid's :

Essentially it goes "there is no such thing as a free lunch".

The "RewriteCond .. !-f" Apache directives you are using above, also 
mean that /something/ will have to go check if that file exists.
Is is probably better to ask the server to do that if possible, rather 
than having your own code do it; that's just because the server code is 
likely to be more optimised and bug-free than yours.
But it will mean some disk accesses anyway.

Maybe a better method would consist in :
1) making sure that you use all possibilities of server and browser to 
insure that the browser will cache stuff like stylesheets, js and 
images.  This way the browser will only really request them when needed.
(Honestly, I do not know if that happens in Tomcat, or at what level it 
happens; but we can certainly revisit this subject with the luminaries 
on this forum).

2) try to organise the files on your site, in such a way that you can 
detect in your filter, by the URL alone, what is supposed to be static 
content and what not.
For example, if all your javascript libraries were stored in directories 
whose path contains "/js/", then your filter would know right away what 
to let pass or not.

After writing the above, I realise that this is what the "default 
servlet" is supposedly for : catching all requests which do not 
explicitly match other servlet url-matching expressions.
But the syntax used for this URL-matching, according to the Servlet 
Spec, may not be the easiest to manipulate for that.
So maybe your servlet filter would still have a role there.

And of course if the purpose of your filter is precisely to return a 
"smart" answer in the case a file does not exist, then that will not 
satisfy you.



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


Mime
View raw message