We have a OSGI Service (using R7 DS annotation). We are using OCD as innerclass within the service.
Also, we would like the component to read properties from the predefined sling:osgiconfig nodes in JCR.
Configuration policy is defined as required.
When the component/service load it goes into a "no config" state.
Need help to read these configs from sling:osgiConfig nodes.
Solved! Go to Solution.
Views
Replies
Total Likes
Why do you want to read sling:OsgiConfig values inside OCD?
OCD is used to declare the OSGi config structure.
You can declare OCD the same as config values but in the end, the value will be read from the defined value in repository.
Example
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/SimpleScheduledTask.java
yes, I get those when bundle is updated -
logger.info("PageJSONServletServiceImpl:activate:refrenceProperties {}",refrenceProperties.length);
01.09.2020 15:32:03.228 *INFO* [Background Update com.acc.aem64.AEM64App.core (545)] com.acc.aem64.core.services.impl.PageJSONServletServiceImpl PageJSONServletServiceImpl:activate:refrenceProperties 2
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
You can find a working example at https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/0ffd40a15460f8be8d3591e17d5648184f...
It features an OSGI service, which uses an inner class for configuration; it should behave according to your requirements.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
The configadmin does all what you expect. Things to check:
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Can you try as below, Firstly you have configuration policy as optional, and second, you are not declaring right interface for @component annotation.
Corrected code below:-
@component(immediate = true, service = DataConfig.class, property = {
Constants.SERVICE_DESCRIPTION + "=Data Config",
Constants.SERVICE_VENDOR + "=ABC"
})
@ServiceDescription("DataConfig Service")
@Designate(ocd = DataConfigImpl.Configuration.class)
public final class DataConfigImpl implements DataConfig {
@ObjectClassDefinition(name = "DataConfigImpl")
public @interface Configuration {
@AttributeDefinition(name = "paths", description = "Paths", type = AttributeType.STRING) String my_paths() default "";
}
@SuppressWarnings("rawtypes") private Dictionary props = null;
@activate Configuration configuration;
@activate ComponentContext componentContext;
@activate @MODIFIED protected void activate(Config c) {
try {
this.configuration = c;
}
}
}
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies