Resource resolver can not locate configuration file | Community
Skip to main content
stiegjo22
Level 4
February 28, 2024
Solved

Resource resolver can not locate configuration file

  • February 28, 2024
  • 3 replies
  • 1265 views

I'm having a problem with the ResourceResolver locating a configuration xml file in my local author instance under apps. Despite attempting various approaches, such as specifying relative and absolute paths, the configResource continues to return null for the file resource. Also the ResourceResolver is using a AEM service user account to access the file. Here's the path for CONFIG_FILE_NAME - "/apps/site/config.author/com.mim.aem.core.service.validpaths.impl.ValidPathsServiceImpl.xml";

 

@9944223 public List<String> getValidPaths() { List<String> validPaths = new ArrayList<>(); try (ResourceResolver resourceResolver = ResourceResolverUtil.getResourceResolver(resolverFactory)) { Resource configResource = resourceResolver.getResource(CONFIG_FILE_NAME); if (configResource != null) { String xmlContent = configResource.getValueMap().get("jcr:content", String.class); ///XML logic here

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Harwinder-singh

@stiegjo22  Is there a specific reason why you want to access the content of a config file like this ?

Ideally, to access a config , you may want to create a object class definition (OCD) and access the properties inside the config file via a service implementation. 

More on this here - 

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-services/configurations-ocd.html?lang=en

https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6

 

3 replies

Imran Khan
Community Advisor
Community Advisor
February 28, 2024

@stiegjo22 Provide the read access to your system user to access config node as shown below:

/apps/practice/osgiconfig/config.author/com.day.cq.wcm.mobile.core.impl.TestProvider~practice.cfg.json

Resource resource = resourceResolver.getResource("/apps/practice/osgiconfig/config.author/com.day.cq.wcm.mobile.core.impl.MobileEmulatorProvider~practice.cfg.json");

Just curious to know the reason to read config file through Java in place of reading through OSGI component and services like below.

https://medium.com/@toimrank/aem-as-a-cloud-service-osgi-configuration-secret-and-environment-variables-667a0ddfb1d5 

SureshDhulipudi
Community Advisor
Community Advisor
February 28, 2024

as @imran__khan mentioned below - issue is with either Permission issue or Resource Resolver not initiated properly - can you debug the issue or print log statements to see the issue?

Harwinder-singh
Community Advisor
Harwinder-singhCommunity AdvisorAccepted solution
Community Advisor
February 28, 2024

@stiegjo22  Is there a specific reason why you want to access the content of a config file like this ?

Ideally, to access a config , you may want to create a object class definition (OCD) and access the properties inside the config file via a service implementation. 

More on this here - 

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-services/configurations-ocd.html?lang=en

https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6

 

stiegjo22
stiegjo22Author
Level 4
February 29, 2024

Thanks - I created an Object Class Definition (OCD) for a service that reads the values of DAM paths entered by a user into an OSGi configuration.