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

OSGI configuration as JSON

Avatar

Level 4

Hi,

Is there any OOTB way to get OSGI configuration as JSON response ?

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

well any modification of an existing OSGI config get's saved to  /apps/system/config/. Change a config and check for yourself. The best way to deploy OSGI configurations is to create an appropriate runmode folder[1]

If this is on publish you won't have access to /apps, so best to write a servlet that reads the node and returns the json

Regards,

Opkar

[1] https://helpx.adobe.com/experience-manager/kb/RunModeDependentConfigAndInstall.html

[2] https://cqdump.wordpress.com/2015/04/21/aem-basics-runmodes/

View solution in original post

7 Replies

Avatar

Employee

Hi,

Are you looking for an OOTB OSGI config or a custom config? As custom configs get saved to the repository, at /apps/system/config/. Or if you include them in runmode folders, again you can access them. Not sure about the OOTB configs.

What are you trying to achieve?

Regards,

Opkar

Avatar

Level 10

You need to write a plugin & no option available OOB.  But you can get in AS IS format.  Does not sounds good you are trying to consume in java script. What is your usecase trying to solve 

Avatar

Employee Advisor

Hi,

IIRC the OSGI console offers no way to export a single configuration as JSON or XML. You could use [1] to get all configuration settings. But this always requires admin privileges (and direct access to the OSGI webconsole, which is locked down by the security list), so it isn't the way you should go.

Exporting the config directly from /apps/myapp/config.-1.json is also not the best idea, as you might not have created configuration settings for the services you are interested in. It also requires much privileges any standard user should have.

So I would think, that implementing this on your own is likely the best idea. You can use the OSGI config admin to access every configuration in the system (as long as you know the PID).

In every case you should think of the case, that you expose system configuration to a potenteially 3rd party user!

kind regards,
Jörg

 

[1] http://localhost:4502/system/console/status-Configurations.json

Avatar

Level 4

Hi Sham,

I need some custom osgi configuration to be consumed in javascript front end. What would be your suggestion ?

Also did not understand the 'AS IS format'. Can you please provide a little detail?

Avatar

Level 4

Hi Opkar,

It's custom config.Basically these custom configs will be consumed by Javascript. So, was thinking a JSON response will be easy to handle.

Please provide your thought

Avatar

Correct answer by
Employee

Hi,

well any modification of an existing OSGI config get's saved to  /apps/system/config/. Change a config and check for yourself. The best way to deploy OSGI configurations is to create an appropriate runmode folder[1]

If this is on publish you won't have access to /apps, so best to write a servlet that reads the node and returns the json

Regards,

Opkar

[1] https://helpx.adobe.com/experience-manager/kb/RunModeDependentConfigAndInstall.html

[2] https://cqdump.wordpress.com/2015/04/21/aem-basics-runmodes/

Avatar

Level 10

sumitc22 wrote...

Hi Sham,

I need some custom osgi configuration to be consumed in javascript front end. What would be your suggestion ?

Also did not understand the 'AS IS format'. Can you please provide a little detail?

 


Still your business case is not clear to me.  There are two way config is stored in repository once saving directly from felix console which is config so example you can access like [1] which gets name value pair seperated by line feed.  Another using content-nodes (sling:osgiConfig) in the repository example at [2] in which case you can access like [3] example [4] which is json format.   In any case both need authentication from java script.    If you are following the recommendation of content-nodes (sling:osgiConfig) then your question is answered to get json format otherwise you get as non json format.

Hope thing clarifies.

[1]  http://<host>:<port>/apps/system/config/org.apache.sling.security.impl.ReferrerFilter.config

[2]  https://docs.adobe.com/docs/en/cq/5-6-1/deploying/configuring_osgi.html#Adding%20a%20New%20Configura...

[3]    http://<host>:<port>/apps/<yourProject>/config/<pid>.json

[4]   http://<host>:<port>/apps/geometrixx-outdoors-app/config/com.day.cq.wcm.mobile.core.impl.MobileEmulatorProvider-topcoatconfig.json