The ConfigurationAdminTestCase shows how an OSGi ManagedService can be configured through the ConfigurationAdmin service.
public void testManagedService() throws Exception { // Get the {@link Configuration} for the given PID Configuration config = configAdmin.getConfiguration(ConfiguredService.SERVICE_PID); assertNotNull("Config not null", config); Dictionary<String, String> configProps = new Hashtable<String, String>(); configProps.put("foo", "bar"); config.update(configProps); // Register a {@link ManagedService} Dictionary<String, String> serviceProps = new Hashtable<String, String>(); serviceProps.put(Constants.SERVICE_PID, ConfiguredService.SERVICE_PID); bundlecontext.registerService(new String[] { ConfiguredService.class.getName(), ManagedService.class.getName() }, new ConfiguredService(), serviceProps); // Wait a little for the update event if (latch.await(5, TimeUnit.SECONDS) == false) throw new TimeoutException(); // Verify service property ServiceReference sref = bundlecontext.getServiceReference(ConfiguredService.class.getName()); ConfiguredService service = (ConfiguredService) bundlecontext.getService(sref); assertEquals("bar", service.getValue("foo")); config.delete(); }
Configuration Admin support is build into the config admin subsystem and is available by default. The OSGi configurations will appear together with any other configurations that use this service in the AS7 domain model.
For the OSGi specific part we use this capability, which is also configured by default
<capability name="org.apache.felix.configadmin"/>