I want to send a file from the server side to the client side using rest service I'm using spring MVC. I used this service method:
public ResponseEntity<InputStreamResource> postFile() throws Exception {
DocumentDaoImpl dao = new DocumentDaoImpl();
Document docCmis = (Document) dao.getDocument("workspace://SpacesStore/ae6d1722-0f08-49ab-a73b-c07036001318");
byte[] myByteArray = readContent(docCmis.getContentStream().getStream());
ClassPathResource myFile = new ClassPathResource(docCmis.getContentStreamFileName());
//System.out.println("eeeee"+pdfFile);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity
.ok()
.headers(headers)
.contentLength(myByteArray.length)
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(docCmis.getContentStream().getStream()));
}
and this function in a rest controller class
@RequestMapping(value = "/downloadPDFFile",produces = { "application/json" }, method = RequestMethod.GET)
@ResponseBody
public ResponseEntity downloadPDFFile() throws Exception {
return courriersArrivésServices.postFile();
}
then with a rest call using RestTemplate class,i tryied to get my file
Map<String, Object> selectedCourrier=restTemplate.getForObject(SERVER_URI + "/getCourrierDetails"+"?id="+id, HashMap.class);
But that didn't work for me and gives me this error
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.http.ResponseEntity] and content type [application/octet-stream]