Skip to main content
mahadevb2859329
Level 2
Oct 21, 2016 5:09 PM UTC
Solved

How to get  OSGI Factory Configurations values in AEM ?

how to read OSGI factory configuration values from configuration

i have created configuration which have three properties (string,string , Array ), same configuration for Apache Sling Logging Logger Configuration 

please can you send me implementation code for how to get OSGI factory configuration values.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Jitendra_S_Toma
Jitendra_S_TomaAccepted solution
Level 10
Oct 28, 2016 6:34 AM UTC

Hi @Jorg,

Small correction. I think, Component annotation must have  "configurationFactory = true" attribute to enable OSGI Service factory.

For more details, follow the instruction given in below doc.

https://cqdump.wordpress.com/2014/08/05/managing-multiple-instances-of-services-osgi-service-factories/

 

Regards,

Jitendra

6 replies

smacdonald2008
Level 10
Oct 21, 2016 6:29 PM UTC

See this AEM Community Article on this use case: 

This development article guides you through creating an OSGi bundle that reads OSGi configuration values that are defined in CRXDE Lite. To read this development article, click:

https://helpx.adobe.com/experience-manager/using/osgi_config.html.

Translate
Level 8
Oct 21, 2016 9:14 PM UTC
private final String MY_OSGI_PROPERTY = "MyProperty"; private String myProperty; @Activate protected void activate(final Map<String, Object> config) { this.myProperty = PropertiesUtil.toString(config.get(MY_OSGI_PROPERTY), null); }
Translate
kautuk_sahni
Level 9
Oct 24, 2016 6:39 AM UTC

Hi 

Please refer to this Helpx artilce:- 

Link:- https://helpx.adobe.com/experience-manager/using/osgi_config.html

This class contains this method that reads the configuration values.

//

myArraySetting = PropertiesUtil.toStringArray(properties.get(MY_PROPERTY_NAME), ArrayUtils.EMPTY_STRING_ARRAY);
    

protected void readProperties(Map<String, Object> properties)
{
LOG.info(properties.toString());
this.multiString = PropertiesUtil.toStringArray(properties.get("multifield"));
LOG.info("Mutli String Size: " + this.multiString.length);
this.simpleString = PropertiesUtil.toString(properties.get("simplefield"), "default");
LOG.info("Simple String: " + this.simpleString);
}
 

I hope this would help you.

 

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
varunmitra
Adobe Employee
Adobe Employee
Oct 27, 2016 4:03 PM UTC

Here is some sample code:

@Property(label = "Path", description = "Delete this path", value = "/tmp/mypath") public static final String CLEANUP_PATH = "cleanupPath"; protected void activate(ComponentContext componentContext){ configure(componentContext.getProperties()); } protected void configure(Dictionary<?, ?> properties) { this.cleanupPath = (String.valueOf(properties.get(CLEANUP_PATH)) != null)?String.valueOf(properties.get(CLEANUP_PATH)):null; LOGGER.info("configure: cleanupPath='{}''", this.cleanupPath); }

 

Hope this helps. 

Translate
joerghoh
Adobe Employee
Adobe Employee
Oct 27, 2016 8:21 PM UTC

In case you are referring to an OSGI service factory (your question isn't 100% clear to me): The difference from creating (and writing) a simple OSGI service to an OSGI service factory is just the "factory=true" parameter to the @Component annotation. Then you have the chance to create N instances of the configuration, and for each configuration a dedicated version of the service is started with this specific configuration.

Translate
Jitendra_S_Toma
Jitendra_S_TomaAccepted solution
Level 10
Oct 28, 2016 6:34 AM UTC

Hi @Jorg,

Small correction. I think, Component annotation must have  "configurationFactory = true" attribute to enable OSGI Service factory.

For more details, follow the instruction given in below doc.

https://cqdump.wordpress.com/2014/08/05/managing-multiple-instances-of-services-osgi-service-factories/

 

Regards,

Jitendra

Translate