camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Store un-evaluated simple expression, and evaluate on use?
Date Fri, 15 Apr 2016 11:18:19 GMT
Ah yeah use <ref> instead of <simple>

On Fri, Apr 15, 2016 at 11:31 AM,  <jimi.hullegard@svensktnaringsliv.se> wrote:
> I can't get it to work.
>
> This is my config:
>
> <bean id="testExpression" class="org.apache.camel.language.simple.SimpleLanguage"
factory-method="simple">
>         <constructor-arg value="${file:name.noext}_${date:now:yyyy-MM-dd_HH.mm.ss}"
/>
> </bean>
>
> <camelContext>
>     <route>
>       [...]
>       <setHeader headerName="testHeader">
>           <simple>ref:testExpression</simple>
>       </setHeader>
>       <log logName="test" loggingLevel="DEBUG" message="Test 1: ${in.headers['testHeader']}"
/>
>       <log logName="test" loggingLevel="DEBUG" message="Test 2: $simple{ref:testExpression}"
/>
>       [...]
>     </route>
> </camelContext>
>
>
> And this is the output:
>
> Test 1: ${file:name.noext}_${date:now:yyyy-MM-dd_HH.mm.ss}
> Test 2: ${file:name.noext}_${date:now:yyyy-MM-dd_HH.mm.ss}
>
>
> But I expected something like this as output:
>
> Test 1: myFile_2016-04-15_11.26.40
> Test 2: myFile_2016-04-15_11.26.40
>
> So, it seems like it treats the expression as a String instead of evaluating it.
>
> /Jimi
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Friday, April 15, 2016 10:39 AM
> To: users@camel.apache.org
> Subject: Re: Store un-evaluated simple expression, and evaluate on use?
>
> In Java code you can store anything in the registry,
>
> and also in xml but using <bean> style and call the static simple method on the
language
>
> <bean id="xxx" class="org.apache.camel.language.simple.SimpleLanguage">
>   <static-factory stuff here I cannot remember  but call the simple method with your
string as parameter> </bean>
>
> And then you can refer to the expression using
>
> <ref>xxx</ref>
>
> Or if using simple
>
> <simple>ref:xxx</simple>
>
>
> An alternative is to use property placeholders http://camel.apache.org/using-propertyplaceholder.html
>
> On Fri, Apr 15, 2016 at 10:22 AM,  <jimi.hullegard@svensktnaringsliv.se> wrote:
>> Hi,
>>
>> Is it possible to define a simple expression in some global variable, without evaluating
it? And then reference it, and evaluate it, later? I'm using Camel Spring XML.
>>
>> For example, something like this pseudo config:
>>
>> <variable name="testExpression"
>> value="${file:name.noext}_${date:now:yyyy-MM-dd_HH.mm.ss}"/>
>>
>> <camelContext>
>>     <route>
>>       [...]
>>       <setHeader headerName="myHeader"><simple>${testExpression}</simple></setHeader>
>>       [...]
>>     </route>
>> </camelContext>
>>
>> Can this be done with some built in standard functionality? The reason is that I
want to use the exact same expression in multiple places, and want to avoid copy pasting it.
>>
>> I use Camel 2.17.0.
>>
>> Regards
>> /Jimi
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Mime
View raw message