Quantcast

using values from a properties-file in setHeader-method

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

using values from a properties-file in setHeader-method

Christoph Burmeister
hi,

how can I set a header with a value from a properties-file using
spring-xml?
Doing this with the const-tag is no problem, but then the value has to be
directly written in the camel.xml:

<setHeader>
   <const>foobar</const>
</setHeader>

I like to use something like this:

environment.properties:
-----------------------------
header.value=foobar

camel.xml
---------------
<beans>
   <bean id="placeholderConfig"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>environment.properties</value>
                <value>another-file.properties</value>
            </list>
        </property>
    </bean>


    <route>
     ...
         <setHeader>
                 ${header.value}
         </setHeader>
      ...
    </route>
</beans>

Is there a solution for camel 2.7 ?

best,
christoph
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

Christian Mueller
Does this solve your needs: http://camel.apache.org/constant.html

<from uri="seda:a"/>
<setHeader headerName="theKey">
<constant>theValue</constant>
</setHeader>

Best,
Christian

On Wed, Jan 18, 2012 at 10:34 AM, Christoph Burmeister <
[hidden email]> wrote:

> hi,
>
> how can I set a header with a value from a properties-file using
> spring-xml?
> Doing this with the const-tag is no problem, but then the value has to be
> directly written in the camel.xml:
>
> <setHeader>
>   <const>foobar</const>
> </setHeader>
>
> I like to use something like this:
>
> environment.properties:
> -----------------------------
> header.value=foobar
>
> camel.xml
> ---------------
> <beans>
>   <bean id="placeholderConfig"
>
>
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>        <property name="locations">
>            <list>
>                <value>environment.properties</value>
>                <value>another-file.properties</value>
>            </list>
>        </property>
>    </bean>
>
>
>    <route>
>     ...
>         <setHeader>
>                 ${header.value}
>         </setHeader>
>      ...
>    </route>
> </beans>
>
> Is there a solution for camel 2.7 ?
>
> best,
> christoph
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

bibryam
In reply to this post by Christoph Burmeister
My guess is that something like this should work:

    <setHeader headerName="myHeader">
            <simple>${properties:key}</simple>
    </setHeader>


Bilgin

On 18 January 2012 09:34, Christoph Burmeister
<[hidden email]> wrote:

> hi,
>
> how can I set a header with a value from a properties-file using
> spring-xml?
> Doing this with the const-tag is no problem, but then the value has to be
> directly written in the camel.xml:
>
> <setHeader>
>   <const>foobar</const>
> </setHeader>
>
> I like to use something like this:
>
> environment.properties:
> -----------------------------
> header.value=foobar
>
> camel.xml
> ---------------
> <beans>
>   <bean id="placeholderConfig"
>
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>        <property name="locations">
>            <list>
>                <value>environment.properties</value>
>                <value>another-file.properties</value>
>            </list>
>        </property>
>    </bean>
>
>
>    <route>
>     ...
>         <setHeader>
>                 ${header.value}
>         </setHeader>
>      ...
>    </route>
> </beans>
>
> Is there a solution for camel 2.7 ?
>
> best,
> christoph
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

Christoph Burmeister
In reply to this post by Christoph Burmeister
Hi,

@Christian: That would mean, I have to hold the value for the header in my
camel.xml and that's not what I need. I need it in a separate file :-/
Thank's anyway.

@Bilgin: That's the way it works :-) Thank you.

For others: you need to define a propertyPlaceholder in the context to use
external properties:


camel.properties
-----------------------
header.value = foobar

camel.xml
---------------

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="properties" location="camel.properties"/>
                <route>
                      .....
                      <setHeader headerName="foobarHeader">
<simple>${properties:header.value}</simple>
                      </setHeader>
                      <log message="set header >>foobarHeader<< to
value ${properties:header.value}" loggingLevel="INFO" />
                      ...
                </route>
    <camelContext>


best,
christoph
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

ebinsingh
Hi All,

I am trying to set few header's, but does not seem to work.
I guess I am missing something but not able to find that out.
The below logs age not printted in the log file.

<route>
      <from ref="acquireltel2" />
            <setHeader headerName="pathName"><simple>${file:path}</simple></setHeader>
                  <log message="set header pathName to ${file:path}" loggingLevel="INFO"/>
            <setHeader headerName="fileName"><simple>${file:name}</simple></setHeader>
              <log message="set header fileName to ${file:name}" loggingLevel="INFO"/>
        <setHeader headerName="fileType"><constant>ltel2</constant></setHeader>
              <log message="set header fileType to ltel2" loggingLevel="INFO"/>
      <to ref="producerQueue"/>
</route>

Appriciate your help.

Ebe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

Claus Ibsen-2
Put the <log> outside the <setHeader>.

On Thu, Jan 19, 2012 at 3:56 PM, ebinsingh
<[hidden email]> wrote:

> Hi All,
>
> I am trying to set few header's, but does not seem to work.
> I guess I am missing something but not able to find that out.
> The below logs age not printted in the log file.
>
> <route>
>      <from ref="acquireltel2" />
>            <setHeader
> headerName="pathName"><simple>${file:path}</simple></setHeader>
>                  <log message="set header pathName to ${file:path}"
> loggingLevel="INFO"/>
>            <setHeader
> headerName="fileName"><simple>${file:name}</simple></setHeader>
>              <log message="set header fileName to ${file:name}"
> loggingLevel="INFO"/>
>        <setHeader headerName="fileType"><constant>ltel2</constant></setHeader>
>              <log message="set header fileType to ltel2" loggingLevel="INFO"/>
>      <to ref="producerQueue"/>
> </route>
>
> Appriciate your help.
>
> Ebe
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/using-values-from-a-properties-file-in-setHeader-method-tp5154287p5157868.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using values from a properties-file in setHeader-method

ebinsingh
I see something strange here.
If I have the below to routes, the logginf works perfectly.
<route>
        <from ref="acquireltel2" />
                <setHeader headerName="pathName"><simple>${file:path}</simple></setHeader>
                        <log message="set header pathName to ${file:path}" loggingLevel="INFO"/>
                <setHeader headerName="fileName"><simple>${file:name}</simple></setHeader>
                        <log message="set header fileName to ${file:name}" loggingLevel="INFO"/>
                <setHeader headerName="fileType"><constant>ltel2</constant></setHeader>
                        <log message="set header fileType to ltel2" loggingLevel="INFO"/>
                <to ref="producerQueue"/>
</route>
<route>
        <from ref="producerQueue"/>
                <log message="Processing messege out of producerQueue ${file:name}   ${file:path}" loggingLevel="INFO"/>
        <to uri="jms:queue:test_request_2"/>
</route>

But NOT if I have the second route as below. Do not know what difference it makes in the flow.
I am not seeing any of the logs.


<route>
        <from ref="producerQueue"/>
                <log message="Processing messege out of producerQueue" loggingLevel="INFO"/>
                <choice>
                        <when>
                                <simple>${header.fileType} == "ltel2"</simple>
                                <log message="processing ltel2 file type" loggingLevel="INFO" />
                                <threads executorServiceRef="ltel2threadpool1">
                                        <bean ref="ltel2Consumer" method="doConsume" />
                                </threads>
                        </when>
                </choice>
</route>


Also please adive if the above Choice evaluation is correct.
Loading...