I'm using AEMaaCS. Created an OSGi config with config.author run mode. Deployed it. But while fetching its value, it is coming as null. What can be the issue?
If I'm making any change in crxde config file, it is not getting reflected on OSGi console configuration.
Also, warning signs are coming up against the values in the OSGi console.
I'm working in my local as of now.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @goyalkritika ,
According to my knowledge, the possible cases where you may experience this behavior:
1. When you created and deployed your service for the first time without any configuration, you opened the OSGi Configuration Console (http://localhost:4502/system/console/configMgr), where you wanted to test the configuration, and manually created (updated) the configuration. This way, the console created the configuration file automatically in the CRX folder /apps/system/config, so all new configurations for the same service are not getting processed because of the prevalence of configurations in /apps/system/config. To resolve this case, remove the configuration from that folder using CRX/DE and your config will start working.
2. When your configuration file name is not correct. By default, it must be a full reference to your impl class, in your case I think `com.cbdt.core.services.impl.SapDetailsConfigServiceImpl.cfg.json`
You can copy the correct PID from configMgr:
3. If your configuration file is not formatted correctly. To correctly format the configuration it's better to author it using the OSGi Configuration console, and then download the created configuration from your local AEM OSGi > OSGi Installer Configuration Printer (http://localhost:4502/system/console/osgi-installer-config-printer)
Just don't forget to remove the configuration /apps/system/config/com.cbdt.core.services.impl.SapDetailsConfigServiceImpl.cfg.json after you pasted it to your source codes (see #1)
4. Your META-INF/vault/filter.xml for the ui.config doesn't have an entry for your configurations, like this one below:
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/cbdt/osgiconfig"/>
</workspaceFilter>
Check that you have your configuration files in the CRX DE after the local deployment. It must be automatic though if you created the project using the AEM Maven archetype. Also, you may need to update your ui.apps.structure/pom.xml file to add your project's root, but again it must be there automatically if you used the maven archetype. Check maven build logs, package coverage in PackManager, and folders in CRX after the deployment.
5. Incorrect place (config folder) for the configuration. For example, you put your configuration to config.author.dev, and it should be in config for all servers, or config.author to take place on all author environments or, if I am not mistaken, you can put it into `aem.author.sdk` to make it work only on local SDK.
Also, why in your code this one is in lowercase? I suppose just mistyping bcz it won't work.
@activate
protected void activate(SapDetailsConfig sapDetailsConfig) ...
Also, the 'type=String' on configuration fields is by-default, you can omit those declarations if you want. And you have specified default values in your config - that's what will be filled in text boxes by default when you open configMgr, they are not required. If you want default values that will be used if there are no values in configuration, you can use the default operand after a function name, then you may have shorter configuration files:
String ecommerceBearerTokenUrl() default "https://some/default/url";
@goyalkritika can you ping here the file and the structure of your ui.config ?
package com.cbdt.core.services.impl;
import com.cbdt.core.services.SapDetailsConfigService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@Component(service = SapDetailsConfigService.class, immediate = true)
@Designate(ocd = SapDetailsConfigServiceImpl.SapDetailsConfig.class)
public class SapDetailsConfigServiceImpl implements SapDetailsConfigService {
private static final long serialVersionUID = -1449429375422119590L;
private String ecommerceEndpointUrl;
private String ecommerceBearerTokenUrl;
private String clientSecret;
private String grantType;
private String clientId;
@ObjectClassDefinition(name = "CBDT - SAP Configuration", description = "SAP Details")
public @interface SapDetailsConfig {
@AttributeDefinition(name = "Ecommerce Endpoint URL", description = "Commerce endpoint URL", type = AttributeType.STRING, defaultValue = "url")
String ecommerceEndpointUrl();
@AttributeDefinition(name = "Bearer Token URL", description = "Bearer Token URL", type = AttributeType.STRING, defaultValue = "default_url")
String ecommerceBearerTokenUrl();
@AttributeDefinition(name = "Client Secret", description = "Client Secret", type = AttributeType.STRING, defaultValue = "client_secret")
String clientSecret();
@AttributeDefinition(name = "Grant Type", description = "Grant Type", type = AttributeType.STRING, defaultValue = "grant_type")
String grantType();
@AttributeDefinition(name = "Client ID", description = "Client ID", type = AttributeType.STRING, defaultValue = "client_id")
String clientId();
}
@Override
public String getEcommerceEndpointUrl() {
return ecommerceEndpointUrl;
}
@Override
public String ecommerceBearerTokenUrl() {
return ecommerceBearerTokenUrl;
}
@Override
public String getClientSecret() {
return clientSecret;
}
@Override
public String getGrantType() {
return grantType;
}
@Override
public String getClientId() {
return clientId;
}
@activate
protected void activate(SapDetailsConfig sapDetailsConfig) {
ecommerceEndpointUrl = sapDetailsConfig.ecommerceEndpointUrl();
ecommerceBearerTokenUrl = sapDetailsConfig.ecommerceBearerTokenUrl();
clientId = sapDetailsConfig.clientId();
clientSecret = sapDetailsConfig.clientSecret();
grantType = sapDetailsConfig.grantType();
}
}
Hi @goyalkritika
Could you please share your config file "cfg.json" under your "config.author" run mode as well. That would be helpful to identify the root cause.
Just sharing a reference to official documentation here.
https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi...
// Configuration created by Apache Sling JCR Installer
{
"ecommerceEndpointUrl":"changed_url",
"ecommerceBearerEndpointUrl":"changed_url",
"clientId":"clientId",
"clientSecret":"clietSecret",
"grantType":"type"
}
I would start my debugging as below:
1) Check the filter.xml found under "META-INF" for ui.config module and make sure "/apps/cbdt/osgiconfig" path is set for the filter root paths.
2) GoTo OSGI system console bundles and open your core module OSGI bundle and go all the way down to "Declarative Service Component" and make user your service "SapDetailsConfig" is showing up as "state active". If this is not showing up as "active", I would check the logs while installing the bundle for any reference errors. Sometimes, even though the OSGI bundle itself is active, some of the services/components doesn't end up in active state due to various dependency reasons.
1. Checked -> It is fine.
2. All components are active.
Hi @goyalkritika ,
According to my knowledge, the possible cases where you may experience this behavior:
1. When you created and deployed your service for the first time without any configuration, you opened the OSGi Configuration Console (http://localhost:4502/system/console/configMgr), where you wanted to test the configuration, and manually created (updated) the configuration. This way, the console created the configuration file automatically in the CRX folder /apps/system/config, so all new configurations for the same service are not getting processed because of the prevalence of configurations in /apps/system/config. To resolve this case, remove the configuration from that folder using CRX/DE and your config will start working.
2. When your configuration file name is not correct. By default, it must be a full reference to your impl class, in your case I think `com.cbdt.core.services.impl.SapDetailsConfigServiceImpl.cfg.json`
You can copy the correct PID from configMgr:
3. If your configuration file is not formatted correctly. To correctly format the configuration it's better to author it using the OSGi Configuration console, and then download the created configuration from your local AEM OSGi > OSGi Installer Configuration Printer (http://localhost:4502/system/console/osgi-installer-config-printer)
Just don't forget to remove the configuration /apps/system/config/com.cbdt.core.services.impl.SapDetailsConfigServiceImpl.cfg.json after you pasted it to your source codes (see #1)
4. Your META-INF/vault/filter.xml for the ui.config doesn't have an entry for your configurations, like this one below:
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/cbdt/osgiconfig"/>
</workspaceFilter>
Check that you have your configuration files in the CRX DE after the local deployment. It must be automatic though if you created the project using the AEM Maven archetype. Also, you may need to update your ui.apps.structure/pom.xml file to add your project's root, but again it must be there automatically if you used the maven archetype. Check maven build logs, package coverage in PackManager, and folders in CRX after the deployment.
5. Incorrect place (config folder) for the configuration. For example, you put your configuration to config.author.dev, and it should be in config for all servers, or config.author to take place on all author environments or, if I am not mistaken, you can put it into `aem.author.sdk` to make it work only on local SDK.
Also, why in your code this one is in lowercase? I suppose just mistyping bcz it won't work.
@activate
protected void activate(SapDetailsConfig sapDetailsConfig) ...
Also, the 'type=String' on configuration fields is by-default, you can omit those declarations if you want. And you have specified default values in your config - that's what will be filled in text boxes by default when you open configMgr, they are not required. If you want default values that will be used if there are no values in configuration, you can use the default operand after a function name, then you may have shorter configuration files:
String ecommerceBearerTokenUrl() default "https://some/default/url";