1

I have an endpoint that should generate a CSV report with a stream. I implemented the endpoint like this:

     @GetMapping(value = "/sessions/csv")
      public Flux<CsvEntity> getCsv() {
        return csvService.exportToCsv();
  }

Now I'm getting the response through a stream, but I don't have headers and the data is shown with the field name. I tried to use StatefulBeanToCsv of opencsv but for that I need a writer. When I used servlets I could initialize a writer with the response.getOutputStream() but with webflux I couldn't make it work.

I didn't find any documentation for that. Any help?

Yuval
  • 764
  • 1
  • 9
  • 23
  • I'm not sure but I think your problem is that right now you are returning a stream of chunks, so you can find a way to create a file with frontend or you have to send a file with the old way. Maybe you can send a Mono or something else? Let me know please – firegloves Dec 09 '19 at 13:56
  • @firegloves StreamingResponseBody is a servlet class, it can't be used in a reactive context – Yuval Dec 10 '19 at 09:18
  • The only thing I can think of is to create a `ByteArrayOutputStream`, to set this in the `StatefulBeanToCsv` and if you have a bean, you write it to beanToCsv, extract the content of baos, reset the baos, and now you are able to push the extracted text to bytebuffer in the response. – wargre Feb 05 '20 at 14:12
  • 1
    @Yuval what did you end up doing here? I am currently looking into a similar problem. – Chris K Sep 03 '20 at 08:52

0 Answers0