How to get  OSGI Factory Configurations values in AEM ? | Adobe Higher Education
Skip to main content
mahadevb2859329
Level 2
October 21, 2016
解決済み

How to get  OSGI Factory Configurations values in AEM ?

  • October 21, 2016
  • 6 の返信
  • 10110 ビュー

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.

 

 

このトピックへの返信は締め切られました。
ベストアンサー Jitendra_S_Toma

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 の返信

smacdonald2008
Level 10
October 21, 2016

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.

Level 8
October 21, 2016
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); }
kautuk_sahni
Community Manager
Community Manager
October 24, 2016

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

Kautuk Sahni
varunmitra
Adobe Employee
Adobe Employee
October 27, 2016

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. 

joerghoh
Adobe Employee
Adobe Employee
October 27, 2016

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.

Jitendra_S_Toma
Level 10
October 28, 2016

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