This is an old version of the Sling website, see the site conversion page for more info.
Apache Incubator
Apache Sling Website > Apache Sling > Advanced Topics > MIME Type Support

MIME Type Support

Support for MIME type mappings is generally a problematic issue. On the one hand applications have to take care to stay up to date with their mappings on the other hands in web applications it is tedious to maintain the mappings. Apache Sling takes a very user and deployment friendly approadch to this problem which is described in detail on this page.

Servlet API Support

The Servlet API specification provides a limited support for MIME type mappings :

Enter Sling: The MimeTypeService

Already at the start of the Sling project we realized, that just basing the MIME type mapping decisions on the servlet container will not yield acceptable results. For this reason the Apache Sling projects provides a spezialized and configurable service supporting such mappings: The MimeTypeService.

This service provides access to registered MIME types and their mappings with two methods:

Two more method allow to programmatically add MIME type mappings:

And More...

Besides the MimeTypeService provided by Apache Sling, there is actually more:

Configuring MIME Type Mappings

The implementation of the MimeTypeService in the Apache Sling MIME type mapping support (org.apache.sling.commons.mime) bundle supports a numnber of ways to configure and extend the set of MIME type mappings:

Please note, that existing mappings cannot be overwritten later. Thus mappings have an inherent priority:

  1. Mappings provided by the Apache httpd project's mime.types file
  2. Extensions by the Apache Sling MIME type mapping support bundle
  3. Bundles providing a META-INF/mime.types file in the order of their bundle-id (or startup order if started after the MIME type mapping support bundle)
  4. OSGi Configuration. Note that bundles started after the MIME type mapping support bundle may not overwrite mappings provided by the OSGi configuration. This may sounds like a problem, but in reality this should genrally not matter
  5. Mappings registered calling the MimeTypeService.registerMimeType method
  6. Mappings provided by MimeTypeProvider services

MIME Type Mapping File Format

The file format for MIME type mapping files is rather simple:

THe data line format described here also applies to configuration provided by the values of the mime.types property of the MIME type service configuration. The file format description applies to all META-INF/mime.types files provided by the bundles as well as input streams supplied to the MimeTypeService.registerMimeType(InputStream) method.

Web Console Plugin

The Apache Sling MIME type mapping support bundle implements a plugin for the Apache Felix Web Console which may be consulted to investigate the current contents of the MIME type mapping tables.

Last modified by fmeschbe on Mon May 18 00:26:02 PDT 2009