将csv转换为POJO的Camel错误

时间:2013-10-30 16:23:06

标签: java apache-camel

我正在尝试使用bindy将csv文件转换为pojo,但收到错误 Pojo课程:

@CsvRecord(separator = ",")
public class PurchaseOrder {

    @DataField(pos = 1)
    private String name;

    @DataField(pos = 2)
    private BigDecimal price;

    @DataField(pos = 3)
    private int amount;

    //getters, setters
}

主要课程

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("file://data/inbox?noop=true")
                    .unmarshal()
                    .bindy(BindyType.Csv, PurchaseOrder.class)
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            PurchaseOrder object = (PurchaseOrder) exchange.getIn().getBody();
                            System.out.println(object);
                        }
                    });
context.start();
Thread.sleep(3000);
context.stop();

data.csv中的文件inbox包含数据:

Camel in Action,39.95,"1"

这是我得到的错误:

Failed delivery for (...). Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
Message History
    ---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId              Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://data/inbox?noop=true                                                   ] [        23]
[route1            ] [unmarshal1        ] [unmarshal[org.apache.camel.model.dataformat.BindyDataFormat@13ca15af]         ] [        11]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id                  ID-krichevsky-57174-1383149655498-0-2
ExchangePattern     InOnly
Headers             {breadcrumbId=ID-krichevsky-57174-1383149655498-0-1, CamelFileAbsolute=false, CamelFileAbsolutePath=C:\Users\krichevsky\IdeaProjects\Camel-xml-json\data\inbox\data.csv, CamelFileLastModified=1383147160076, CamelFileLength=25, CamelFileName=data.csv, CamelFileNameConsumed=data.csv, CamelFileNameOnly=data.csv, CamelFileParent=data\inbox, CamelFilePath=data\inbox\data.csv, CamelFileRelativePath=data.csv, CamelRedelivered=false, CamelRedeliveryCounter=0}
BodyType            org.apache.camel.component.file.GenericFile
Body                [Body is file based: GenericFile[data.csv]]
]

堆栈跟踪

java.lang.NullPointerException
at org.apache.camel.dataformat.bindy.BindyAbstractFactory.initModel(BindyAbstractFactory.java:112)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.dataformat.bindy.BindyAbstractFactory.<init>(BindyAbstractFactory.java:72)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.dataformat.bindy.BindyCsvFactory.<init>(BindyCsvFactory.java:79)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.createModelFactory(BindyCsvDataFormat.java:271)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.dataformat.bindy.BindyAbstractDataFormat.getFactory(BindyAbstractDataFormat.java:69)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:108)[camel-bindy-2.12.1.jar:2.12.1]
at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:65)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:401)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:201)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:165)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)[camel-core-2.12.1.jar:2.12.1]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)[camel-core-2.12.1.jar:2.12.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_25]
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)[:1.7.0_25]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)[:1.7.0_25]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)[:1.7.0_25]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_25]
at java.lang.Thread.run(Thread.java:724)[:1.7.0_25]
Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@4f2fb603 for file: GenericFile[data.csv]

0 个答案:

没有答案