14

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>
Max
  • 915
  • 10
  • 28
Steve Harrington
  • 942
  • 1
  • 7
  • 18
  • What Camel version do you use? – Claus Ibsen Sep 19 '13 at 06:07
  • Using camel 2.11.1 -- I suspect this is something to do w/ the fact that I'm using camel & spring properties (both)? My spring props I can reference using syntax such as: #{springprops['tylerAgency']} and my camel props I can reference using syntax such as: {{ftpOdysseyInputPath}}. Perhaps the use of spring props makes this an issue, I've read through the various camel / spring properties docs, but maybe I'm missing something. – Steve Harrington Sep 19 '13 at 16:15

5 Answers5

18

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"/>
Steve Harrington
  • 942
  • 1
  • 7
  • 18
9

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?

Jakub Korab
  • 4,974
  • 2
  • 24
  • 34
  • Thanks for suggestions, but neither of those work for me; using camel version 2.11.1. Updating my original question to show a larger snippet of my spring DSL xml file. – Steve Harrington Sep 19 '13 at 15:34
  • Camel 2.17, `" ... ${header.CamelFileName}"` works for me. – fg78nc Sep 20 '18 at 18:56
7

In JAVA DSL

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

LoggingLevel is from org.apache.camel.LoggingLevel

javalearner_heaven
  • 483
  • 1
  • 6
  • 21
1

One way that I could acomplish that (using Java DSL) was:

from("logger")
.log("${exchange.getIn().getHeader(\"<HEADER>\").toString()}")
.end

Where "<HEADER>" should be replaced by any header key that you want like "Authorization":

from("logger")
.log("${exchange.getIn().getHeader(\"Authorization\").toString()}")
.end
Lukasavicus
  • 137
  • 8
0

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.

Frederic Close
  • 9,389
  • 6
  • 56
  • 67