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:35:48 GMT
On Fri, Apr 15, 2016 at 1:29 PM,  <jimi.hullegard@svensktnaringsliv.se> wrote:
> OK, thanks. Now the test with the header works. But I still can't get the "inline" expression
to work, in the <log> tag. How should I write there? I have tried:
>
> <log logName="test" loggingLevel="DEBUG" message="Test 2: $simple{ref:testExpression}"
/>
> <log logName="test" loggingLevel="DEBUG" message="Test 3: $ref{testExpression}" />
>
> But this just prints:
>
> Test 2: ${file:name.noext}_${date:now:yyyy-MM-dd_HH.mm.ss}
> Test 3: $ref{testExpression}
>
>
> So, to summarize. I can get Camel to eval the Expression bean when using <ref>testExpression</ref>
in a setHeader. But I can't get Camel to eval it as part of another simple expression, like
the log example above. Shouldn't this be possible too?
>

No that is not possible a simple ref just refers to a bean in the
registry, its not for evaluating an expression.


> /Jimi
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Friday, April 15, 2016 1:18 PM
> To: users@camel.apache.org
> Subject: Re: Store un-evaluated simple expression, and evaluate on use?
>
> 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



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

Mime
View raw message