Programmatically updating OSGi configurations in AEM and Sling

Adobe Experience Manager | AEM/CQ | Apache Sling

Programmatically updating OSGi configurations in AEM and Sling

OSGi components can be configured via the concept of Managed Services and Managed Service Factories. Each component has a Service PID. Once a configuration has been updated, the changes are persisted to the file system. In Adobe Experience Manager you can find the files under the crx-quickstart/launchpad/config folder. If you're using the Sling jar, you can find the files under the sling/config folder.

Hopefully you're following best practices and creating sling:OsgiConfig files so that configurations can be stored in your version control system and configured for specific server instances assigned by Sling run modes. When you want to manually update an OSGi configuration you do so through the Apache Felix console's Configuration screen located at http://localhost:4502/system/console/configMgr.

You can programmatically read and update OSGi configurations through the Apache Felix provided ConfigurationAdmin service. In fact, this is the same service used by the Apache Felix console. When you look at the Configuration console it tells you the status of the ConfigurationAdmin service. If you disable the Apache Felix Configuration Admin Service (org.apache.felix.configadmin) you will notice that you are no longer able to update configurations from the Felix console.

Using the service is simple and straightforward. However, the one thing to watch out for is that updating the configuration though ConfigurationAdmin is an asynchronous call and the component associated with the configuration will become unavailable for a brief moment on update. That means trying to make rapid consecutive updates or trying to read from the configuration directly after an update is unreliable unless properly handled.

The following example demonstrates how to get a Configuration from a Managed Service as well as a Managed Service Factory, how to get properties from the configuration and how to update the configuration.

The files below are a service I created for the Publick Sling + Sightly Blog Engine to manage configurations easily and consistently throughout the application as well as a sample consumer of the service.

Further reading:

Apache Felix Configuration Admin Service


Dhrati | February 03, 2017 at 08:40 AM | Reply

The blog is very useful,.. Thank you,. :)

Namit Kochar | April 16, 2019 at 08:28 AM | Reply

Hi Nate, Is it possible to programmatically add a field in osgi configuration. For example, dynamically adding a drop down in osgi config.

EllAlople | July 29, 2019 at 11:35 PM | Reply

Prix Amoxicillin 100mg Donde Comprar Cialis Farmacia <a href=>cialis</a> Viagra Generico Online Spedizione Rapida Lowest Price Cialis 20mg Brand In Usa Acheter Kamagra Voir Le Profil

EllAlople | August 03, 2019 at 05:44 AM | Reply

Tabletten Viagra Foto Cialis Sur Internet Avis Kamagra Consegna Veloce Francia <a href=>propecia e esterilidad</a> Kamagra Com Canadian Medicine Buy Atarax No Script

pjwtmhok | March 11, 2020 at 04:42 AM | Reply

buy viagra cheap viagra <a href="">viagra 100mg </a> viagra generic viagra 100mg bh88Ð°Ð¿Ñ Ð¿hfa viagra pills viagra 100mg <a href=>viagra generic </a> viagra 100mg buy viagra

Leave a Comment