Hello Adobe Experience Manager Community,
I’m currently working on implementing a custom cloud service in AEM using the official documentation.
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.
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
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.
I have not used the API, but if its working on Author but not on publish, requesting you to assure following:
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.
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.
@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!
Views
Replies
Total Likes
Currently not found any solution for my Proble.
Do anyone have idea how can i access the same properties any other way.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies