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

  1. Nice Article Bro !!
    Thanks for sharing good knowledge. You are really doing great work :)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This is one of the only guides to setting up an OSGI service for AEM that I can find, so its been a life saver. The only problem we have is when we try to create a cfg.json file to deploy the settings, it doesnt work (we end up with two duplicate entries in configMgr, the one you get above, plus the one created from the config file, both with the same PID. The service is reading the wrong one, but there seems nothing we can do about it.

    ReplyDelete
  4. i got a error in line number 66 at "String response = Network.readJson(url);" in HttpServiceImpl program.how can i resolve that issue? and how can i get this Network related import statement?

    ReplyDelete
  5. i have got some errors....how can i contact you?

    ReplyDelete

Post a Comment

Popular posts from this blog

Day 05: Working with Sling Servlets in AEM

AEM Developer Series Day 00: AEM Developer Series Day 01: Introduction to AEM Day 02: AEM Architecture Day 03: Setting up AEM Development Environment Day 04: Developing First OSGi Bundle Day 05: Working with Sling Servlets in AEM Day 06: Playing with Sling Post Servlet Day 07: Creating your first component in AEM Day 08: Dueling with JavaScript Use API Day 09: Dueling with Java User API Day 10: Getting to know Sling Models Day 11: Client Libraries in Action Day 12: Creating your custom OSGi Configuration Day 13: Schedulers in AEM Day 14: Eventing in AEM Day 15: Custom Workflows in AEM Day 16: Creating JMX Beans in AEM Day 17: Working with QueryBuilder API Day 18: Working with Granite Datasources in AEM Day 19: Replication API in Action Day 20: Working with Users and Groups in AEM A Servlet is a class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. For such applications, Servlet tec

Day 00: AEM Developer Series

image source:  https://solutionpartners.adobe.com/ 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