0

I'm trying to let users download a text file from my camel application. The trouble is, is that the file contains 0 bytes (should be 435b and is in the debugger). Could someone look at the code and advise?

I'm trying to let users download a text file from my camel application. The trouble is, is that the file contains 0 bytes (should be 435b and is in the debugger). Could someone look at the code and advise?

@Component
public class CalendarRoute extends ExceptionHandlingRoutes {

  @Autowired
  private CalendarService calendarService;

  @Override
  public void configure() {
    super.configure();
    rest("/calendar").description("Foo calendaring")
        .produces("plain/text")
        .get("/").description("accepts data to create an ics file with")
        .to("direct:getIcs");

    from("direct:getIcs")
        .process(getIcs());
  }

  private Processor getIcs() {
    return exchange -> {
      exchange.getIn().removeHeader("Content-Length");
      exchange.getIn().setHeader("Content-Type", MediaType.parseMediaType("text/calendar"));
      byte[] file = calendarService.generateCalendarFile();
      exchange.getIn().setBody(file);
    };
  }
}
Rick
  • 485
  • 6
  • 23
  • Can you try adding `exchange.getIn().removeHeader("Content-Length"));` in the processor. Could smell like that the content-lenght from the client request gets used when saving the file. Also you may need to set a header with "Content-Type" to indicate its a file being returned - I cannot remember what that exact header is. And what camel http component are you using together with the rest-dsl? Jetty, Servlet, Restlet or something else? And what is the Camel version? – Claus Ibsen Aug 28 '18 at 05:59
  • @ClausIbsen Thanks for the reply! I've updated the code but it's still an empty file. I believe (from looking at the pom) that we're using Servlet. Camel version 2.20.2. – Rick Aug 29 '18 at 22:18
  • Solved! I'm editing my question – Rick Aug 30 '18 at 01:44

1 Answers1

0

solved. The changes are in the original question

Rick
  • 485
  • 6
  • 23