I'm trying to update a cfg file using config admin from one bundle and listen to that config file from other bundle. When I deploy code I get java.lang.ClassNotFoundException: org.osgi.service.cm.ManagedService. Pleasse point to any Talend example where a config file is programmatically updated.
Thanks,
tBeginner
My karaf tutorial about config admin service might help you. See:
http://liquid-reality.de/display/liquid/2011/09/23/Karaf+Tutorial+Part+2+-+Using+the+Configuration+A... The ClassNotFoundException means that you need to import the package "org.osgi.service.cm" in your Manifest. The simplest way to do this is to use the maven bundle plugin like shown in the examples.
Unfortunately I do not have an example about changing the config. It is quite simple though. You get the config admin service using a blueprint service reference. Then with the config admin service you retrieve the configuration by pid and set new properties. There is an example at the felix website:
http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.html
Hi Christian
Problem with felix example is it goes into infinite loop when I deploy. The following sample code prints on console "ConfigAdminRef {org.osgi.service.cm.ConfigurationAdmin}={service.vendor=Apache Software Foundation, service.pid=org.apache.felix.cm.ConfigurationAdmin, service.description=Configuration Admin Service Specification 1.2 Implementation, service.id=33}"
public void start(BundleContext bc)
throws Exception {
Dictionary props = config.getProperties();
// if null, the configuration is new
if (props == null) {
props = new Hashtable();
}
// set some properties
props.put("port","1234");
// update the configuration
config.update(props);
}
Often in these cases an exception happens in the start method and OSGi swallows this exception. So you may try to surround the whole start method with a try catch and print the exception so you see if this is the case.
I do not get any error trace. There is a non null configadmin reference and when i try to get configadmin service from its reference the bundle restarts.