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 <shus...@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

Reply via email to