Apache Camel Bindy: Unexpected / unmapped characters found at the end of the fixed-length record at line : 2

781 views Asked by At

Getting following exception in Camel:

Exchange[
    Id                  ID-Dell-PC-51429-1581618665098-0-4
    ExchangePattern     InOnly
    Headers             {breadcrumbId=ID-Dell-PC-51429-1581618665098-0-3, CamelFileAbsolute=false, CamelFileAbsolutePath=C:\Users\Dell\eclipse-workspace\camelHelloWorld\input\TIL.txt, CamelFileContentType=text/plain, CamelFileLastModified=1581618006722, CamelFileLength=12050, CamelFileName=TIL.txt, CamelFileNameConsumed=TIL.txt, CamelFileNameOnly=TIL.txt, CamelFileParent=input, CamelFilePath=input\TIL.txt, CamelFileRelativePath=TIL.txt, CamelRedelivered=false, CamelRedeliveryCounter=0}
    BodyType            org.apache.camel.component.file.GenericFile
    Body                [Body is file based: GenericFile[TIL.txt]]
]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.IllegalArgumentException: Unexpected / unmapped characters found at the end of the fixed-length record at line : 2
    at org.apache.camel.dataformat.bindy.BindyFixedLengthFactory.bind(BindyFixedLengthFactory.java:281)
    at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.createModel(BindyFixedLengthDataFormat.java:262)
    at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.unmarshal(BindyFixedLengthDataFormat.java:196)
    at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:67)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:433)
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Trying to convert fixed file format using following:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
 "id",
 "name",
  .
  .
})
@XmlRootElement(name = "Til")
@FixedLengthRecord(length = 239)
public class Til {

 @XmlElement(name = "ID", required = true)
 @DataField(pos = 1, length = 4)
 protected String id;

 @XmlElement(name = "NAME", required = true)
 @DataField(pos = 5, length = 15)
 protected String name;
 .
 .
}

Total Characters are 239 in File.

What could be reason of this error? Any kind of trim or padding required to fix this?

1

There are 1 answers

0
Camel Dev On BEST ANSWER

This can be overcome by applying the following code on your POJO class. This is basically telling Bindy to ignore characters that comes after the last mapped fixed length data as per POJO.

@FixedLengthRecord(ignoreTrailingChars = true)

You can perhaps open your file in notepad++ after enabling View -> Show Symbol ->Show All Characters and see if any characters are actually present at the end. These characters are commonly noticed when dealing with files generated from a different OS. You can also doublecheck the mapping to ensure that all the fields are actually mapped as per the correct length, which can go easily unnoticed.