title: Download a server-generated KML file with Spring MVC
body: <p>I want to create an API that generates a KML file compatible with Google Earth/Maps API for downloading.</p>
  
  <p>Currently I'm facing a 406 Not Acceptable error.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>@RequestMapping(
          value = "/kml",
          method = RequestMethod.GET)
  public @ResponseBody HttpEntity&lt;InputStream&gt; kml() throws IOException
  {
      InputStream is = geocodingManager.generateKml(geocodingProviderId);
  
      HttpHeaders headers = new HttpHeaders();
  
      headers.add("content-disposition", "attachment; filename=Samo.kml");
      headers.add("content-type", "application/vnd.google-earth.kml+xml");
  
      return new HttpEntity&lt;InputStream&gt;(is, headers);
  
  }
  </code></pre>
  
  <p>If I invoke the API (<code>http://localhost/context/path-to/kml</code>) with browser or RESTClient plugin (even by setting explicitly the <code>Accept: *.*</code> or <code>Accept: */*</code> headers) I always get error <code>406 Not Acceptable</code>.</p>
  
  <p>I had first tried to set the <code>produces</code> attribute to the annotation, then decided to remove it as an attempt, but that didn't fix.</p>
  
  <p>How can I download a KML to my browser?</p>