Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

updating config file from bundle

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
Labels (3)
5 Replies
Anonymous
Not applicable

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

Christian
_AnonymousUser
Specialist III
Specialist III
Author

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 {

ServiceReference configurationAdminReference = bc.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
System.out.println("ConfigAdminRef "+ configurationAdminReference);
ConfigurationAdmin confAdmin = (ConfigurationAdmin) bc.getService(configurationAdminReference);
Configuration config = confAdmin.getConfiguration("demo.service.internal.MyConfigurator");

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);
}
Anonymous
Not applicable

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.
_AnonymousUser
Specialist III
Specialist III
Author

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.
_AnonymousUser
Specialist III
Specialist III
Author

I'm using TESB_SE v5.3.1