0

How can we provide document download using camel API, I need to provide an api using camel rest to response the file as download and I have the logic to create the pdf using apache fop, but i need to get some information how to respond the file as rest response using camel rest.

@RestController
public class MyController {

    @Autowired
    ICityService cityService;

    @RequestMapping(
        value = "/pdfreport", 
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_PDF_VALUE
    )
    public ResponseEntity<InputStreamResource> citiesReport() throws IOException {

        List<City> cities = (List<City>) cityService.findAll();

        ByteArrayInputStream bis = GeneratePdfReport.citiesReport(cities);

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "inline; 
        filename = citiesreport.pdf");

        return ResponseEntity
            .ok()
            .headers(headers)
            .contentType(MediaType.APPLICATION_PDF)
            .body(new InputStreamResource(bis));
    }
}
jozef
  • 11
  • 3
  • you can use apache pdfbox to create PDFs. https://pdfbox.apache.org/1.8/cookbook/pdfacreation.html – Salil Sep 02 '18 at 16:22
  • Thanks, but i am aware about the PDF creation functionality. But need to convert the Spring rest api to camel rest api – jozef Sep 03 '18 at 04:49

0 Answers0