Adobe Experience Manager | AEM/CQ | Apache Sling

Programmatically read and update OSGi configurations in Adobe Experience Manager and Apache Sling using the ConfigurationAdmin service.

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

Get the HTML for an AEM resource, component or page
It's easy to retrieve a rendered component by making a GET request. Apache Sling's SlingMainServlet and DefaultGetServlet will process GET requests, take the path's extension into account, and return the rendered resource. The most obvious example of triggering this process is simply typing the component's path into the browser's address bar or making an AJAX call. You can retrieve the HTML markup (or JSON, XML, txt, PDF, etc...) for a component as well as a page if you provide the correct path. After all, they're both just Sling resources.

Trying to get the rendered HTML of a component on the server side is still easy, but requires a little more work. Without knowing the inner workings of Sling, you might use Java's class to construct and make an HTTP request from within your application to your application.

The better way is to use the SlingRequestProcessor service as the entry point into Sling's process. The processRequest method of the SlingRequestProcessor takes an HttpServletRequest, HttpServletResponse, and Resource Resolver as parameters. The only trick is that you need to provide a request that enables you to set the request path and a response that enables you to get the OutputStream as a String.

AEM provides the RequestResponseFactory where you can easily get such a request and response.

You'll need to provide your own mock request and response in Apache Sling. Fortunately, it already exists. You need the HttpRequest, HttpResponse, and TestServletOutputStream classes.

You will need to include the dependency in your pom file. If your bundle resolves but your component remains unsatisfied, make sure sure you've included the package in the Import-Package section of your maven-bundle-plugin.
Introducing the Publick Apache Sling + Sightly blog engine.
This blog post is the unveiling of the Publick Sling + Sightly blog engine. The name of the project is in honor of Publick Occurrences Both Forreign and Domestick, the first multi-page newspaper published in the American colonies.

Anyone familiar with AEM will immediately feel comfortable with this project as the Publick blog engine uses the same technology stack as the latest Adobe Experience Manager. Publick uses the Sightly server-side templating language to render the markup. The restful Apache Sling framework is used to access the Apache Jackrabbit implementation of the Java Content Repository. Apache Felix is the implement of the OSGi framework and Apache Maven is used to manage the builds.

Screenshot of the asset upload capability of Publick.
I've wanted to write about my experiences, my work and my passion for quite some time. I could have used Blogger or Medium and I considered using Jekyll with GitHub Pages for more excitement. I could have had a WordPress site running in mere minutes. However, I came to the conclusion that using any of those platforms to blog about the Adobe Marketing Cloud and Adobe Experience Manager specifically, just didn't resonate harmoniously within. The virtuous platform would of course been AEM itself, however, I simply can't afford to purchase a license from Adobe - maybe it's the preposterous cost of renting in the San Francisco Bay Area. Therefore, I did the next best thing; I dedicated my free time to writing a custom blog engine that uses the same technology stack as Adobe Experience Manager.

I've made the code for the blog engine publicly available on GitHub. Likewise, I've done the same for the implementation of Publick. The purpose of this website is to share my thoughts and experiences. However, it is also meant to be a living demonstration of the Publick blog engine. For that reason, I've created a read-only test account and published the credentials. You can log into the dashboard at with user demo and password demo.

For this project, I'm using a scaled down version of a similar setup that we're using to host Adobe's Document Cloud AEM marketing site. I'm using an EC2 instance running Amazon's Linux AMI to host the Sling server. Emails are sent through Amazon's Simple Email Service (SES). GoDaddy remains my DNS manager with the A record pointing to my Amazon Elastic IP address and the MX record remaining at GoDaddy to manage my personal emails. The next step is to implement Adobe's Dispatcher Apache web server module for added security and performance. At Adobe my project is using Akamai's CDN; for this project I want to try Amazon's CloudFront. Thanks to Amazon's free tier and the open source Apache projects, this entire setup is near cost free. My only expense is renewing my domain name.

This project, like all projects, is a work in progress and a learning experience. It's been a rich, rewarding, and enormously satisfying process getting into the lower levels of Sling and Jackrabbit, all of which is completely applicable to AEM. There's still very much left to accomplish and I look forward to its continued progress.

Publick Sling + Sightly blog engine on GitHub implementation of Publick on GitHub

Publick live example (user/pass: demo/demo)