Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!

Fetching Cloud Configuration Returns Null in AEM Publish Instance

Avatar

Level 2

Hello Adobe Experience Manager Community,

I’m currently working on implementing a custom cloud service in AEM using the official documentation.

Progress so far:

  • I have successfully set up and stored the cloud configuration on the Author instance.
  • I can also configure my site with the cloud configuration on the Author instance without any issues.

Problem:

When I attempt to fetch the configuration on the Publish instance, it always returns null.

Code:-

 

HierarchyNodeInheritanceValueMap pageProperties1 = new HierarchyNodeInheritanceValueMap(resource);
String[] services = pageProperties1.getInherited("cq:cloudserviceconfigs", new String[]{});

// Fetch the DataReader service
final DataReader milestoneSchemaJSONReader = sling.getService(DataReader.class);

// Retrieve the ResourceResolver
ResourceResolver resolver = milestoneSchemaJSONReader.getResourceResolver();

// Adapt resolver to ConfigurationManager
ConfigurationManager cfgMgr = resolver.adaptTo(ConfigurationManager.class);

// Retrieve the configuration
Configuration cfg = cfgMgr.getConfiguration("milestoneschema", services);
if (cfg != null) {
    out.println("Configuration is available.");
} else {
    out.println("Configuration is null.");
    return;
}

 

 I also tried this approach:

 

String[] services = pageProperties.getInherited("cq:cloudserviceconfigs", new String[]{});
ConfigurationManager cfgMgr = resource.getResourceResolver().adaptTo(ConfigurationManager.class);

 


I have checked in crxde at that node properties are present. Please help with any solution.

7 Replies

Avatar

Level 9

Hi @manishkaith1,

I never used the ConfigurationManager class on my project, but I suspect the issue might be the resource resolver you are using to adapt to the ConfigurationManager.

If that resolver comes from the request then it's probably the anonymous user on the publisher with little permission. If you are not already using a service user try that and check the service user permissions on Publisher.

 

Good luck,

Daniel

Avatar

Level 2

Thanks Daniel for the reply.
I already have a system user which was created using the osgi config folder present in config module of aem archetype project.

org.apache.sling.jcr.repoinit.RepositoryInitializer~milestoneSchema.cfg.json

{
  "scripts": [
    "create path (sling:OrderedFolder) /content/dam/milestoneSchema",
    "create path (nt:unstructured) /content/dam/milestoneSchema/jcr:content",
    "set properties on /content/dam/milestoneSchema/jcr:content\n  set cq:conf{String} to /conf/milestoneSchema\n  set jcr:title{String} to \"Milestone Schema Connector\"\nend",
    "create service user aem-milestone-schema-service-user with forced path system/cq:services/milestoneschema",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read on /etc/cloudservices\nend",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read,jcr:lockManagement,jcr:versionManagement,rep:write,crx:replicate on /content\nend",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read,rep:write on /conf\nend"
  ]
}

org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~milestoneschema.cfg.json

{
  "user.mapping": [
    "com.milestone.schema.core:milestone-schema-service=[aem-milestone-schema-service-user]"
  ]
}


Also the resolver i use to get from data reader service.

public ResourceResolver getResourceResolver() throws LoginException {
        LOG.info("DataReader::getResourceResolver - Getting resource resolver...");
        Map<String, Object> param = new HashMap<>();
        param.put(ResourceResolverFactory.SUBSERVICE, "milestone-schema-service");
        ResourceResolver resolver = resolverFactory.getServiceResourceResolver(param);
        if (resolver != null) {
            LOG.info("DataReader::getResourceResolver - Resource resolver obtained successfully.");
        } else {
            LOG.error("DataReader::getResourceResolver - Failed to obtain resource resolver.");
        }
        return resolver;
    }



But still the config is null. Also all replication are done correctly on publish instance. I checked the same with elevated permission of repository.

Avatar

Community Advisor

@manishkaith1 

 

I have not used the API, but if its working on Author but not on publish, requesting you to assure following:

  • The Parent page where the configuration is done is replicated to publish.
  • The Cloud config that it uses is also replicated to publish.
  • Assure the session that uses that configuration has sufficient privileges to access the Cloud configs.

Aanchal Sikka

Avatar

Level 2

Thanks Aanchal for the reply.
I already have a system user which was created using the osgi config folder present in config module of aem archetype project.

org.apache.sling.jcr.repoinit.RepositoryInitializer~milestoneSchema.cfg.json

 

{
  "scripts": [
    "create path (sling:OrderedFolder) /content/dam/milestoneSchema",
    "create path (nt:unstructured) /content/dam/milestoneSchema/jcr:content",
    "set properties on /content/dam/milestoneSchema/jcr:content\n  set cq:conf{String} to /conf/milestoneSchema\n  set jcr:title{String} to \"Milestone Schema Connector\"\nend",
    "create service user aem-milestone-schema-service-user with forced path system/cq:services/milestoneschema",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read on /etc/cloudservices\nend",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read,jcr:lockManagement,jcr:versionManagement,rep:write,crx:replicate on /content\nend",
    "set ACL for aem-milestone-schema-service-user\n  allow jcr:read,rep:write on /conf\nend"
  ]
}

 

org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~milestoneschema.cfg.json

 

{
  "user.mapping": [
    "com.milestone.schema.core:milestone-schema-service=[aem-milestone-schema-service-user]"
  ]
}

 


Also the resolver i use to get from data reader service.

 

public ResourceResolver getResourceResolver() throws LoginException {
        LOG.info("DataReader::getResourceResolver - Getting resource resolver...");
        Map<String, Object> param = new HashMap<>();
        param.put(ResourceResolverFactory.SUBSERVICE, "milestone-schema-service");
        ResourceResolver resolver = resolverFactory.getServiceResourceResolver(param);
        if (resolver != null) {
            LOG.info("DataReader::getResourceResolver - Resource resolver obtained successfully.");
        } else {
            LOG.error("DataReader::getResourceResolver - Failed to obtain resource resolver.");
        }
        return resolver;
    }

 



But still the config is null. Also all replication are done correctly on publish instance. I checked the same with elevated permission of repository.

Avatar

Community Advisor

Hi @manishkaith1 

If it works on Author but not on Publish, the issue could be related to permissions or the configuration of the Publish environment.

Try accessing Publish locally using an admin account to see if it works. If it doesn't, deploy the cloud configuration using a package and check again.

 



Arun Patidar

Avatar

Administrator

@manishkaith1 Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni

Avatar

Level 2

Currently not found any solution for my Proble.
Do anyone have idea how can i access the same properties any other way.