user1904
user1904

Reputation: 1

JCR session created using ResourceResolver returns null

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.

Upvotes: 0

Views: 1454

Answers (1)

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.

Upvotes: 1

Related Questions