How to read property from OSGI configuration in AEM 6.1 in model class which extends WCMUse class | Community
Skip to main content
Level 2
October 25, 2015
Solved

How to read property from OSGI configuration in AEM 6.1 in model class which extends WCMUse class

I am extending my model class to WCMUse class to write my business logic. I have osgi configuration which has couple of properties. I want to read one of the property in my model class. I am not sure how to get the handle of osgi configuration in WCMUse class. Any pointers will be highly appreciated. 

edubey
edubeyAccepted solution
Level 10
October 25, 2015

Hi,

public class SightlyComponent extends WCMUse  { private String myTitle; @Override public void activate() { myTitle = "My Project " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }

This is demo piece of code which will help you to call a service in sightly class.

Write a small service to read those configuration properties and then call your service like above in sightly class

3 replies

kautuk_sahni
Employee
October 28, 2015

Hi 

Apart from what mentioned in above mentioned posts, You can refer to following :-

@Reference
    ConfigurationAdmin configAdmin;
   
    /*Get the configurations based on the fully qualified name of your Bundle*/
    Configuration config = configAdmin.getConfiguration(Constants.FULLY_QUALIFIED_CLASS_NAME);

    /*Get the configuration properties / returns a Dictionary Object*/
    Dictionary<?, ?> properties = config.getProperties();
   
    /*Iterate through the Dictionary properties to get your configurations*/   
    String item = (String) properties.get(Constants.CONFIG_ITEM);

 

Link:- http://myadobecq.blogspot.in/2013/12/reading.html

 

Another Reference link :- http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

I hope this will help you.

 

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
Lokesh_Shivalingaiah
Level 10
October 25, 2015

You can use ConfigurationAdmin and get the properties using pid of the service from where you need to read the properties

ex:

@Reference

Private ConfigurationAdmin config;

Configuration config = configAdmin.getConfiguration(<pid>);

Translate
edubey
edubeyAccepted solution
Level 10
October 25, 2015

Hi,

public class SightlyComponent extends WCMUse  { private String myTitle; @Override public void activate() { myTitle = "My Project " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }

This is demo piece of code which will help you to call a service in sightly class.

Write a small service to read those configuration properties and then call your service like above in sightly class

Translate