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.
Solved! Go to Solution.
Views
Replies
Total Likes
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.
Regards,
Jitendra
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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); }
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
Regards,
Jitendra
Views
Replies
Total Likes
Views
Likes
Replies