I'm trying to use multiple property files from the etc
directory in a JBoss Fuse (6.3) Blueprint. My first approach was the following:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar" />
I thought that would work, as it is described in Red Hat's documentation:
Using multiple property placeholders in Blueprint
It is legal to define multiple property placeholders in a Blueprint XML file (that is, defining multiple cm:property-placeholder elements that reference different persistent IDs). One thing that you need to be aware of, however, is that there can be a clash if two properties from different property placeholders have the same name. In this case, the following rules determine which property takes precedence:
Explicitly defined property settings (for example, defined in a
etc/PersistentID.cfg
file) take precedence over default property settings (defined in acm:default-properties
element).If there is more than one explicit setting for a given property, the setting from the last property placeholder in the Blueprint file takes precedence.
Default property settings (defined in a
cm:default-properties
element) have the lowest priority.
But then I got the error that Multiple placeholders with the same prefix and suffix are not allowed
:
2018-05-15 17:43:59,065 | ERROR | /s42http1/deploy | BlueprintContainerImpl | 22 - org.apache.aries.blueprint.core - 1.8.0 | Unable to start blueprint container for bundle myBlueprint/0.0.1.SNAPSHOT
org.osgi.service.blueprint.container.ComponentDefinitionException: Multiple placeholders with the same prefix and suffix are not allowed
at org.apache.aries.blueprint.ext.PlaceholdersUtils.validatePlaceholder(PlaceholdersUtils.java:49)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parsePropertyPlaceholder(CmNamespaceHandler.java:318)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler.parse(CmNamespaceHandler.java:199)[20:org.apache.aries.blueprint.cm:1.1.0]
at org.apache.aries.blueprint.parser.Parser.parseCustomElement(Parser.java:1369)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.loadComponents(Parser.java:427)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.parser.Parser.populate(Parser.java:331)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:350)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:277)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[22:org.apache.aries.blueprint.core:1.8.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)[10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)[10:org.apache.felix.fileinstall:3.6.4]
So I've set the placeholder-prefix
and placeholder-suffix
:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
With that, I should be able to access etc/foo.cfg
with $ { } and etc/bar.cfg
Properties with $ ( ), right?
No:
Caused by: java.io.IOException: Could not open $(bar_property) as a file, class path resource, or URL.
at org.apache.camel.util.jsse.JsseParameters.resolveResource(JsseParameters.java:182)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyStoreParameters.createKeyStore(KeyStoreParameters.java:174)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.KeyManagersParameters.createKeyManagers(KeyManagersParameters.java:108)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.util.jsse.SSLContextParameters.createSSLContext(SSLContextParameters.java:256)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createConnectionRegistry(HttpComponent.java:285)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.component.http4.HttpComponent.createEndpoint(HttpComponent.java:227)[296:org.apache.camel.camel-http4:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:569)[199:org.apache.camel.camel-core:2.17.0.redhat-630329]
... 36 more
And I've checked that bar_property
exists in etc/bar.cfg
.
So how to use multiple property-placeholder in JBoss Fuse Blueprints? I'm using JBoss Fuse 6.3.0.329.
As I type in that question, I found the answer directly above the quoted section of the RedHat documentation (Rubber duck debugging ;-) :
The syntax,
{{prefix}}
, substitutes the value of theprefix
variable into the blueprint XML file. The OSGi properties are set up using the following XML elements:
cm:property-placeholder
This element gives you access to the properties associated with the specified persistent ID. After defining this element, you can use the syntax,{{PropName}}
, to substitute variables belonging to the specified persistent ID.
cm:property-placeholder/cm:default-properties
You can optionally specify default values for properties by definingcm:property
elements inside thecm:default-properties
element. If the correspondingetc/PersistentID.cfg
file defines property values, however, these will be used instead.
So the definition of the property-placeholder was correct as follows:
<cm:property-placeholder persistent-id="foo" />
<cm:property-placeholder persistent-id="bar"
placeholder-prefix="$(" placeholder-suffix=")"/>
But in my example the property must then be used with {{bar_property}}
instead of $(bar_property)
.