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 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 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.
To watch the video, click:
Join the Adobe Experience Cloud Community
Join the Adobe Experience Cloud Community by clicking this banner
I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.
Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.
YouTube: Subscribe to the AEM Community Channel.
Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.