String Template抛出空指针异常

时间:2013-12-30 06:32:35

标签: java apache-camel stringtemplate

使用Camel String Template端点,我试图按如下方式循环嵌套集合

端点:

<to uri="string-template:classpath:META-INF/spring/dataformat/stringTemplate/coparn-ack-txt.tm"/>

模板:

  $body: {coparnHeader|
    <label class="smallfield">$coparnHeader.vesselName$</label>
      $coparnHeader.coparnAckDetails: {detail|
         <label class="smallfield">$detail.remarks$</label>
         .....
      }$
      $coparnHeader.errorList: {error|
         <label class="smallfield">***$error$</label> 
         ......
      }$
   }$       

解析模板,并根据需要生成值。但问题是骆驼路线引发了以下异常。

action parse error; template context is [anonymous anonymous anonymous]
line 1:23: unexpected token: null
    at org.antlr.stringtemplate.language.ActionParser.primaryExpr(ActionParser.java:794)
    at org.antlr.stringtemplate.language.ActionParser.expr(ActionParser.java:539)
    at org.antlr.stringtemplate.language.ActionParser.templatesExpr(ActionParser.java:222)
    at org.antlr.stringtemplate.language.ActionParser.action(ActionParser.java:126)
    at org.antlr.stringtemplate.StringTemplate.parseAction(StringTemplate.java:876)
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:162)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.language.ActionParser.anonymousTemplate(ActionParser.java:639)
    at org.antlr.stringtemplate.language.ActionParser.template(ActionParser.java:590)
    at org.antlr.stringtemplate.language.ActionParser.templatesExpr(ActionParser.java:235)
    at org.antlr.stringtemplate.language.ActionParser.action(ActionParser.java:126)
    at org.antlr.stringtemplate.StringTemplate.parseAction(StringTemplate.java:876)
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:162)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.language.ActionParser.anonymousTemplate(ActionParser.java:639)
    at org.antlr.stringtemplate.language.ActionParser.template(ActionParser.java:590)
    at org.antlr.stringtemplate.language.ActionParser.templatesExpr(ActionParser.java:235)
    at org.antlr.stringtemplate.language.ActionParser.action(ActionParser.java:126)
    at org.antlr.stringtemplate.StringTemplate.parseAction(StringTemplate.java:876)
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:162)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.StringTemplate.<init>(StringTemplate.java:308)
    at org.antlr.stringtemplate.StringTemplate.<init>(StringTemplate.java:293)
    at org.apache.camel.component.stringtemplate.StringTemplateEndpoint.onExchange(StringTemplateEndpoint.java:60)
    at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:81)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
    at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
    at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
problem parsing template 'anonymous'
java.lang.NullPointerException
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:163)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.language.ActionParser.anonymousTemplate(ActionParser.java:639)
    at org.antlr.stringtemplate.language.ActionParser.template(ActionParser.java:590)
    at org.antlr.stringtemplate.language.ActionParser.templatesExpr(ActionParser.java:235)
    at org.antlr.stringtemplate.language.ActionParser.action(ActionParser.java:126)
    at org.antlr.stringtemplate.StringTemplate.parseAction(StringTemplate.java:876)
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:162)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.language.ActionParser.anonymousTemplate(ActionParser.java:639)
    at org.antlr.stringtemplate.language.ActionParser.template(ActionParser.java:590)
    at org.antlr.stringtemplate.language.ActionParser.templatesExpr(ActionParser.java:235)
    at org.antlr.stringtemplate.language.ActionParser.action(ActionParser.java:126)
    at org.antlr.stringtemplate.StringTemplate.parseAction(StringTemplate.java:876)
    at org.antlr.stringtemplate.language.TemplateParser.action(TemplateParser.java:162)
    at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:127)
    at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
    at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
    at org.antlr.stringtemplate.StringTemplate.<init>(StringTemplate.java:308)
    at org.antlr.stringtemplate.StringTemplate.<init>(StringTemplate.java:293)
    at org.apache.camel.component.stringtemplate.StringTemplateEndpoint.onExchange(StringTemplateEndpoint.java:60)
    at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:81)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
    at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
    at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

Maven依赖:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-stringtemplate</artifactId>
        <version>2.10.4</version>
    </dependency>

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。

问题是由于使用了点运算符。

在我使用的一个地方导致了这个问题。

 <label class="smallfield">$detail.remarks.$</label>