camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Huston <shus...@riverace.com>
Subject RE: Seeking to understand properties
Date Wed, 16 Nov 2016 17:51:05 GMT
Thank you for the responses thus far. I still have some confusion and an observation.

First, I find it very confusing and non-intuitive that the "properties" in CamelContext are
apparently not the "properties" in property placeholder. From my reading of the various doc
pages it seemed like property placeholders are ways to get values from the properties substituted
into routes. But it seems like maybe there are more than one set, or type, of properties.
Is this true?

My observation... in my test below I added @PropertyInject("datafile") on the line above "private
String filename;" and that _did_ get the value set via useOverridePropertiesWithPropertiesComponent().
However, if I add the same @PropertyInject to a member in the MyRouteBuilder class, that _does
not_ get the value.

Can someone please help me understand what's going on here? 

Thanks,
-Steve

> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Wednesday, November 16, 2016 9:59 AM
> To: users@camel.apache.org
> Subject: Re: Seeking to understand properties
> 
> Hi
> 
> context().getProperty("dataFile");
> 
> is not property placeholders. Its just generic key/value pairs on
> CamelContext. See the javadoc of the API.
> 
> For property placeholders take a look at http://camel.apache.org/using-
> propertyplaceholder.html
> 
> On Tue, Nov 15, 2016 at 11:58 PM, Steve Huston <shuston@riverace.com>
> wrote:
> > I am struggling to understand something I fear is very basic, but I just don't
> see it. Hoping someone can help me understand this.
> >
> > Properties... I can use them in route definitions, but I don't seem to be able
> to obtain their values in regular Java code.
> >
> > Example (using Camel 2.16.3):
> >
> > I have a route builder:
> >
> > public class MyRouteBuilder extends RouteBuilder {
> >     public void configure() {
> >         from("file:{{dataFile}}?noop=true")
> >          .to("file:target/messages/others");
> >     }
> > }
> >
> > And a unit test:
> >
> > @RunWith(JUnit4.class)
> > public class UnitTest extends CamelTestSupport {
> >
> >         private String fileName;
> >
> >             @Override
> >             protected RouteBuilder createRouteBuilder() {
> >                 return new MyRouteBuilder();
> >             }
> >
> >             @Override
> >             public Boolean ignoreMissingLocationWithPropertiesComponent() {
> >                 return true;
> >             }
> >
> >             @Override
> >             protected Properties
> useOverridePropertiesWithPropertiesComponent() {
> >                     Properties override = new Properties();
> >                     override.put("dataFile", "overridden-file");
> >                     return override;
> >             }
> >
> >             @Test
> >                 public void testPropertyGetting() throws Exception {
> >                 fileName = context().getProperty("dataFile");
> >                 assert(fileName != null);
> >             }
> > }
> >
> > When I run this test, the output includes:
> >
> > INFO  Route: route1 started and consuming from:
> > Endpoint[file://overridden-file?noop=true]
> >
> > So the override property set above did get filled into the route definition.
> > However, when I try to get the property in the testPropertyGetting()
> > method, the value is null
> >
> > Why???
> >
> > -Steve
> >
> 
> 
> 
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
Mime
View raw message