0

I want to read file(s) from a location, extract the fileName & make a rest call (GET) with the fileName as a request parameter. The file name is required to be passed dynamically as each file will be unique. I used toD() after going through the tutorials. The high level pseudo code is provided below (I am just interested with the status code from this call. There's further operations required after this.).

The issue I am facing now using toD() is that it is running into an infinite loop after making the Get service call.

How can this issue be handled? Appreciate your suggestions!

from("file:C:/inbound?delete=true&noop=true")
    .process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            String fileName = exchange.getIn().getHeader("CamelFileName").toString();
            exchange.getIn().setHeader("fileName", fileName);
        }
    })
    .setHeader(Exchange.HTTP_METHOD, simple("GET"))
    .toD("http://localhost:8090/fileWatcher?fileName=${header.fileName}")

Here's a simple Get endpoint mockup running on port 8090:

@RequestMapping(value = "/fileWatcher", method = RequestMethod.GET)
public ResponseEntity<FileDetails> firstService(@RequestParam String fileName) {
    return new ResponseEntity<>(HttpStatus.OK);
}
hk6279
  • 1,881
  • 2
  • 22
  • 32
Arjun
  • 21
  • 3
  • Can you better explain that infinite loop problem? Is the file consumed over and over again and therefore the same service call is done over and over again? – burki Dec 09 '20 at 06:18
  • By the way, the file consumer options `delete` and `noop` are contradictory. `delete=true` deletes the file after successful processing. `noop=true` does nothing with the file, but is idempotent (ignores all files that were successfully processed). – burki Dec 09 '20 at 06:56
  • @burki - The detailed use case is posted in this thread which is resolved now. https://stackoverflow.com/questions/65154708/apache-camel-how-to-pass-values-from-configure-method-to-from-to-componen/65254588#65254588 The issue initially I was facing was when i was making back to back rest calls after reading a file where after the the 1st call - it was getting into an infinite loop. I was under the impression that using toD() is causing it. Later, I refactored the apporach & realized it's nothing to do with toD() rather the implementation. I have uploaded the working code (link above). – Arjun Dec 11 '20 at 15:59
  • @burki - I have to move the file after reading it - so made use of delete=true. If i didn't specify noop=true, the file was moving in the output directory but inside inside a folder called '.camel' which was not giving me the absolute path of the file required for my next operation. Is there a better way to manage this? – Arjun Dec 11 '20 at 16:05
  • Yes, the `move` option moves processed files to the configured location. If you use `move` you should no more need `delete` and `noop`. – burki Dec 14 '20 at 06:58

0 Answers0