You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Olivier.Roger" <ol...@bsb.com> on 2010/10/29 17:00:00 UTC

Properties in Java DSL

Hello Camel !

Since using properties in non-string attribute in Spring DSL is not possible
(see CAMEL-3171).
I would like to have a example how to do it in Java DSL.

For example I use a Throttler and I would like to be able to configure the #
msg per period and the period parameters with properties (in fact with SMX
config service).

Thanks in advance,

Olivier

-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3242156.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
I see,

It explains the results I observed then.
Thanks for the explanation.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3254753.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by German O <ge...@gmail.com>.
Ok, and how can I access to a property value, from java code?



--
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p5723683.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 8, 2010 at 10:01 AM, Olivier.Roger <ol...@bsb.com> wrote:
>
> Thanks Claus,
>
> I got this working using
> getContext().resolvePropertyPlaceholders("{{key}}"));
>
> However, I could not retrieve the Propeties Object from the context.
> When I use this :
>
>        Map<String, String> properties = getContext().getProperties();
>        System.out.println("size=" + properties.keySet().size());
>
> The output is always "size=0".
>
> Is there a reason for this ?

Yes those 2 features are not related.

The properties placeholders is a Camel component

See the documentation
http://camel.apache.org/properties

Property placeholders is also discussed in the camel book chapter 6


The properties on CamelContext is currently kinda like for system
properties where you can set a few options to control some logging and
charset etc.


> --
> View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3254659.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Properties in Java DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
Thanks Claus, 

I got this working using
getContext().resolvePropertyPlaceholders("{{key}}"));

However, I could not retrieve the Propeties Object from the context.
When I use this :

        Map<String, String> properties = getContext().getProperties();
        System.out.println("size=" + properties.keySet().size());

The output is always "size=0".

Is there a reason for this ?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3254659.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by Claus Ibsen <cl...@gmail.com>.
You should most likely use ref in the location to refer to that OSGi
property stuff.

        <propertyPlaceholder id="properties"
 location="ref:crg-properties" />


On Fri, Oct 29, 2010 at 6:15 PM, Olivier.Roger <ol...@bsb.com> wrote:
>
> It appears that in both cases the Properties Object does not contains any
> entry.
> I use this to load it in the CamelContext.
>
>    <util:properties id="crg-properties"
> location="classpath:properties/endpoints.properties" />
>    <ctx:property-placeholder properties-ref="crg-properties" />
>
>    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"
> trace="true">
>        <propertyPlaceholder id="properties"
> location="classpath:properties/endpoints.properties" />
>
> Am I doing something wrong here ?
> --
> View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3242285.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Properties in Java DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
It appears that in both cases the Properties Object does not contains any
entry.
I use this to load it in the CamelContext.

    <util:properties id="crg-properties"
location="classpath:properties/endpoints.properties" />
    <ctx:property-placeholder properties-ref="crg-properties" />

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"
trace="true">
        <propertyPlaceholder id="properties"
location="classpath:properties/endpoints.properties" />

Am I doing something wrong here ?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3242285.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
I found 2 ways to do it, I do not know which one is best.

First I configure a propertiesPlaceholder in the CamelContext
    <osgix:cm-properties id="properties" persistent-id="myRoute" />

In both case I use the CamelContext using the getContext() method.
After that I can either retrieve the the Property as a Map :
    Map<String, String> properties = getContext().getProperties();

... Or use it to resolve the properties directly
    getContext().resolvePropertyPlaceholders(null)

I feel more confortable to retrieve the object and use it but I was
wondering is there was any drawback/better alternative to that method ?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3242204.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
That's exactly what I needed.

Where can I find how to load the Properties from SMX config service ?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Properties-in-Java-DSL-tp3242156p3242178.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Properties in Java DSL

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Olivier,

why not simply make something like the following in the RouteBuilder:

Properties properties = new Properties();
properties.load(file);
from("uri").throttler(Integer.parseInt(properties.getProperty("throttler.value")).to("uri");

Moreover, if you use it in SMX4, you can get the property from the 
ConfigAdmin service.

Regards
JB

On 10/29/2010 05:00 PM, Olivier.Roger wrote:
>
> Hello Camel !
>
> Since using properties in non-string attribute in Spring DSL is not possible
> (see CAMEL-3171).
> I would like to have a example how to do it in Java DSL.
>
> For example I use a Throttler and I would like to be able to configure the #
> msg per period and the period parameters with properties (in fact with SMX
> config service).
>
> Thanks in advance,
>
> Olivier
>