I'm using blueprint in Karaf to bootstrap the startup of a CamelContext which in turn configures a route defined in the Java DSL (Camel version 2.21.2). In the blueprint.xml, I've defined a few default property placeholders to take advantage of the config admin OSGi service:
<cm:property-placeholder persistent-id="foo.MyRoute">
<cm:default-properties>
<cm:property name="log.message" value="Hello world"/>
<cm:property name="response.code" value="200"/>
</cm:default-properties>
</cm:property-placeholder>
In the Java DSL I can use the {{log.message}} placeholder just fine as it's a String:
from("timer:timer").log("{{log.message}}")
However, what I'm looking to figure out is how to go about setting the type of the placeholder so I can use them in cases like the following:
.setHeader(Exchange.HTTP_RESPONSE_CODE).constant("{{response.code}}")
It's a bit of a contrived example, but what I'm trying to do here is set a header to an int/Integer type.
Are the placeholders exclusively for use in the endpoint URI definitions? Or should I be casting the resolved String to the type that I require? I'm assuming I've missed something here or am not using the placeholders as intended...
I've read https://camel.apache.org/manual/latest/using-propertyplaceholder.html and in particular the sections after: Using Property Placeholders for Any Kind of Attribute in the XML DSL and I see that there is support for auto type casting, but it seems to only apply to EIP options:
from("direct:start")
.multicast()
.placeholder("stopOnException", "stop")
.to("mock:a")
.throwException(new IllegalAccessException("Damn"))
.to("mock:b");
Any help would be appreciated as I've read the documentation so often now the words have stopped making sense!
You can use @PropertyInject
to inject a property on a field in the route builder class, where the field can be the type:
@PropertyInject("myPropertyKey")
private int myValue;
Then you can use the field in your route, via constant.
But Camel is often capable of converting from one type to another when needed, eg in that header example you can set it as a string value and that is okay.
You can also use simple where you can specify the type
.setHeader("foo", simple("{{foo}}, int.class))