title: Spring 3.2 with MVC, ContentNegotation, REST and PDF Generator
body: <p>Let's say, I have a REST styled controller mapping</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value="users", produces = {MediaType.APPLICATION_JSON_VALUE})
  public List&lt;User&gt; listUsers(@ReqestParams Integer offset, @ReqestParams Integer limit, @ReqestParams String query) {
      return service.loadUsers(query, offset, limit);
  }
  </code></pre>
  
  <p>Serving JSON (or even XML) is not an issue, this is easy using ContentNegotation and MessageConverters</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"&gt;
      &lt;property name="favorPathExtension" value="true" /&gt;
      &lt;property name="favorParameter" value="false" /&gt;
      &lt;property name="ignoreAcceptHeader" value="false" /&gt;
      &lt;property name="mediaTypes" &gt;
          &lt;value&gt;
              html=text/html
              json=application/json
              xml=application/xml
          &lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now, I need to add support for PDF. Naturally, I want to use (Spring) MVC + REST as much as possible. Most examples I have found implement this with an explicit definition not using REST style, e.g.</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value="users", produces = {"application/pdf"})
  public ModelAndView listUsersAsPdf(@ReqestParams Integer offset, @ReqestParams Integer limit, @ReqestParams String query) {
      List&lt;User&gt; users = listUsers(offset, limit, query); // delegated
      return new ModelAndView("pdfView", users);
  }
  </code></pre>
  
  <p>That works, but is not very comfortable because for every alternate output (PDF, Excel, ...)  I would add a request mapping.</p>
  
  <p>I have already added <code>application/pdf</code> to the content negotation resolver; unfortunately any request with a suffix <code>.pdf</code> or the Accept-Header <code>application/pdf</code> were be responded with <code>406</code>.</p>
  
  <p>What is the ideal setup for a REST/MVC style pattern to integrate alternate output like PDF?</p>