April 14, 2020
Estimated Post Reading Time ~

Querying Adobe Experience Manager 6 data using the Sling getServiceResourceResolver method

You can create an Adobe Experience Manager (AEM) 6 application that queries data located in the AEM Java Content Repository (JCR). To query data, you use a javax.jcr.query.Query instance that belongs to the JCR Query API. This API supports both searching and querying operations. For example, assume that your AEM application tracks your organization’s customers. You can query the JCR to obtain a customer result set in which a digital marketer is interested.

As of AEM 6, you get a session instance (required to work with the JCR API) by using a Sling method named getServiceResourceResolver(). This new method replaces the use of the following API code:

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

The following code shows the use of the more secure getServiceResourceResolver API call.

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;

try {

//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
session = resolver.adaptTo(Session.class);

This code uses a specific AEM account with JCR to read and write privileges to access the AEM 6 JCR.

Note: As of AEM 6, the getAdministrativeResourceResolver method is deprecated.

This article creates the following AEM Query application.


To read this AEM 6 development article, click http://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.