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.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.