0
votes

I am trying to implement the example

https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

but in the following code

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null); session = resourceResolver.adaptTo(Session.class);

resourceResolver.adaptTo returns null everytime

Any help is appreciated.Thanks in advance.

1
AEM6 provide the subservices concept to get the session. Here did you find what exactly resolverFactory returns? - Vivek Dhiman
Thanks Vivek.It returns a JCRResource resolver. - user1904
What is the package imported for Session ? - Sharath Madappa
it imports javax.jcr.Session; - user1904
@user1904 any reason for using getAdministrativeResourceResolver() ? It is deprecated by now. Are you using an old API? - santiagozky

1 Answers

1
votes

Please check whether your resolverFactory is returning an object. If not, session will always be null. If you have not made use of @Reference annotation to get resolverFactory reference, please make use of it and see if it returns the resolverFactory,reference as follows:

@Reference private ResourceResolverFactory resolverFactory;

If your using a HttpSlingServlet , then we can get the session using sling request as shown below. SlingHttpServletRequest.getResourceResolver() method For reference you can follow the below api.

https://sling.apache.org/apidocs/sling5/org/apache/sling/api/resource/ResourceResolver.html

This might be the solution. If it doesn't work, Can you please share the entire code so that it is easy to track the exact reason why it is returning null value.