Apache camel Apache Camel 2.18中使用简单表达式进行索引
以下示例代码适用于除2.18.x之外的所有版本的CamelApache camel Apache Camel 2.18中使用简单表达式进行索引,apache-camel,Apache Camel,以下示例代码适用于除2.18.x之外的所有版本的Camel from("direct:process") .process(new Processor() { public void process(Exchange exchange) { List<String> alist = new ArrayList<String>(); alist.add("1");
from("direct:process")
.process(new Processor() {
public void process(Exchange exchange) {
List<String> alist = new ArrayList<String>();
alist.add("1");
alist.add("99");
exchange.getIn().setHeader("ITEMS", alist);
exchange.getIn().setHeader("TOTAL_LOOPS", alist.size());
}
})
.loop(simple("${header.TOTAL_LOOPS}", Integer.class))
.setHeader("item", simple("${header.ITEMS[${property.CamelLoopIndex}]}", String.class))
.log(LoggingLevel.INFO, LOG_CLASS_NAME, simple("item = ${header.item} and TOTAL_MAPS = ${header.TOTAL_LOOPS}").getText())
.end()
.end();
from(“直接:过程”)
.进程(新处理器(){
公共作废流程(交换){
列表列表=新的ArrayList();
添加(“1”);
添加(“99”);
exchange.getIn().setHeader(“ITEMS”,alist);
setHeader(“TOTAL_循环”,alist.size());
}
})
.loop(简单(${header.TOTAL_LOOPS}),Integer.class))
.setHeader(“item”,简单(${header.ITEMS[${property.CamelLoopIndex}]}),String.class))
.log(LoggingLevel.INFO,log_CLASS_NAME,simple(“item=${header.item}和TOTAL_MAPS=${header.TOTAL_LOOPS}”).getText()
(完)
.end();
但是,对于2.18.x,会引发以下异常:
2017-02-03 21:13:31错误DefaultErrorHandler:204-交付失败
对于(消息ID:ID-CATL0W10D4DG4R1-55822-1486174410756-0-1,打开
交换ID:ID-CATL0W10D4DG4R1-55822-1486174410756-0-2)。筋疲力尽的
交付尝试后:1次捕获:
org.apache.camel.language.bean.RuntimeBeanExpressionException:失败
调用java.util.ArrayList上的方法:[${property.CamelLoopIndex}]
原因:java.lang.IndexOutOfBoundsException:键:
在类型为的bean:[1,99]中找不到${property.CamelLoopIndex}
使用OGNL路径[[${property.CamelLoopIndex}]的java.util.ArrayList
您使用的是什么版本的Camel?目前我们使用的是Camel 2.17.4(JDK1.7),这个表达式工作正常。我们希望迁移到2.18.2或更高版本(JDK1.8),并发现此表达式抛出IndexOutofBoundsCeption您可以记录JIRA票证打开:从2.17.1迁移到2.24.3@ClausIbsen后,我遇到了相同的问题