Apache camel getbody作为自定义类 [英] Apache camel getbody as custom class

查看:537
本文介绍了Apache camel getbody作为自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,也许是因为我在这个过程中有点困惑。
我要做的是在代码示例中显示:

The question is rather simple, perhaps because I'm a little confused in the process. What I'm trying to do is shown in the code example:

cc.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://files?noop=true")
                    .split()
                    .tokenize("\n")
                    .split()
                    .method(SplitToken.class, "hashTokens")

和:

class SplitToken {
@SuppressWarnings("unchecked")
public static List<HashMap<String, Integer>> hashTokens(final Exchange exchange) {
    List<String> oldstr = exchange.getIn().getBody(List<String>);
    //Create a key value hashmap from accumulated string list
    }
}

但返回错误:

expression required.

关于如何实现getbody w的任何想法一般的理想课程? (由于第一个split方法返回一个字符串列表,但我无法在第二次拆分中检索它,或者我可以吗?)

Any ideas about how we can achieve getbody with desired class in general? (Since the first split method returns a string list but I can't retrieve it in second split, or can I?)

推荐答案

据我记得,你无法通过 getBody 获得通用列表。这可能有效:

As far as I remember you cannot get generic list with getBody. This might work:

List<String> oldstr = (List<String>)exchange.getIn().getBody(List.class);

甚至更好的你可以用 @Body <为你制作骆驼提取物的身体/ code>注释:

or even better you can make camel extract body for you with @Body annotation:

public static List<HashMap<String, Integer>> hashTokens(final Exchange exchange, @Body List<String> oldStr) {
    //Create a key value hashmap from accumulated string list
    return new ArrayList<>();
}

这篇关于Apache camel getbody作为自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆