Expand my Community achievements bar.

SOLVED

Sling Component resource resolver returns null for custom folder

Avatar

Level 2

Hello,

 

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

The code looks like the following:

pilmenkov_0-1674239178843.png

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

Thanks

View solution in original post

5 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Community Advisor

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

 

Thanks

Avatar

Level 4

Hi @pilmenkov y

 

@reference
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!

Avatar

Level 2

 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)

Avatar

Level 4

yes correct, it was ResourceResolverFactory. I misspelled it.