Sling Component resource resolver returns null for custom folder | Community
Skip to main content
Level 2
January 20, 2023
Solved

Sling Component resource resolver returns null for custom folder

  • January 20, 2023
  • 3 replies
  • 1966 views

Hello,

 

I have the problem with locating the folder as resource from Sling Component.

The code looks like the following:

The line 36 gives not null resource object but line 37 gives null.

 

The folder "/apps/sling" exists initially but "/apps/myfolder" was manually created in JCR Repository Browser.

I compared the properties and access rules of "/apps/sling" and "/apps/myfolder" and was unable to see any difference.

 

Could you please help me to understand why the custom folder is invisible for resource resolver and how to reach this folder properly during component activation?

 

Thanks,

Pavel

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 Asutosh_Jena_

Hi @pilmenkov 

 

You are not obtaining the correct resource resolver here.

Please use the system user to get the resource resolver and ensure you are giving access to the system user for the path you want to perform any operation here i.e. /apps/myfolder.

 

Please refer the link here.

https://rmengji.wordpress.com/2016/02/13/how-to-get-service-resource-resolver/#:~:text=Below%20steps%20will%20help%20you%20to%20get%20the%20resource%20resolver%20object.&text=Go%20to%20%2Fcrx%2Fexplorer%20and,the%20newly%20created%20%E2%80%9Cserviceuser%E2%80%9D.

 

Thanks

3 replies

Aditya_Chabuku
Community Advisor
Community Advisor
January 21, 2023

Hi @pilmenkov ,

 

Can you please explain a bit about how you are creating "/apps/myfolder" .? and how it was created?

Make sure it doesn't get into Race Condition.

 

Thanks,

Aditya Ch

Thanks,Aditya Chabuku
Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
January 21, 2023

Hi @pilmenkov 

 

You are not obtaining the correct resource resolver here.

Please use the system user to get the resource resolver and ensure you are giving access to the system user for the path you want to perform any operation here i.e. /apps/myfolder.

 

Please refer the link here.

https://rmengji.wordpress.com/2016/02/13/how-to-get-service-resource-resolver/#:~:text=Below%20steps%20will%20help%20you%20to%20get%20the%20resource%20resolver%20object.&text=Go%20to%20%2Fcrx%2Fexplorer%20and,the%20newly%20created%20%E2%80%9Cserviceuser%E2%80%9D.

 

Thanks

Shivam153
Level 3
January 21, 2023

Hi @pilmenkov y

 

@3214626
private ResourceResolverFactoryService resourceResolverFactoryService;

 

Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "label");
param.put(ResourceResolverFactory.USER, "serviceUser");
resolver = resourceResolverFactory.getServiceResourceResolver(param);

 

try this, Hope it will work!

pilmenkovAuthor
Level 2
January 23, 2023

 Shivam153, thank you for your example.

It works finally after setting up the system user as advised by 

 

(Please note that ResourceResolverFactoryService uses in your code example does not exist in sling libraries, at least I was not able to find it)

Shivam153
Level 3
January 23, 2023

yes correct, it was ResourceResolverFactory. I misspelled it.