tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garret Wilson <gar...@globalmentor.com>
Subject programmatically setting MIME mappings for static-only site
Date Fri, 19 Apr 2019 16:20:24 GMT
I'm wanting to embed Tomcat to only serve static files (for the moment). 
That is, no JSP, etc. I also want to have the welcome files completely 
customizable.

So instead of calling `tomcat.addWebapp()`, I go the completely 
programmable route and call `tomcat.addContext()`, 
`context.createWrapper()`, etc. This makes my bypass the 
`DefaultWebXmlListener`, which would have called 
`initWebappDefaults(Context ctx)` to set up the welcome files and such 
myself.

But `initWebappDefaults()` also sets up the default MIME mappings. And 
`Tomcat.DEFAULT_MIME_MAPPINGS` is private.

So the situation seems to be that Tomcat forces me to choose between 
creating a full-fledged JSP server, or setting up all the MIME types 
with some list of my own. Maybe it would be good for me to have my own 
list eventually, but for now this seems like an artificial choice forced 
upon me.

Part of the problem seems to be that the (ancient?) code has the MIME 
mappings as a string array!! Heaven knows we don't want to expose that. 
It should really be turned into a read-only map and then exposed so we 
can use it.

Then of course I see the comment:

 > TODO: would a properties resource be better ? Or just parsing 
/etc/mime.types ?

To answer part of that question, we can't just parse `/etc/mime.types` 
because the embedded server might not even have an `/etc/mime.types` 
file. This should definitely be put into a properties resource, I would 
think.

So I've probably answered my own question; this is an old TODO that 
needs to be done, I suppose?

Garret


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


Mime
View raw message