简体   繁体   English

Apache Camel Bindy:在第 2 行的固定长度记录末尾发现意外/未映射的字符

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

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.文件中的字符总数为 239。

What could be reason of this error?这个错误的原因是什么? Any kind of trim or padding required to fix this?解决这个问题需要任何类型的修剪或填充吗?

This can be overcome by applying the following code on your POJO class.这可以通过在 POJO 类上应用以下代码来克服。 This is basically telling Bindy to ignore characters that comes after the last mapped fixed length data as per POJO.这基本上是告诉 Bindy 根据 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.您还可以仔细检查映射以确保所有字段实际上都按照正确的长度进行映射,这很容易被忽视。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM