0

I'm running Karaf and have a blueprint xml file that access a file from the Karaf etc directory (...apache-karaf/etc/SomeProperties.properties) for use in a bundle:

<ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]">
    <ext:location>file:etc/SomeProperties.properties</ext:location>
</ext:property-placeholder>

<bean id="SomeBean" class="impl.com.package.SomeBean"
      init-method="init" destroy-method="destroy">
    <property name="beanvariable1" value="$[property1key]"/>
    <property name="beanvariable2" value="$[property2key]"/>
</bean>

However, I also want to access not only all the properties in that one particular file, but all files from that same karaf/etc directory that end in .cfg (without naming any of the files individually). Can this be done?

Specifically, is there a way to specify a directory location instead of file location? And additionally filter on file type within that directory?

Or, for that matter, is there any way (using blueprint or otherwise) to access all the files in the apache-karaf/etc dir (not just particular properties contained in them) from within a bundle running in Karaf?

Woodchuck
  • 3,869
  • 2
  • 39
  • 70

1 Answers1

1

Get a handle to the Configuration Admin Service directly, you can then roll through all the stored configuration sets (called 'pid' for Persistent ID in OSGi)

You have a couple options, you can reference it using the blueprint built-in bean reference to your bundle (which has a way to traverse to the Config Admin Service). See this link for one of the more complete references to working with Blueprint: IBM's Blueprint Reference

Or you can set a reference and get wired directly to the Config Admin service

<reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin">

Then wire the 'configAdmin' bean into your bean.

Matt Pavlovich
  • 4,087
  • 1
  • 9
  • 17
  • Great info. Thanks! A follow-up, if you can help: when iterating through the properties in each PID (getProperties() method of Configuration), additional properties appear: service.pid & felix.fileinstall.filename. Any idea whether it's possible to get only the properties actually contained in the file, and not these additional ones (even though they seem useful)? – Woodchuck Jul 19 '17 at 17:01
  • Anytime =) Not possible to remove those from the list.. felix/karaf add them for tracking. – Matt Pavlovich Jul 19 '17 at 19:40