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
Solved! Go to Solution.
Views
Replies
Total Likes
@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.
https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6
@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.
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?
@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.
https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6
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.