没有类型的正文:com.mongodb.DBObject

时间:2018-03-19 09:56:42

标签: java spring mongodb apache-camel

我有读取文件的camel路由,必须在mongoDB中插入文件的内容。我已成功读取该文件但无法将其内容插入到mongoDB中。抛出异常org.apache.camel.InvalidPayloadException: No body available of type: com.mongodb.DBObject请看一下。

控制台日志

  

消息历史记录   -------------------------------------------------- -------------------------------------------------- ----------------------------------- RouteId ProcessorId Processor
  经过(ms)[route1] [route1]   [文件:// C:// //工作区// EmailResponseAutomation响应//   ] [2] [route1] [convertBodyTo1]   [convertBodyTo [com.mongodb.DBObject]
  ] [2]

     

堆栈跟踪

     

org.apache.camel.InvalidPayloadException:没有类型的正文:   com.mongodb.DBObject但有价值:   GenericFile [C:\工作空间\ EmailResponseAutomation \响应\ SampleEmailResponseFile.txt]   类型:org.apache.camel.component.file.GenericFile on:   SampleEmailResponseFile.txt。引起:没有可用的类型转换器   从类型:org.apache.camel.component.file.GenericFile转换为   必需类型:带有值的com.mongodb.DBObject   GenericFile [C:\工作空间\ EmailResponseAutomation \响应\ SampleEmailResponseFile.txt]。   交换[ID-XAV-101001260-52594-1521452849077-0-12]。引起:   [org.apache.camel.NoTypeConversionAvailableException - 没有类型   转换器可用于转换类型:   org.apache.camel.component.file.GenericFile为所需类型:   带有值的com.mongodb.DBObject   GenericFile [C:\工作空间\ EmailResponseAutomation \响应\ SampleEmailResponseFile.txt]]     在   org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:107)   〜[camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.ConvertBodyProcessor.process(ConvertBodyProcessor.java:91)   〜[camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)   〜[camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)   〜[camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.Pipeline.process(Pipeline.java:121)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.Pipeline.process(Pipeline.java:83)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)   [camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)   [camel-core-2.17.0.jar:2.17.0] at   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)   [na:1.8.0_102] at   java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)   [na:1.8.0_102] at   java.util.concurrent.ScheduledThreadPoolExecutor中的$ ScheduledFutureTask.access $ 301(ScheduledThreadPoolExecutor.java:180)   [na:1.8.0_102] at   java.util.concurrent.ScheduledThreadPoolExecutor中的$ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)   [na:1.8.0_102] at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)   [na:1.8.0_102] at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)   [na:1.8.0_102]在java.lang.Thread.run(Thread.java:745)   [na:1.8.0_102]引起:   org.apache.camel.NoTypeConversionAvailableException:没有类型转换器   可以转换类型:   org.apache.camel.component.file.GenericFile为所需类型:   带有值的com.mongodb.DBObject   GenericFile [C:\工作空间\ EmailResponseAutomation \响应\ SampleEmailResponseFile.txt]     在   org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:198)   〜[camel-core-2.17.0.jar:2.17.0] at   org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:105)   〜[camel-core-2.17.0.jar:2.17.0] ...省略了19个常用帧

骆驼路线

@Override
    public void configure() throws Exception {

        from("file://workspace//EmailResponseAutomation//response//")
                .convertBodyTo(com.mongodb.DBObject.class)
                .to("mongodb:myDb?database=email_response&collection=emailResponse&operation=save");
    }

    @Bean
    public Mongo myDb() {
        return new MongoClient(new ServerAddress("127.0.0.1", 27017));
    }

0 个答案:

没有答案