title: Spring REST returning PDF - Response status 406 (not acceptable)
body: <p>I read many questions on SO about this type of issue, but all of them recommend using the correct Jackson version. This is my current situation:</p>
  
  <p>REST API:</p>
  
  <pre><code>@RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET, produces = "application/pdf")
      @Override
      public ResponseEntity&lt;InputStream&gt; getPdfContractById(@PathVariable("id") Long id);
  </code></pre>
  
  <p>Using <code>Accept:*/*</code> produces an error in mapping the request (404 occurs)</p>
  
  <p>From my pom:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
          &lt;version&gt;2.4.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;version&gt;2.4.1.1&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>I also tried to add these two dependencies, but nothing changes:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
          &lt;version&gt;1.9.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
          &lt;version&gt;1.9.13&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Response client-side: <code>There was an unexpected error (type=Not Acceptable, status=406).</code>Headers incude:</p>
  
  <pre><code>    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip, deflate, sdch
  </code></pre>
  
  <p>What's wrong with it?</p>
  
  <p><hr>
  <b>More details</b></p>
  
  <p>I am using this code to return the remote PDF file:</p>
  
  <pre><code>    URL url = null;
      try {
          url = new URL(urlStr);
      } catch (MalformedURLException e) {
          e.printStackTrace();
          throw new MyException(e.getMessage());
      }
      InputStream pdfFile = null;
      try {
          pdfFile = url.openStream();
      } catch (IOException e) {
          e.printStackTrace();
          throw new MyException(e.getMessage());
      }
  
      ResponseEntity&lt;InputStream&gt; re = ResponseEntity
              .ok()
                      //     .headers(headers)
                      //     .contentLength(contentLength)
              .contentType(
                      MediaType.parseMediaType("application/pdf"))
              .body(pdfFile);
     return re;
  </code></pre>