Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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. 

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

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

Avatar

Level 10

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>);

Avatar

Administrator

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



Kautuk Sahni