Skip to main content

Day 12: Creating your Custom OSGi configuration


AEM Developer Series

We all know that AEM works on Apache Felix which is an implementation of OSGi. OSGi provides a way to manage bundles and configurations. We saw one example of an OSGi configuration in the previous post where we saw Adobe Granite HTML Library Manager.

You can find all the Out of the box OSGi configurations at - http://<host>:<port>/system/console/configMgr. Apart from out of the box configurations, we can also create our custom configurations. In this post, we will be creating a custom out of the box configuration which reads the user input and gets the JSON reponse from a web service.

Code in Action

  • To make a custom OSGi configuration, we need to first create an interface whose public methods will represent the fields in the configuration. 
  • Create an interface named HttpConfiguration and paste the following code in it.
  • This configuration has a checkbox Enable Config, a drop-down Protocol, two text fields Server and Endpoint.
  • Now create an interface HttpService to make the http call as below
  • Create an implementation class HttpServiceImpl as below.
  • This is an OSGi component in which we are reading values from the OSGi configuration. Notice that we are using @Designate annotation to link this class to the configuration.
  • Now create a simple Sling Servlet to use this component as follows.
  • Go to the ./system/console/configMgr and search for Http Configuration and open it and configure it accordingly. Then save.
OSGi Configuration
[{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}, {"userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false}, {"userId": 1, "id": 3, "title": "fugiat veniam minus", "completed": false}, {"userId": 1, "id": 4, "title": "et porro tempora", "completed": true}, ...]

Conclusion

Congratulations!! 🙋 today we created a custom OSGi configuration that reads values from the user and provides the results accordingly. I hope you enjoyed this post.

You can find the complete code of this project on my GitHub in this commit. Feel free to fork or open issues, if any.

I would love to hear your thoughts on this and would like have suggestions from you to make it better. 

Feel free to befriend me on Facebook, Twitter or Linked In or say Hi by email.

Happy Coding 😊



Comments

Popular posts from this blog

Day 00: AEM Developer Series

Hello everyone! Welcome to this AEM development series. We can all see the revolution of Digital Marketing today. Companies are dying to be a part of it and they have made this a war for the Digital Marketing tools.
Adobe is way ahead in this war and has gained a lot of market capture. They are leaders in the Digital Marketing platforms since 2014-15. One of the flagship product in Adobe's Digital Marketing suite is Adobe Experience Manager (AEM).
Since AEM is in huge demand, the people who know how to develop on AEM are also in huge demand. But developing on AEM is not easy as it is made up of various open-source technologies such as Apache Felix (OSGi), Apache Sling, Apache Oak and Adobe's own technologies like Granite, HTL etc. Learning all these technologies in conjunction can sometimes become confusing and frustrating 😫.
When I first started learning AEM in 2016, I was dumbfounded to see there is so much going on under the hood. I then spent months to gather all the res…

Day 01: Introduction to AEM

Day 04: Developing first OSGi bundle