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

Where to put config files - the missing piece.

TB3dock
Level 7
Level 7

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

 

1 Accepted Solution
markus_bulla_adobe
Correct answer by
Employee
Employee

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.

View solution in original post

10 Replies
asutosh_jena
Community Advisor
Community Advisor

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!

TB3dock
Level 7
Level 7
Hi, there such directory /apps/... anywhere in the wknd project source code. This is the problem.
asutosh_jena
Community Advisor
Community Advisor

Hi @TB3dock 

You can find it inside ui.config module in the code base. Please see below:

asutosh_j3_0-1617866798534.png

 

Thanks!

TB3dock
Level 7
Level 7
you have include a snippet of XML. there is no XML in the tutorial, and my service is picking up variables without it.
asutosh_jena
Community Advisor
Community Advisor
As I mentioned earlier it will pick XML and JSON. If you have not defined anything then it will pick the default value from the ServiceImpl class.
TB3dock
Level 7
Level 7
There is no "wknd", or "runmodes" dir in the source code that I can find. There is an i18n dir, but this is under ui.apps
asutosh_jena
Community Advisor
Community Advisor

@TB3dock  If you see the above screenshot, you can see osgiconfig folder which is what I was referring as runmodes.

Hope this is clear now.

 

Thanks!

markus_bulla_adobe
Correct answer by
Employee
Employee

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.

View solution in original post

TB3dock
Level 7
Level 7
This is a great explanation, thanks. Given the various tutorials dont cover this, and nor the docs, I wonder how everyone knows about it. Out of interest, are the contents of the config file (i.e. the json structure and options) documented?
markus_bulla_adobe
Employee
Employee
The content of the config json file needs to reflect the the properties that you define in your OSGI service. It's just a key-value-list of the parameters. You can double check on the required keys in the OSGI web console config manager UI by opening your service configuration. The key is always listed in brackets after the property description (below the input field). You'll also see the PID (required for the naming oif your file) in the dialog at the bottom.