Apache的骆驼:访问CamelLoopIndex

问题描述:

我有以下路线DSL:Apache的骆驼:访问CamelLoopIndex

from("file:" + autoLoadBaseDir + "?move=.classified") 
       .loop(fileTypes.length) 
        .choice() 
         .when(header("CamelFileName").contains(fileTypes[Integer.valueOf("${CamelLoopIndex}")])) 
          .to("file:" + classesBaseDir + "/" + fileTypes[Integer.valueOf("${CamelLoopIndex}")]); 

如图所示,我希望访问CamelLoopIndex并使用它作为在阵列中的索引。表达式不计算,因此路由不会被创建。我究竟做错了什么?提前致谢。

这方面的文档很少,而且我还没有成功地在搜索几个小时后获得解决方案。

UPDATE:我已经发布了同样的问题到骆驼用户邮件列表。

我迟到了,但也许有人会从这个答案得到帮助。在上面给出的例子中,这适用于我访问Java DSL中的循环索引。

property(Exchange.LOOP_INDEX) 

所以对于来自于奥凯洛后的第一个上面的例子我想这会工作

Integer.valueOf(property(Exchange.LOOP_INDEX).toString()) 

您应该使用$ {} property.CamelLoopIndex

+0

我用这个,但不知何故表达不能得到解决。 – okello 2013-04-11 16:27:05

+0

假设您可以在“简单”表达式中使用$ {property.CamelLoopIndex}。如果你不使用简单的try属性(“CamelLoopIndex”) – katrin 2013-04-12 12:49:26

+0

我只是使用了一个额外的处理器,我可以通过调用exchange.getProperty(“CamelLoopIndex”)来提取循环索引,并使用索引来获取实际值我想,将其设置在标题中,并在随后的路线组件中访问它。看到下面的答案(我在这里发布我的解决方案)。 – okello 2013-04-12 12:57:14

已经尝试与周围的一些选项,我下面的作品:

from("file:" + autoLoadBaseDir + "?preMove=inprogress&move=.classified") 
       .routeId("Test-Route") 
       .loop(fileTypes.length) 
       .processRef("keFileTypeNameService") 
        .choice() 
         .when(header("CamelFileName").contains(header("MyFileType"))) 
          .to("file:" + classesBaseDir + "/?autoCreate=true&fileName=${header[MyFileType]}/${header[CamelFileName]}"); 

keFileTypeNameService检索来自交换CamelLoopIndex财产。然后它使用它来获取该索引处的文件类型。然后只需在标题中设置该文件类型名称即可。该keFileTypeNameService豆如下:

@Service(value = "keFileTypeNameService") 
public class FileTypeNameService implements Processor { 

    private @Value("${ke.file.types}") String[] fileTypes; 

    public void process(Exchange exchange) throws Exception { 
     Integer count = exchange.getProperty("CamelLoopIndex", Integer.class); 
     String fileType = fileTypes[count]; 
     exchange.getIn().setHeader("MyFileType", fileType); 
    } 




} 

我希望这有助于别人。