[英]Camel bean parameter binding not working
I'm learning Apache Camel framework, trying to implement simple bean parameter binding example.我正在学习 Apache Camel 框架,试图实现简单的 bean 参数绑定示例。
I have the following route我有以下路线
from("timer://foo?delay=2000")
.setBody(simple("hello"))
.log("${body}")
.transform(simple("<foo>${body}</foo>"))
.log("${body}")
.bean(DocumentProcessorBean.class, "process");
And the following Spring bean而下面的Spring bean
@Component("documentProcessorBean")
public static class DocumentProcessorBean {
public Document process(@Body Document doc, @Headers Map<String, Object> headers) {
System.out.println(doc);
System.out.println(headers);
return doc;
}
}
However, the parameter binding doesn't seem to work, as I'm getting Document instance without content, as is shown in the log但是,参数绑定似乎不起作用,因为我正在获取没有内容的 Document 实例,如日志中所示
2018-04-03 18:14:39.354 INFO 7740 --- [1 - timer://foo] route1 : hello
2018-04-03 18:14:39.354 INFO 7740 --- [1 - timer://foo] route1 : <foo>hello</foo>
[#document: null]
{breadcrumbId=ID-DESKTOP-LI5P50P-1522768469501-0-6, firedTime=Tue Apr 03 18:14:39 EEST 2018}
I'm also confused about the "implicit" data formats camel uses.我也对骆驼使用的“隐式”数据格式感到困惑。 For example, does transformation using
simple
always return a string?例如,使用
simple
转换是否总是返回一个字符串? What is the difference of using string, marshalled format (eg xstream) or binding class format (POJO) in the route, or does it even matter?在路由中使用字符串、编组格式(例如 xstream)或绑定类格式(POJO)有什么区别,或者甚至重要吗? Generally, what are the scenarios when I need to transform between these formats in the route?
一般来说,我需要在路由中在这些格式之间进行转换时有哪些场景? And most importantly, why the bean parameter binding in this particular route doesn't work?
最重要的是,为什么这个特定路由中的 bean 参数绑定不起作用?
You cannot just System.out.println
a Document
instance and have it show the XML content. 您不能仅
System.out.println
一个Document
实例并使它显示XML内容。 What you see in the log is expected, it may just show Document: null
or something, but that does not mean there is no content. 您期望在日志中看到的内容可能只是显示
Document: null
或其他内容,但这并不意味着没有任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.