Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Reading sling:OsgiConfig into @ObjectClassDefinition

Adilmo
Level 4
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
Arun_Patidar
Correct answer by
Community Advisor
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

View solution in original post

36 Replies
Shashi_Mulugu
Community Advisor
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

Adilmo
Level 4
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
Adilmo
Level 4
Level 4
The component remains in "no config" state even though there is sling:osgiconfig for the corresponding PID present in JCR ... kindly help
Adilmo
Level 4
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
Arun_Patidar
Correct answer by
Community Advisor
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

View solution in original post

Adilmo
Level 4
Level 4
Our problem is that we want to load the configuration values from sling:osgiconfig and not add them manually to through console.
Adilmo
Level 4
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
Arun_Patidar
Community Advisor
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/...

Adilmo
Level 4
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....
Adilmo
Level 4
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.
Adilmo
Level 4
Level 4
is there a way we can achieve this in OSGI r7 annotation
Arun_Patidar
Community Advisor
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?
Adilmo
Level 4
Level 4
In your SimpleScheduledTask.java .... can you load properties from sling:osgiconfig ?? if yes can you share your config package as well ??
Adilmo
Level 4
Level 4
ok ... these are config files rather xml for sling:osgiconfig
Adilmo
Level 4
Level 4
is there a difference between config files and sling:osgiconfig when dealing with configadmin
Arun_Patidar
Community Advisor
Community Advisor
config files are created when you update osgi config from web console
Adilmo
Level 4
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(); }