Where to put config files - the missing piece.

Avatar

Avatar

TB3dock

Avatar

TB3dock

TB3dock

07-04-2021

This post shows how to create an OSGi service in Java (which we assume is the only way) which creates and uses some configuration parameters which can be edited in the configMgr

 

However, this is useless without the ability to distribute pre-set parameters for the various run modes as part of our code deployment.

 

AEM documentation seems to be lacking info on this subject, it only has info on configuration on the actual running servers themselves and talks about config under /apps/.

 

If we look at the wknd project, it seems to be putting config files in:

 

ui.config/src/main/content/jcr_root/apps/wknd/osgiconfig/*

 

These files have a strange naming convention, e.g. e.g. com.adobe.aem.graphql.sites.adapters.SlingSchemaServlet~wknd-graphql.cfg.json

 

Are these files, their location, naming and content structure documented?

 

We have created a new osgi service (just to read config params) called say MyService with the following path: /aem-guides-wknd.core/src/main/java/com/adobe/aem/guides/wknd/core/services/MyService.java

 

What should the corresponding config file be called, and where should it be located?  How do we link our services config params to the config file?

 

=== UPDATE === 

 

@asutosh_jena kindly replied that I should put xml files under:

 

/apps/wknd/runmodes/config.dev

 

This sums up the discrepancy and why I am posting here: things like /apps/wknd/runmodes does not exist, nor anything like it, in the source code for wknd.

 

This is the wknd source code file structure:

 

TB3dock_0-1617866972618.png

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

markus_bulla_adobe

Employee

Avatar

markus_bulla_adobe

Employee

markus_bulla_adobe
Employee

08-04-2021

Not sure if you have already seen my explanations on this topic in your other thread.

 

The ui.config Maven module is a dedicated place to hold the OSGI configurations that you want to distribute. The structure of the module follows some conventions:

Everything up to (and including) the “jcr_content” folder is part of the Maven module structure (same as with “regular” Java modules holding all packages within the /src/main/java structure). Everything inside the “jcr_content” folder reflects the structure and hierarchy that will be created by the CRX package that the Maven module creates at build time.

Inside the repository all your project specific application code (including OSGI configs) should reside in the “/apps” tree. You will usually create your own folder (e. g. /apps/mysite) that holds all your templates, components, OSGI configs and more.

With regards to the OSGI configs, I have already outlined the naming convention of their respective folders (usually “config” or “config.RUNMODE”). Inside that/these folder/s you can create your OSGI configuration files. These files have to reflect the OSGI bundles PID (basically: fully qualified class name). So an according filename for your MyService class would be “com.adobe.aem.guides.wknd.core.services.MyService.cfg.json”.

Once you deploy your package (which will include the OSGI bundle at /apps/mysite/install/ and your OSGI config at /apps/mysite/config/) everything should be set. AEM will take care if deploying the OSGI bundle from the “install” folder to the OSGI context and apply the according config from the “config” folder. There is nothing more to do.

 

Recapitulating your specific questions:

  • Are these files, their location, naming and content structure documented? ==> Unfortunately, I’m not aware of a documentation covering this topic from this angle.
  • What should the corresponding config file be called? ==> com.adobe.aem.guides.wknd.core.services.MyService.cfg.json (reflecting yourn services PID aka fully qulified class name)
  • Where should it be located?  ==> ui.config/src/main/content/jcr_root/apps/mysite/config/ (will be mapped to /apps/mysite/config/ inside the repository)
  • How do we link our services config params to the config file? ==> That’s handled automatically, just follow the above naming conventions (config file name = PID of OSGI service). The parameter names inside the config file need to match your definition in your service class.

 

Hope that helps.

Answers (1)

Answers (1)

Avatar

Avatar

asutosh_jena

Avatar

asutosh_jena

asutosh_jena

08-04-2021

Hi @TB3dock 

 

If you OSGi Service interface is within

/aem-guides-wknd.core/src/main/java/com/adobe/aem/guides/wknd/core/services/ folder and the interface name is MyService.java

then you must have an Implementation class implementing the above interface which I believe you would have kept under 

/aem-guides-wknd.core/src/main/java/com/adobe/aem/guides/wknd/core/services/impl with class name MyServiceImpl.java

 

If the above statements are true, then your config file will be kept under:

/apps/wknd/runmodes/config path with file name as:

com.adobe.aem.guides.wknd.core.services.imp.MyServiceImpl.xml (it will be full qualified name of the class with .xml as the extension for AEM 6.5 and for cloud service it will be .cfg.json with will be a JSON file)

 

Please see the sample OSGI XML file:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
siteKey="somevalue"
secretKey="somevalue"
validationEndpoint="https://www.google.com/recaptcha/api/siteverify"
scriptURL="https://www.google.com/recaptcha/api.js"/>

Highlighted keys will be the variable name those are defined inside the interface which will be mapped against your configuration.

 

Now for run mode specific you can keep the same .xml file under:

/apps/wknd/runmodes/config.dev

/apps/wknd/runmodes/config.qa

/apps/wknd/runmodes/config.uat

 

with different values based on the run mode.

 

asutosh_j3_0-1617866504875.png

 

 

Thanks!