1

I have a flat file, in which each line needs to be captured and unmarshalled into a POJO. I am using Camel and Bindy and utilizing the Splitter EIP. For some reason i am not able to inspect the POJO (using a Processor) after the unmarshalling completed. Any suggestions?

I am trying to debug the Exchange inside the Process right after both Bindy conversions below. The code never gets invoked (breakpoint never reaches)

Here is my code:

from("file://inbox")
    .setHeader(Exchange.FILE_NAME,simple("${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}")) 
    .wireTap("file://ORIGINAL_BACKUP")
    .process(converterProcessor)
    .split(body(String.class).tokenize(System.lineSeparator()))
    .choice()       
    .when(new Predicate() {

        public boolean matches(Exchange exchange) {
            if(exchange.getIn().getBody().toString().startsWith("HEADER1")) return true;
            return false;
        }
    })      
    .unmarshal()
    .bindy(BindyType.Fixed, MessageHeaderGroup_HEADER1.class).process(new Processor() {

        public void process(Exchange exchange) throws Exception {
            System.out.println("Object: "+ exchange.getIn().getBody());

        }
    }).to("direct:mhg")

    .when(new Predicate() {

        public boolean matches(Exchange exchange) {
            if(exchange.getIn().getBody().toString().startsWith("HEADER2")) return true;
            return false;
        }
    })
    .unmarshal()
    .bindy(BindyType.Fixed, TransactionHeaderGroup_HEADER2.class).process(new Processor() {

        public void process(Exchange exchange) throws Exception {
            System.out.println("Object: "+ exchange.getIn().getBody());

        }
    }).to("direct:trg")
    .otherwise().to("file://outbox");

I am fairly new to Camel. I have tried to end the choice() using endChoice() but to no avail. If i use a Filter EIP (to only use one possible Bindy conversion) i can inspect the Exchange in the Process step. But if i switch to a choice() with Predicate i am not able to. Thanks for your suggestions!

Mechkov
  • 4,294
  • 1
  • 17
  • 25

1 Answers1

0

Why do you use wireTap? This could be your Problem. See the documentation --> wire-tap.

If you Wire Tap a stream message body then you should consider enabling Stream caching to ensure the message body can be read at each endpoint. See more details at Stream caching.

Please set a BreakPoint in your converterProcessor and look inside the exchange.

If you only want to move the file you can make a simple .to("file://ORIGINAL_BACKUP") and then go on. Another way:

from("file://inbox?move=ORIGINAL_BACKUP/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}")
  • I use Wire Tap to save a copy of my original flat file. It is not a necessity on my part to have it. I have tested without it as well. I came to find out that the problem was an exception being thrown while Bindy was unmarshalling the file to a POJO. Since i am fairly new to Camel, i was confused by the fact that i did not see the exception on my console in Eclipse. Do you know of a good way to show errors/exception in your route as it is being traversed? I am yet to research the Exception Handling facilities in Camel, but need some debugging tips before i get there. Thanks! – Mechkov Jul 28 '15 at 12:48
  • Ok, to answer my question above to those interested - here is a similar question i stumbled upon that should get me started on a verbose exception handling during route traversal in Camel - http://stackoverflow.com/questions/26487115/apache-camel-bindy-how-to-log-or-debug?rq=1 – Mechkov Jul 28 '15 at 12:51