Java 如何使用 spring DSL 在骆驼中记录标头值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18877562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I log a header value in camel using spring DSL
提问by Steve Harrington
This seems like it should be simple, pardon the pun. I'm trying to log a header in camel within a spring DSL route. I've seen the answer for Java DSLbut I've been searching in vain for how to make it work in spring DSL. I've tried:
这看起来应该很简单,请原谅双关语。我正在尝试在 spring DSL 路由中记录骆驼的标头。我已经看到了Java DSL的答案,但是我一直在寻找如何让它在 spring DSL 中工作的徒劳无功。我试过了:
<log message="ftping $simple{header.CamelFileName}"/>
and also:
并且:
<log message="ftping ${header.CamelFileName}"/>
and several other permutations/variations, but all of them simply log that text verbatim (i.e. they do not substitute the actual header name).
以及其他几种排列/变体,但它们都只是逐字记录该文本(即它们不替换实际的标题名称)。
What am I missing?
我错过了什么?
update:here's a larger portion of my xml file:
更新:这是我的 xml 文件的较大部分:
<split>
<simple>${body}</simple>
<setHeader headerName="CamelFileName">
<simple>${body.batchNumber}.xml</simple>
</setHeader>
<log message="SLH - 5 -- marshalling an EFileBatch to XML" loggingLevel="DEBUG" />
<marshal>
<jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation"
partClass="generated.gov.nmcourts.ecitation.NMCitationEFileBatch"
partNamespace="EFileBatch" />
</marshal>
<log message="SLH - 6 -- xslt transform to add schema location" loggingLevel="DEBUG" />
<to uri="{{addSchemaLocationXsltUri}}"/>
<log message="SLH - 7 -- ftp now initiating" loggingLevel="DEBUG" />
<log message="ftping ${headers.CamelFileName}"/>
<to uri="{{ftpOdysseyInputPath}}"/>
<log message="SLH - 8 -- ftp now complete" loggingLevel="DEBUG" />
</split>
采纳答案by Steve Harrington
Asked this question some time back, and realized that I eventually found the answer so should post it here in case someone else finds this thread in a search. This works:
一段时间前问了这个问题,并意识到我最终找到了答案,所以应该将其发布在这里,以防其他人在搜索中找到该线程。这有效:
<log message="ftping $simple{in.header.CamelFileName}" loggingLevel="DEBUG"/>
回答by Frederic Close
Not sure it's possible
不确定有没有可能
http://camel.apache.org/logeip.html
http://camel.apache.org/logeip.html
Difference between log in the DSL and Log component The log DSL is much lighter and meant for logging human logs such as Starting to do ... etc. It can only log a message based on the Simple language.
DSL 中的 log 和 Log 组件之间的区别 log DSL 更轻巧,用于记录人类日志,例如开始做...等。它只能记录基于 Simple 语言的消息。
On the other hand Log component is a full fledged component which involves using endpoints and etc. The Log component is meant for logging the Message itself and you have many URI options to control what you would like to be logged.
另一方面,日志组件是一个完整的组件,涉及使用端点等。日志组件用于记录消息本身,您有许多 URI 选项来控制您想要记录的内容。
回答by Jakub Korab
Try the following, either will work:
尝试以下操作,两者都可以:
<log message="ftping ${header[CamelFileName]}"/>
<log message="ftping ${headers.CamelFileName}"/>
The $simple{...}
syntax was added in Camel 2.5 to avoid clashes with Spring ${...}
- it might be that you're using an older version?
在$simple{...}
骆驼2.5加入的语法来避免使用Spring的冲突${...}
-它可能是你使用的是旧版本?
回答by javalearner_heaven
In JAVA DSL
在 JAVA DSL 中
from("logger")
.log(LoggingLevel.INFO, "${in.headers.CamelFileName}")
.end
LoggingLevel is from org.apache.camel.LoggingLevel
LoggingLevel 来自 org.apache.camel.LoggingLevel