AEM 6.4 unable to access content path via resourceresolver/session | Community
Skip to main content
Level 9
May 17, 2018
Solved

AEM 6.4 unable to access content path via resourceresolver/session

  • May 17, 2018
  • 31 replies
  • 14157 views

Hey Guys,

I am trying to access the path under content structure and i see that the code keeps complaining that path under /content does not exist.

i have a system user with permissions to /content folder and i am trying to get the resourceresolver via the java code and check if the node exists at the path. The output is that the node does not exist for any path under /content. is there something i am missing? I see that session.nodeExists works if i test for path under apps.

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 NitroHazeDev

Hi,

I had to alter the code discussing with Adobe

Try this:

Class extending WCMUsepojo

----------------

GetResourceResolverService getService = getSlingScriptHelper().getService(GetResourceResolverService.class);

if(getService ==null)

return;

resourceResolver= getService.getServiceResourceResolver("core-admin");// core-admin is the service name ,                                                                       //resourceResolverParams.put(ResourceResolverFactory.SUBSERVICE,"core-admin")

Resource resource = resourceResolver.resolve(resourcePath);

GetResourceResolverService  class

-----------------------------------------------

@component(name="",service=GetResourceResolverService  .class,immediate=true)

public class GetResourceResolverServiceImpl implements GetResourceResolverService {

@Reference

private ResourceResolverFactory resolverFactory;

private ResourceResolver resourceResolver;

@Override

public ResourceResolver getServiceResourceResolver(String subServiceName){

final Map<String,Object> serviceMap = new ConcurrentHashMap<>();

serviceMap.put(ResourceResolverFactory .SUBSERVICE,subServiceName);

try{

resourceResolver = resolverFactory.getServiceResourceResolver(serviceMap);

}catch(LoginException e)

}

}

31 replies

joerghoh
Adobe Employee
Adobe Employee
August 24, 2018

Can you please give more details? What path exactly is not working on publish? Do you have an exception you can share?

Jörg

NitroHazeDevAuthorAccepted solution
Level 9
August 24, 2018

Hi,

I had to alter the code discussing with Adobe

Try this:

Class extending WCMUsepojo

----------------

GetResourceResolverService getService = getSlingScriptHelper().getService(GetResourceResolverService.class);

if(getService ==null)

return;

resourceResolver= getService.getServiceResourceResolver("core-admin");// core-admin is the service name ,                                                                       //resourceResolverParams.put(ResourceResolverFactory.SUBSERVICE,"core-admin")

Resource resource = resourceResolver.resolve(resourcePath);

GetResourceResolverService  class

-----------------------------------------------

@component(name="",service=GetResourceResolverService  .class,immediate=true)

public class GetResourceResolverServiceImpl implements GetResourceResolverService {

@Reference

private ResourceResolverFactory resolverFactory;

private ResourceResolver resourceResolver;

@Override

public ResourceResolver getServiceResourceResolver(String subServiceName){

final Map<String,Object> serviceMap = new ConcurrentHashMap<>();

serviceMap.put(ResourceResolverFactory .SUBSERVICE,subServiceName);

try{

resourceResolver = resolverFactory.getServiceResourceResolver(serviceMap);

}catch(LoginException e)

}

}

Feike_Visser1
Adobe Employee
Adobe Employee
August 25, 2018

I would always AutoClosable when creating a new resolver / session: htl-examples/AutoCloseableService.java at master · heervisscher/htl-examples · GitHub

joerghoh
Adobe Employee
Adobe Employee
August 25, 2018

Still I don't understand why you need a session with more or different privileges when rendering a page.

Level 9
August 27, 2018

I was surprised .. and i knew editing permissions for sling scripting giving permissions to code under apps is not the right way , thanks to people to pointed out against it....So apparently in 6.2 sling scripting user with certain privileges were used to access classes that extend wcmuspojo, i raised a ticket with daycare and they suggested this which helped me resolve the issue. This is the solution they provided and it worked for me

Level 9
August 27, 2018

feike_visser​: i would definitely want to keep that in mind.. nice to know.. thank you so very much

Feike_Visser1
Adobe Employee
Adobe Employee
August 27, 2018

Still request.getResourceResolver() always has my preference

Level 2
August 27, 2018

It was null pointer error in publish environment on the same code in the author as it was not able to get resources at the location/child page.

it got fixed now as I have created a package of permissions and replicated on publish environment with "Merge" type.

but I am unable to understand how it was working in AEM6.2 but didn't work when we moved the code base from AEM6.2 to AEM6.4?

Feike_Visser1
Adobe Employee
Adobe Employee
August 27, 2018

most likely due to changed permissions between 6.2 and 6.4

Level 2
August 27, 2018

feike_visser

could you please explain what kind of permissions has been changed from AEM6.2 to AEM6.4 ?

Actually, We need to follow the same practice in Stage/PROD and we have too much content in PROD, it could be risky approach and may bring some issues in the live site.