Issue 1:
Sorin Jucovschi opened SPR-6178 and commented

In my application I have a ContentNegotiatingViewResolver set to handle html , xml and json. Following is the beans declaration:

\

<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
p:order="1">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html"/>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean class="org.springframework.oxm.xstream.XStreamMarshaller"
p:autodetectAnnotations="true" />
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
<property name="ignoreAcceptHeader" value="true"/>
<property name="defaultContentType" value="application/xml"/>
</bean>

<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="2" />

//

As seen in the code I turned off acceptHeader and want to have a default content type of application/xml. When I access the page without an explicit extension I get a java.lang.UnsupportedOperationException:

java.lang.UnsupportedOperationException

at java.util.AbstractList.set(AbstractList.java:115)

at java.util.AbstractList$ListItr.set(AbstractList.java:412)

at java.util.Collections.sort(Collections.java:121)

at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:344)

at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1105)

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1052)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:808)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)

...

Affects: 3.0 RC1

Issue Links:

#10831 Using ignoreAcceptHeader and defaultContentType together causes problems. ("duplicates")

Issue 2:
Ken Egervari opened SPR-6163 and commented

Using ignore accept header and default content type causes problems. Here is my bean xml:

{code?xml}

<bean id="contentNegotiatingViewResolver"

class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

<property name="order" value="1"/>

<property name="ignoreAcceptHeader" value="true" />

<property name="defaultContentType" value="text/html" />

<property name="mediaTypes">

<map>

<entry key="ftl" value="text/html"/>

<entry key="xml" value="application/xml"/>

<entry key="json" value="application/json"/>

<entry key="atom" value="application/atom+xml"/>

<entry key="rss" value="application/rss+xml"/>

</map>

</property>

<property name="defaultViews">

<list>

<bean class="org.springframework.web.servlet.view.xml.MarshallingView">

<property name="contentType" value="application/xml" />

<property name="marshaller">

<bean class="org.springframework.oxm.xstream.XStreamMarshaller">

<property name="autodetectAnnotations" value="true"/>

</bean>

</property>

</bean>

<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">

<property name="contentType" value="application/json" />

</bean>

</list>

</property>

<property name="viewResolvers">

<list>

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">

<property name="contentType" value="text/html" />

<property name="order" value="2"/>

<property name="cache" value="false"/>

<property name="prefix" value=""/>

<property name="suffix" value=".ftl"/>

<property name="exposeSpringMacroHelpers" value="true"/>

</bean>

</list>

</property>

</bean>

Here is the exception that is generated:

SEVERE: Servlet.service() for servlet jawbs threw exception

java.lang.UnsupportedOperationException

at java.util.AbstractList.set(AbstractList.java:115)

at java.util.AbstractList$ListItr.set(AbstractList.java:412)

at java.util.Collections.sort(Collections.java:121)

at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:344)

at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1105)

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1052)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:808)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

If there is a short-term fix, I'd love to hear it.

Basically what I want to do is have no extension (like /rest/hotels/list) go to text/html and still have the json, xml, etc. views work with the extensions on any/all browsers.

Thanks!

Affects: 3.0 RC1

Issue Links:

#10846 Using defaultContentType property in ContentNegotiatingViewResolver throws java.lang.UnsupportedOperationException ("is duplicated by")

Referenced from: commits 0c47a01