title: Controller returning inputstream - content negotiation and media types
body: <h2>Introduction</h2>
  
  <p>I have a question about a RestController and a Test .</p>
  
  <p>I have the following <code>PostMapping</code>:</p>
  
  <pre><code>@PostMapping(path = "/download/as/zip/{zipFileName}" )
      @ResponseBody
      public ResponseEntity&lt;InputStreamResource&gt; downloadDocumentZip(@RequestHeader(required=false,name="X-Application") String appName, @RequestBody ZipFileModel zipFileModel, @PathVariable("zipFileName") String zipFileName)
  </code></pre>
  
  <p>And I have the following Test:</p>
  
  <pre><code>Response response = given(this.requestSpecification).port(port)
                  .filter(document("downloadAsZip",
                          preprocessRequest(prettyPrint()),
                          requestHeaders(headerWithName("X-Application").description("Owner application")),
                          pathParameters(parameterWithName("zipFileName").description("The name of the resulting zip file. Mostly not needed/optional.")))
                  )
                  .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
                  .header(new Header(HEADER, "themis"))
                  .body(jsonContent)
                  .when()
                  .post("/download/as/zip/{zipFileName}", "resultFile.zip");
  </code></pre>
  
  <p>This works and 200 is returned. </p>
  
  <h2>First Question</h2>
  
  <p>Now I am a bit confused about the meaning of <code>.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)</code> within the Test. </p>
  
  <p>Content-type is the header on the returned response. But in this test it is being included while making the test request ? <strong>Or is it signifying in this case that we are sending JSON in the request body?</strong>  </p>
  
  <h2>Second Question</h2>
  
  <p>I know that my controller method should consume JSON, and returns Bytes. 
  So hence, I make the following change:</p>
  
  <p>@PostMapping(path = "/download/as/zip/{zipFileName}", consumes = <code>MediaType.APPLICATION_JSON_VALUE)</code></p>
  
  <p><strong>This works so far.</strong> </p>
  
  <p>So then I add the following:</p>
  
  <pre><code>@PostMapping(path = "/download/as/zip/{zipFileName}", consumes = MediaType.APPLICATION_JSON_VALUE, 
  produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
  </code></pre>
  
  <p>And it fails:</p>
  
  <pre><code>java.lang.AssertionError: 
  Expected :200
  Actual   :406
   &lt;Click to see difference&gt;
  </code></pre>
  
  <p>So I changed my test to be the following:</p>
  
  <pre><code>.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
                  .accept(MediaType.APPLICATION_OCTET_STREAM_VALUE)
  </code></pre>
  
  <p>This fails once again. </p>
  
  <pre><code>Expected :200
  Actual   :406
  </code></pre>
  
  <p>So even though the client is signalling the same accept header as what the controller produces, we have an error. </p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>So should we or should we not have the <code>produces=</code> on the request mapping?</li>
  <li>Why is it failing now? Is there a conflict in consuming JSON and Producing Bytes? Or the <code>ContentType</code> within the test?</li>
  </ol>