Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to get  OSGI Factory Configurations values in AEM ?

Avatar

Level 2

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.

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 9

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-factori...

 

Regards,

Jitendra

View solution in original post

6 Replies

Avatar

Level 10

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.

Avatar

Level 8
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); }

Avatar

Administrator

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

Avatar

Level 3

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. 

Avatar

Employee Advisor

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.

Avatar

Correct answer by
Level 9

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-factori...

 

Regards,

Jitendra