How can I log a header value in camel using spring DSL

拟墨画扇 提交于 2020-01-01 04:27:28

问题


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 DSL but I've been searching in vain for how to make it work in spring DSL. I've tried:

 <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:

<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>

回答1:


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"/>



回答2:


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?




回答3:


In JAVA DSL

from("logger")
.log(LoggingLevel.INFO, "${in.headers.CamelFileName}")
.end

LoggingLevel is from org.apache.camel.LoggingLevel




回答4:


Not sure it's possible

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.

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.



来源:https://stackoverflow.com/questions/18877562/how-can-i-log-a-header-value-in-camel-using-spring-dsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!