Description
David Cole opened SPR-13645 and commented
Prior to 4.2.2, the following code snippet (Groovy) would derive the file name (I believe from the @RequestMapping
value) and set the Content-Disposition response header automatically:
@RequestMapping(value = "{path}/{fileName}.jnlp", method = RequestMethod.GET, produces = "application/x-java-jnlp-file")
String getJnlpFile(@PathVariable String path, @PathVariable String fileName) {
//Get the resource content as text
fileName += ".jnlp"
def filePath = path + "/" + fileName
Resource jnlp = getResourceContent(filePath)
InputStream is = jnlp.inputStream
String text = is.text
is.close()
//Return results after variable replacement
jnlpSubstitution(path, fileName, text)
}
Header set in response:
Content-Disposition: attachment;filename=Application.jnlp
After upgrading to 4.2.2 the value of the Content-Disposition header changed to:
Content-Disposition: attachment;filename=f.txt
I was able make a code change to achieve the same result, but the behavior change has forced me to add additional code to set the HttpHeaders and return a ResponseEntity instead of simple text:
@RequestMapping(value = "{path}/{fileName}.jnlp", method = RequestMethod.GET, produces = "application/x-java-jnlp-file")
def getJnlpFile(@PathVariable String path, @PathVariable String fileName) {
//Get the resource content as text
fileName += ".jnlp"
HttpHeaders headers = new HttpHeaders()
headers.set("Content-Disposition", "attachment;filename=$fileName")
def filePath = path + "/" + fileName
Resource jnlp = getResourceContent(filePath)
InputStream is = jnlp.inputStream
String text = is.text
is.close()
//Return results after variable replacement
text = jnlpSubstitution(path, fileName, text)
new ResponseEntity<String>(text, headers, HttpStatus.OK)
}
This seems like a degradation of the behavior to me. Can anyone identify this as a defect, or give instruction on an alternate, cleaner way to achieve the same result?
Affects: 4.2.2
Issue Links:
- Content-Disposition added for @ResponseBody methods explicitly mapped to ".html" or other extensions [SPR-13629] #18207 Content-Disposition added for
@ResponseBody
methods explicitly mapped to ".html" or other extensions ("duplicates")