Expand my Community achievements bar.

SOLVED

Reading sling:OsgiConfig into @ObjectClassDefinition

Avatar

Level 4

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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



Arun Patidar

View solution in original post

36 Replies

Avatar

Community Advisor

@Adilmo  Can you go to /system/console/components or /system/console/configuration and see if you are able to see your service class? If yes try to click/open and see what is the PID it is populating..

 

Even you can fill the configuration from osgi console once, copy the content to your local config file and then delete the file

Avatar

Level 4
component is not starting ... it is in "no config" state .... I would like to the component to fetch SLING CONFIG and start on its own .... no manual configuration through console

Avatar

Level 4
The component remains in "no config" state even though there is sling:osgiconfig for the corresponding PID present in JCR ... kindly help

Avatar

Level 4
component is not starting ... it is in "no config" state .... I would like to the component to fetch sling:osgi configs and start on its own .... no manual configuration through console

Avatar

Correct answer by
Community Advisor

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



Arun Patidar

Avatar

Level 4
Our problem is that we want to load the configuration values from sling:osgiconfig and not add them manually to through console.

Avatar

Level 4
Could you please provide any method to debug this? We have sling:osgiconfig under the /apps/*/config folder but component never recognize these properties. Please note that when we explicitly open the config, it populates with the sling:osgiconfig correctly and when we save it gets bound. Problem only happens when the bundle starts up, at that point component never finds the config and goes into "no config" state. Please advise and help

Avatar

Community Advisor

probably you should check activate and modified annotations

 

@activate
@Modified
    protected void activate(final Config config) {
        myParameter = config.myParameter();
    }

 

Other example you can find on https://github.com/adobe/aem-guides-wknd/blob/archetype-18.1/ui.apps/src/main/content/jcr_root/apps/...



Arun Patidar

Avatar

Level 4
We have kept OCD as blank ... and we expecting we shall get sling:OSGIconfig values in our component .. but component always gets blank OCD....

Avatar

Level 4
We have environment specific sling:osgiconfig values and we want component OCD to populate from them. But on component activation we always get blank OCD.

Avatar

Level 4
is there a way we can achieve this in OSGI r7 annotation

Avatar

Community Advisor
It should work as component is calling activate method when component is geeting activated and when value is modifed. Did you try restarting component just to check if issue is with first time deployment?


Arun Patidar

Avatar

Level 4
In your SimpleScheduledTask.java .... can you load properties from sling:osgiconfig ?? if yes can you share your config package as well ??

Avatar

Community Advisor

hi, You can check examples from https://github.com/Adobe-Consulting-Services/acs-aem-commons/tree/master/ui.apps/src/main/content/jc...

I don't have any now but I will setup a package and share with you.



Arun Patidar

Avatar

Level 4
ok ... these are config files rather xml for sling:osgiconfig

Avatar

Level 4
is there a difference between config files and sling:osgiconfig when dealing with configadmin

Avatar

Community Advisor
config files are created when you update osgi config from web console


Arun Patidar

Avatar

Level 4
just one question when you start the bundle without configuring the component through webconsole, do you get your xml configured properties in this method public void activate(PageJSONServletConfig config) { excludeProperties=config.exclude_properties(); refrenceProperties = config.refrence_properties(); renameProperties = config.rename_properties(); limit= config.limit(); }