Skip to content

Add ignoreJafMediaTypes to ContentNegotiatingViewResolver [SPR-7081] #11741

@spring-projects-issues

Description

@spring-projects-issues

David Turanski opened SPR-7081 and commented

The configuration below is intended to render an Excel document for a .xls extension when the view name is "accounts/list" in a Web application. No extension, or .html should resolve to the TilesView. This works, however any non-html extension, e.g., /accounts.foo also renders an Excel document . This happens because the JAF file types map returns a media type of "application/octet-stream" for arbitrary file extensions. Thus the defaultContentType is suppressed.

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="xls" value="#{ excelView.getContentType() }" />
</map>
</property>
<property name="defaultContentType" value="text/html" />
<property name="ignoreAcceptHeader" value="true" />
</bean>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="contentType" value="text/html" />
</bean>
<!-- A view that generates a Account report as an Excel spreadsheet -->
<bean id="excelView" name="accounts/list" class="rewardsonline.accounts.AccountsExcelView" />
The proposed solution is to add an ignoreJafFileTypes property. If set to true, will produce the desired effect: .xls renders the Excel document, any other type reverts to the default HTML. The proposed patch and unit tests are attached.


Attachments:

Referenced from: commits e6b0a1d

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions