How to add a new mime type to Glassfish


1.) Add the mime type to the the domain’s default-web.xml (ex. domains/domain1/config/default-web.xml)
2.) Restart the domain
3.) Redeploy the web application where the file related to the new mime type is being served.

Sound simple? It is simple! But it took me a week to figure this out! The documentation is flaky on this subject. First, I just tried the Help in the Admin Console. I searched mime. Nothing. So I tried the documentation. In the Developer’s Guide, I found this:

Using the default-web.xml File

You can use the default-web.xml file to define features such as filters and security constraints that apply to all web applications.

The mime-mapping elements in default-web.xml are global and inherited by all web applications. You can override these mappings or define your own using mime-mapping elements in your web application’s web.xml file. For more information about mime-mapping elements, see the Servlet specification.

You can use the Admin Console to edit the default-web.xml file. For details, click the Help button in the Admin Console. As an alternative, you can edit the file directly using the following steps.

ProcedureTo Use the default-web.xml File

  1. Place the JAR file for the filter, security constraint, or other feature in the domain-dir/lib directory.
  2. Edit the domain-dir/config/default-web.xml file to refer to the JAR file.
  3. Restart the server.

From this,  I gathered 2 important facts:

1.) I can add a global mime type to default-web.xml

2.) I will probably need to start the server

On the glassfish forum, I gathered that for default-web.xml changes to take effect, the application that needs them requires a redeployment.  Great!  No problem…didn’t work.I was overlooking a small detail.  I redeployed the wrong application.  I redeployed that application that links to the file I was miming, instead of the application that actually contains the file:  the “/” application that serves the purpose of document root.  Once I redeployed “/”, it all worked fine.

Advertisements

6 thoughts on “How to add a new mime type to Glassfish

  1. David,
    I’m a tech writer on NetBeans at Sun, covering web services. I want to create a tutorial on sending binary data as a SOAP attachment using the MTOM, XOP and/or Swaref. It seems comparatively straightforward to send image data this way (see this tutorial but I’m wondering about sending some nasty proprietary business stuff, like pps application/powerpoint or xls application/vnd.ms-excel. Do you have any suggestions?

  2. Pingback: Revisiting the whole binary serialization/deserialization thing… « Regular, Average Java Programmer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s