пт, 19 апр. 2019 г. в 19:29, Garret Wilson <gar...@globalmentor.com>:> > 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.
Also note that the value is not synch'ed with the default list in conf/web.xml. E.g the following entries from the top of the default list are missing <mime-mapping> <extension>123</extension> <mime-type>application/vnd.lotus-1-2-3</mime-type> </mime-mapping> <mime-mapping> <extension>7z</extension> <mime-type>application/x-7z-compressed</mime-type> </mime-mapping> (and many others) Some years ago the list in web.xml was synch'ed to the similar file in Apache HTTPD, but the list used by embedded Tomcat was not updated. Previous discussion: http://markmail.org/message/gjkixk7wysopyztp > 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. An array is a bad API, but generally it is faster to create an array. All the time used to create a map goes to waste if it is only accessed sequentially, like it is done here. The only place where the values are used is for (int i = 0; i < DEFAULT_MIME_MAPPINGS.length;) { ctx.addMimeMapping(DEFAULT_MIME_MAPPINGS[i++], DEFAULT_MIME_MAPPINGS[i++]); } There are some people who ask for options to make Tomcat to start up faster (e.g. in a "serverless" environment when you start a process on demand and pay for execution time). Not being careful here may negatively affect the startup time. The current 'DEFAULT_MIME_MAPPINGS' field is a static one and is always created when the class is loaded, regardless of whether it will be used or not. > 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. For reference, https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types > So I've probably answered my own question; this is an old TODO that > needs to be done, I suppose? > Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org