I have the following Rest resource that loads a file from the database. It works fine in the browser, however, when I try to do this using the Java client as shown below, I get 406 (error not accepted).
... @RequestMapping(value="/download/{name}", method=RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public @ResponseBody HttpEntity<byte[]> downloadActivityJar(@PathVariable String name) throws IOException { logger.info("downloading : " + name + " ... "); byte[] file = IOUtils.toByteArray(artifactRepository.downloadJar(name)); HttpHeaders header = new HttpHeaders(); header.set("Content-Disposition", "attachment; filename="+ name + ".jar"); header.setContentLength(file.length); return new HttpEntity<byte[]>(file, header); } ...
The client is deployed on the same server with a different port (the message gives the correct name):
... RestTemplate restTemplate = new RestTemplate(); String url = "http://localhost:8080/activities/download/" + message.getActivity().getName(); File jar = restTemplate.getForObject(url, File.class); logger.info("File size: " + jar.length() + " Name: " + jar.getName()); ...
What am I missing here?
source share