Expand my Community achievements bar.

SOLVED

Resource resolver can not locate configuration file

Avatar

Level 4

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";

 

 @Override
    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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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-servi...

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

 

View solution in original post

4 Replies

Avatar

Community Advisor

@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");

Imran__Khan_1-1709139832949.png

Imran__Khan_2-1709139950937.png

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-variab... 

Avatar

Community Advisor

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?

Avatar

Correct answer by
Community Advisor

@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-servi...

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

 

Avatar

Level 4

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.