Victor Victor - 24 days ago 11
Java Question

How to get rid of OSGi bundle's properties that are not exist in their corresponding configuration ("service.pid", etc.)?

I have the class similar to the following:

@Component(configurationPid = "foo.bar", configurationPolicy = ConfigurationPolicy.REQUIRE)
public class MyClass {

@Activate
public void activate(Map<String, Object> properties) throws Exception {
for (String property : properties.keySet()) {
if (!isValidProperty(property)) {
throw new IllegalArgumentException("Unknown property: " + property);
}
...
}
}

}


The
properties
map must contain the properties from the corresponding configuration source (e.g. a file provided by an user). And it is, but it also contains some properties that are not really exist (
service.pid
,
felix.fileinstall.dir
, etc.), so my program is broken. I want to get rid of them somehow.

I tried to use
ConfigurationAdmin.getConfiguration.getProperties
and also blueprint
cm-properties
but this gives the same effect.

I can't hardcode the names of the properties to exclude, because I don't know what they are.

Is there any means to tell the OSGi runtime not to put them at all in my map?

I'm doing this using ServiceMix's OSGi support (which is essentially Karaf, Felix, and Aries).

Answer

Currently there is no way to exclude these artificial properties but I agree this is pretty bad.

You can open an issue and the Apache felix project jira.

Comments