apache-camelfixed-length-recordbindy

Possible to initialize a bindy (Apache Camel DataFormat - FixedLength and use it in the same route


My input file consists of several type of FixedLengthRecord, so I have lots of FixedLengthDataFormat to unmarshal each post.

  1. I split the body per row
  2. for the first I should realize which DataFormat I should use, and create an object
  3. Then unmarshal

Something like this one:

from(myURI)
    .split().tokenize("\n")
        .process(initializeMyBindyDataFormat)
        .unmarshal(bindy)
    .end();

But my problem is, I get NPE for that bindy object when I initilize it via a process. But if I create a bindy object before my route definition (before from) it will be work fine. My bindy object is depended on body and I cannot initialize it before route definition. Actually Apache Camel process initialization of bindy object before starting the route


Solution

  • The answer is using .inout Since I want to have unmarshalling in another route, a simple example should be as below:

    from(myURI)
        .split().tokenize("\n")
            .inout("direct:unmarshalSpecificRow")
        .end();
    
    from(direct:unmarshalSpecificRow")
        .choice()
            .when(firstPredicate)
               unmarshal(new BindyFixedLengthDataFormat(package1)
            .when(secondPredicate)
               unmarshal(new BindyFixedLengthDataFormat(package1)
            .when(thirdPredicate)
               unmarshal(new BindyFixedLengthDataFormat(package1)
            .otherwise()
               .throwException(new IllegalArgumentException("Unrecognised post")
        .end();
    

    Thanks jakub-korab for his help.