artaxerxe
artaxerxe

Reputation: 6421

Store java.util.Date in header as java.util.Date with Camel

I need to store current date in a header, so that later on I can use it for different purposes in route. In one place I would need it as 'yyyyMMdd', in another as 'yyMMdd', in another as 'HHmmss' in another as 'HHmmssSSS', etc...

The problem is that if I store it in a header, it is converted to something else.

N.B. I'm using apache-camel with Spring XML DSL.

If I do this:

<setHeader headerName="current.timestamp">
    <groovy resultType="java.util.Date">new Date()</groovy>
</setHeader>
...
<setHeader headerName="CamelFileName">
    <simple>file${date:header.current.timestamp:yyyyMMdd}T${date:header.current.timestamp:HHmmss}</simple>
</setHeader>

I get an error saying:

java.lang.IllegalArgumentException: Cannot find java.util.Date object at command: header.current.timestamp

Has anyone any solution for this?

Upvotes: 1

Views: 829

Answers (1)

artaxerxe
artaxerxe

Reputation: 6421

The problem was related to dot from header name. I removed it and now it's working.

Upvotes: 2

Related Questions