0

I have a Camel route that needs to receive a XML file from FTP as a stream, validate it and split it.

Everything works fine all the way to the validation, but then the split doesn't work as expected. When debugging, I found the split process doesn't find any processor when the original message is a stream. It looks very much like a bug to me.

     from("direct:start")
    .pollEnrich("ftp://user@host:21?fileName=file.xml&streamDownload=true&password=xxxx&fastExistsCheck=true&soTimeout=300000&disconnect=true")
    .to("validator:myXsd.xsd")
    .split().tokenizeXML("myTag")
    .to(to)
    .end();

In this case I can see the Exchange getting in the splitter, but no processor is found and the split does nothing. the behavior is different if I remove the validation:

     from("direct:start")
    .pollEnrich("ftp://user@host:21?fileName=file.xml&streamDownload=true&password=xxxx&fastExistsCheck=true&soTimeout=300000&disconnect=true")
    .split().tokenizeXML("myTag")
    .to(to)
    .end();

In this case, the splitter works fine.

Also, if the XML file doesn't come from a stream, then everything is fine.

   from("file:file.xml")
    .to("validator:myXsd.xsd")
    .split().tokenizeXML("myTag")
    .to(to)
    .end();

I update my Camel version to 2.15.2 but still get the same error.

pmartin8
  • 1,545
  • 1
  • 20
  • 36

2 Answers2

1

I don't know how validator works, but if is changing message body, try to store it as a header or property, for example: .setHeader("headerName",simple("${body}")) and after validator .setBody(simple("${header.headerName}"))

dey
  • 3,022
  • 1
  • 15
  • 25
  • I tried your solution but I get the same problem. After debugging in Camel, it turned out there might be a bug. I will update my question accordingly. – pmartin8 Aug 07 '15 at 14:43
  • 1
    So the solution is in Claus comment. If you are working on stream, they aren't re-readable, so you must use .streamCaching() (after from) or you can .convertBodyTo(String.class) after getting stream – dey Aug 09 '15 at 14:59
0

The problem that I was trying to pass a body that was a stream. (streamDownload=true). The validator will read the stream and validate the content. No problem.

But the problem comes when the split arrives, the stream was already read and closed. So the split can't do anything with the stream.

I already worked around the problem without a stream, but I guess working with streamcaching would also work if a stream is necessary.

See http://camel.apache.org/why-is-my-message-body-empty.html

pmartin8
  • 1,545
  • 1
  • 20
  • 36