Monday, 12 July 2010

Fun with portlets - Vignette Error: "The provided content type, application/octet-stream, is not a valid response content type." (FIXED)

PROBLEM:

I had a portlet (written using Spring MVC) where I had to download a
CSV file, so in the code, I was making this call

response.setContentType("application/vnd.ms-excel");

But I kept getting the error below from Vignette.

===============================

General Error

The provided content type, application/octet-stream, is not a valid
response content type. Please check the valid response content types
by invoking PortletRequest.getResponseContentTypes().

Please contact your System Administrator for assistance.

class java.lang.IllegalArgumentException

================================

I tried using "text/csv" and "application/octet-stream" and same response.

SOLUTION:

This was caused by a missing config in portlet.xml

The portlet I was working on had this config:

<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>

and to fix the above error, I had to add this:

<supports>
<mime-type>application/vnd.ms-excel</mime-type>
<portlet-mode>view</portlet-mode>
</supports>

No comments: