<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jucosorin" rel="nofollow">Sorin Jucovschi</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6178?redirect=false" rel="nofollow">SPR-6178</a></strong> and commented</p>
<p dir="auto">In my application I have a ContentNegotiatingViewResolver set to handle <strong>html</strong> , <strong>xml</strong> and <strong>json</strong>. Following is the beans declaration:<br>
\</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;bean
    class=&quot;org.springframework.web.servlet.view.ContentNegotiatingViewResolver&quot;
    p:order=&quot;1&quot;&gt;
    &lt;property name=&quot;mediaTypes&quot;&gt;
      &lt;map&gt;
        &lt;entry key=&quot;html&quot; value=&quot;text/html&quot;/&gt;
        &lt;entry key=&quot;xml&quot; value=&quot;application/xml&quot; /&gt;
        &lt;entry key=&quot;json&quot; value=&quot;application/json&quot; /&gt;
      &lt;/map&gt;
    &lt;/property&gt;
    &lt;property name=&quot;defaultViews&quot;&gt;
      &lt;list&gt;
        &lt;bean class=&quot;org.springframework.web.servlet.view.xml.MarshallingView&quot;&gt;
          &lt;property name=&quot;marshaller&quot;&gt;
            &lt;bean class=&quot;org.springframework.oxm.xstream.XStreamMarshaller&quot;
              p:autodetectAnnotations=&quot;true&quot; /&gt;
          &lt;/property&gt;
        &lt;/bean&gt;
        &lt;bean
          class=&quot;org.springframework.web.servlet.view.json.MappingJacksonJsonView&quot; /&gt;
      &lt;/list&gt;
    &lt;/property&gt;
    &lt;property name=&quot;ignoreAcceptHeader&quot; value=&quot;true&quot;/&gt;
    &lt;property name=&quot;defaultContentType&quot; value=&quot;application/xml&quot;/&gt;
  &lt;/bean&gt;

  &lt;bean id=&quot;jspViewResolver&quot;
    class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;
    p:prefix=&quot;/WEB-INF/jsp/&quot; p:suffix=&quot;.jsp&quot; p:order=&quot;2&quot; /&gt;"><pre class="notranslate">&lt;<span class="pl-ent">bean</span>
    <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.web.servlet.view.ContentNegotiatingViewResolver<span class="pl-pds">"</span></span>
    <span class="pl-e">p</span><span class="pl-e">:</span><span class="pl-e">order</span>=<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>mediaTypes<span class="pl-pds">"</span></span>&gt;
      &lt;<span class="pl-ent">map</span>&gt;
        &lt;<span class="pl-ent">entry</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>html<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>text/html<span class="pl-pds">"</span></span>/&gt;
        &lt;<span class="pl-ent">entry</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>xml<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>application/xml<span class="pl-pds">"</span></span> /&gt;
        &lt;<span class="pl-ent">entry</span> <span class="pl-e">key</span>=<span class="pl-s"><span class="pl-pds">"</span>json<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>application/json<span class="pl-pds">"</span></span> /&gt;
      &lt;/<span class="pl-ent">map</span>&gt;
    &lt;/<span class="pl-ent">property</span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>defaultViews<span class="pl-pds">"</span></span>&gt;
      &lt;<span class="pl-ent">list</span>&gt;
        &lt;<span class="pl-ent">bean</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.web.servlet.view.xml.MarshallingView<span class="pl-pds">"</span></span>&gt;
          &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>marshaller<span class="pl-pds">"</span></span>&gt;
            &lt;<span class="pl-ent">bean</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.oxm.xstream.XStreamMarshaller<span class="pl-pds">"</span></span>
              <span class="pl-e">p</span><span class="pl-e">:</span><span class="pl-e">autodetectAnnotations</span>=<span class="pl-s"><span class="pl-pds">"</span>true<span class="pl-pds">"</span></span> /&gt;
          &lt;/<span class="pl-ent">property</span>&gt;
        &lt;/<span class="pl-ent">bean</span>&gt;
        &lt;<span class="pl-ent">bean</span>
          <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.web.servlet.view.json.MappingJacksonJsonView<span class="pl-pds">"</span></span> /&gt;
      &lt;/<span class="pl-ent">list</span>&gt;
    &lt;/<span class="pl-ent">property</span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>ignoreAcceptHeader<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>true<span class="pl-pds">"</span></span>/&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>defaultContentType<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>application/xml<span class="pl-pds">"</span></span>/&gt;
  &lt;/<span class="pl-ent">bean</span>&gt;

  &lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>jspViewResolver<span class="pl-pds">"</span></span>
    <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>org.springframework.web.servlet.view.InternalResourceViewResolver<span class="pl-pds">"</span></span>
    <span class="pl-e">p</span><span class="pl-e">:</span><span class="pl-e">prefix</span>=<span class="pl-s"><span class="pl-pds">"</span>/WEB-INF/jsp/<span class="pl-pds">"</span></span> <span class="pl-e">p</span><span class="pl-e">:</span><span class="pl-e">suffix</span>=<span class="pl-s"><span class="pl-pds">"</span>.jsp<span class="pl-pds">"</span></span> <span class="pl-e">p</span><span class="pl-e">:</span><span class="pl-e">order</span>=<span class="pl-s"><span class="pl-pds">"</span>2<span class="pl-pds">"</span></span> /&gt;</pre></div>
<p dir="auto">//</p>
<p dir="auto">As seen in the code I turned off <strong>acceptHeader</strong> and want to have a default content type of <strong>application/xml</strong>. When I access the page without an explicit extension I get a java.lang.UnsupportedOperationException:</p>
<p dir="auto">java.lang.UnsupportedOperationException<br>
at java.util.AbstractList.set(AbstractList.java:115)<br>
at java.util.AbstractList$ListItr.set(AbstractList.java:412)<br>
at java.util.Collections.sort(Collections.java:121)<br>
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:344)<br>
at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1105)<br>
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1052)<br>
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:808)<br>
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)<br>
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)<br>
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)<br>
...</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 RC1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398097805" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10831" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10831/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10831">#10831</a> Using ignoreAcceptHeader and defaultContentType together causes problems. (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=egervari" rel="nofollow">Ken Egervari</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6163?redirect=false" rel="nofollow">SPR-6163</a></strong> and commented</p>
<p dir="auto">Using ignore accept header and default content type causes problems. Here is my bean xml:</p>
<p dir="auto">{code?xml}<br>
&lt;bean id="contentNegotiatingViewResolver"<br>
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;<br>
&lt;property name="order" value="1"/&gt;<br>
&lt;property name="ignoreAcceptHeader" value="true" /&gt;<br>
&lt;property name="defaultContentType" value="text/html" /&gt;<br>
&lt;property name="mediaTypes"&gt;<br>
&lt;map&gt;<br>
&lt;entry key="ftl" value="text/html"/&gt;<br>
&lt;entry key="xml" value="application/xml"/&gt;<br>
&lt;entry key="json" value="application/json"/&gt;<br>
&lt;entry key="atom" value="application/atom+xml"/&gt;<br>
&lt;entry key="rss" value="application/rss+xml"/&gt;<br>
&lt;/map&gt;<br>
&lt;/property&gt;<br>
&lt;property name="defaultViews"&gt;<br>
&lt;list&gt;<br>
&lt;bean class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;<br>
&lt;property name="contentType" value="application/xml" /&gt;<br>
&lt;property name="marshaller"&gt;<br>
&lt;bean class="org.springframework.oxm.xstream.XStreamMarshaller"&gt;<br>
&lt;property name="autodetectAnnotations" value="true"/&gt;<br>
&lt;/bean&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;<br>
&lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt;<br>
&lt;property name="contentType" value="application/json" /&gt;<br>
&lt;/bean&gt;<br>
&lt;/list&gt;<br>
&lt;/property&gt;<br>
&lt;property name="viewResolvers"&gt;<br>
&lt;list&gt;<br>
&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"&gt;<br>
&lt;property name="contentType" value="text/html" /&gt;<br>
&lt;property name="order" value="2"/&gt;<br>
&lt;property name="cache" value="false"/&gt;<br>
&lt;property name="prefix" value=""/&gt;<br>
&lt;property name="suffix" value=".ftl"/&gt;<br>
&lt;property name="exposeSpringMacroHelpers" value="true"/&gt;<br>
&lt;/bean&gt;<br>
&lt;/list&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
Here is the exception that is generated:
"><pre class="notranslate"><code class="notranslate">
Here is the exception that is generated:

</code></pre></div>
<p dir="auto">SEVERE: Servlet.service() for servlet jawbs threw exception<br>
java.lang.UnsupportedOperationException<br>
at java.util.AbstractList.set(AbstractList.java:115)<br>
at java.util.AbstractList$ListItr.set(AbstractList.java:412)<br>
at java.util.Collections.sort(Collections.java:121)<br>
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:344)<br>
at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1105)<br>
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1052)<br>
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:808)<br>
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)<br>
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)<br>
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)<br>
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)<br>
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
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!"><pre class="notranslate"><code class="notranslate">
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!
</code></pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 RC1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398097922" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10846" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10846/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10846">#10846</a> Using defaultContentType property in ContentNegotiatingViewResolver throws java.lang.UnsupportedOperationException (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/0c47a01953d060a6aa8f306b03730078a60ddf39/hovercard" href="https://github.com/spring-projects/spring-framework/commit/0c47a01953d060a6aa8f306b03730078a60ddf39"><tt>0c47a01</tt></a></p>