3

In an existing java web app hosted on a Tomcat 6 server, I noticed that all URLs finishing with some specific extensions like .png or .gif are served statically whereas if I replace the extension by something more exotic like .eot then it gets handled by a servlet.

Where is this list of file extensions configured? I checked in web.xml and server.xml but did not find any mention to png or gif.

user11153
  • 8,536
  • 5
  • 47
  • 50
sdabet
  • 18,360
  • 11
  • 89
  • 158

3 Answers3

4

All files are served statically as long as no servlet(-mapping) is defined. The mime extensions are predefined in Tomcats default web.xml in folder /conf:

<!-- ===================== Default MIME Type Mappings =================== -->
<!-- When serving static resources, Tomcat will automatically generate    -->
<!-- a "Content-Type" header based on the resource's filename extension,  -->
<!-- based on these mappings.  Additional mappings can be added here (to  -->
<!-- apply to all web applications), or in your own application's web.xml -->
<!-- deployment descriptor.                                               -->

<mime-mapping>
    <extension>123</extension>
    <mime-type>application/vnd.lotus-1-2-3</mime-type>
</mime-mapping>
...
Stefan
  • 12,108
  • 5
  • 47
  • 66
  • There is already a mime-mapping for the `eot` extension: `eotapplication/vnd.ms-fontobject`. Why isn't it served like any other static resource then? – sdabet Apr 11 '14 at 13:01
  • How is it served? I guess you mean not like a download but opening in your browser? – Stefan Apr 11 '14 at 16:16
2

In addition to @Stefoan sollution which is the optimal one Tomcat AS defines the DefaultServlet mapped to default as name and serves all the static resources (jpg,html,css,gif...) upon it. Here you can find it's documentation.

So you can merely add a servlet mapping pointing to it to serve some custom file extension as a static resource:

<servlet-mapping>   
  <servlet-name>default</servlet-name>
  <url-pattern>*.eot</url-pattern>
</servlet-mapping>
user11153
  • 8,536
  • 5
  • 47
  • 50
tmarwen
  • 15,750
  • 5
  • 43
  • 62
2

Well, in fact my problem was specific to Hippo CMS / Bloomreach Experience configuration (which is used in my project). It required to add an .eot to the list of hst:suffixexclusions property under /hst:hst/hst:hosts node, as described in HippoCMS - Request Handling - Mount Matching.

You can also instead add exlusion rules into site/src/main/webapp/WEB-INF/hst-config.properties file:

filter.prefix.exclusions = /ping/, /fonts/
filter.suffix.exclusions = .eot, .woff, .woff2

This will solve the issue that Tomcat is returning HTTP 404 error code on most of font files.

user11153
  • 8,536
  • 5
  • 47
  • 50
sdabet
  • 18,360
  • 11
  • 89
  • 158