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.
Solved! Go to Solution.
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)
}
}
Can you please give more details? What path exactly is not working on publish? Do you have an exception you can share?
Jörg
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)
}
}
I would always AutoClosable when creating a new resolver / session: htl-examples/AutoCloseableService.java at master · heervisscher/htl-examples · GitHub
Still I don't understand why you need a session with more or different privileges when rendering a page.
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
feike_visser: i would definitely want to keep that in mind.. nice to know.. thank you so very much
Still request.getResourceResolver() always has my preference
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?
most likely due to changed permissions between 6.2 and 6.4
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.
Hey,
I want to understand how this code is different than your old code.
Here you have a new class and method to get the resource resolver. But in the class, you are using resource resolver factory to get the resource resolve.
So logically whats the difference. I just want to understand that.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies