HTTP 406 downloading a file with rest call
<p>I followed this <a href="http://www.leveluplunch.com/java/tutorials/032-return-file-from-spring-rest-webservice/" rel="nofollow">tutorial</a> to implement rest API with Spring Boot for downloading files (xml format). </p>

<p>My controller class is as follows:</p>

<pre><code>@RestController
public class RistoreController {
    @Autowired
    private RistoreService ristoreService;

    @RequestMapping( 
            value = "/ristore/foundation/{trf}", 
            method = RequestMethod.GET, 
            produces = "application/xml")
    public ResponseEntity&lt;InputStream&gt; getXMLById(@PathVariable("trf") String trf) throws IOException {
        InputStream inputStream = ristoreService.findByTRF(trf);
        return ResponseEntity
                .ok()
                .contentType(MediaType.parseMediaType("application/octet-stream"))
                .body(inputStream);
    }
}
</code></pre>

<p>I have service interface <code>RistoreService</code> autowired in the controller and Bean class for that service looks like this:</p>

<pre><code>@Service
public class RistoreServiceBean implements RistoreService {
    public InputStream findByTRF(String trf) throws IOException {
        String filePath = "/Users/djiao/Box Sync/Work/Projects/RIStore/foundation/foundation_new/" + trf + ".xml";
        File file = new File(filePath);
        return new FileInputStream(file);
    }
}
</code></pre>

<p>I tested the application using the following curl command:</p>

<pre><code>curl -i -H "Accept: application/xml" http://localhost:8080/ristore/foundation/TRF133672_1455294493597
</code></pre>

<p>However, I got 406 error, "Not Acceptable". Something wrong with the file format?</p>