Showing posts with label JCR. Show all posts
Showing posts with label JCR. Show all posts

Monday, 14 August 2017

Sling Resource API vs JCR API - Performance

Check the article to compare the performance when using Sling Resource API and JCR API.

This article illustrates different tests performed to compare the performance of sling resource api and jcr api.

Test 1: Traversing /content/geometrixx tree
Result: JCR API is roughly twice as fast as the Sling API when traversing a tree.

Test 2: Creating simple pages (single save)
When creating a 1000 simple pages and saving them in one go, it takes respectively 0.20 and 0.26 ms for the JCR and Sling API to create a single page. Creating 1000 pages took 200 and 260 ms respectively for JCR and Sling in total.

Wednesday, 19 April 2017

Different ways to get AEM admin session

Method 1:

AEM admin session can be obtained using below method but this is deprecated

private SlingRepository repository;
adminSession = repository.loginAdministrative(null);

Method 2:

Another way to get the session (not the recommended way)
Session session = repository.login(new SimpleCredentials("admin",

Method 3:

 public ResourceResolverFactory rrFactory;

ResourceResolver adminResolver = rrFactory.getAdministrativeResourceResolver(null);        
Session adminSession = adminResolver.adaptTo(Session.class);

Method 4:

Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "jqom");
ResourceResolver resolver = null;          
        try {                     
            //Invoke the getServiceResourceResolver method to create a Session instance
            resolver = resolverFactory.getServiceResourceResolver(param);
            session = resolver.adaptTo(Session.class);

See Community Article

Method 5:

You can create a user and assign it to the administrative group and use it's credentials rather than the default admin user.
You may also want to take a look at this article which goes over using the correct resource resolver in AEM 6.

Saturday, 18 March 2017

OSGi Configuration via JCR Nodes

The reasons to configure OSGi services via content nodes is obvious:
  • Configurations are deployed with the code
  • Configurations can be transferred with content packages
  • Configurations can be managed with source control
Defining an OSGi configuration with content nodes is pretty simple:
You create a sling:Folder 'config' and add nodes below it of type sling:OsgiConfig. This node has to have the name of the persistence ID, usually that's the fully qualified class name of the service you want to configure, e.g.
Therefore, you can configure the service with an xml file in the folder /apps/yourproject/config with the name and the following content:
<?xml version="1.0" encoding="UTF-8">
versionmanager.purgingEnabled="{Boolean}true" />
You can add factory configurations (multiple settings for one configuration) by adding a unique identifier to the file name, separated by a hyphen. Setting up the MCM configuration e.g. can be done by providing a file named This will create a binding to the configuration.
Only one open topic remains: You usually have one code base, but multiple configuration according to the various systems: An integration test author system has different configurations compared to a production publish system. The instances can be distinguished by using different runmodes, and the configurations can be runmode specific as well:
Just add the name of the runmode the set of configurations apply to the config-folder, like '' or 'config.publish'. By this you can maintain all applicable configurations in the version control, deploy the code, activate the packages - and the instance itself picks the proper settings. Pretty neat, isn't it?

Thursday, 20 October 2016

Render custom metadata for Assets in AEM

Extend Asset List, Column, and Card view (for AEM 6.2)


Each view mode in the Adobe Experience Manager AEM Assets console displays a set of metadata based on the metadata schema associated with the assets.
However, you can display custom metadata in the List, Column, and Card view layouts by configuring existing metadata fields or adding fields using the Metadata Schema editor. The following sections describe how to extend the various layouts to render custom metadata.

Tuesday, 10 November 2015

What is a content repository? What is JCR?

A Content repository is basically a place where digital content is stored. Generally the structure of the content repository is hierarchial and represented as a tree structure where each node of the tree is used to store content. Java Content Repository is a specification provided by the java community to access the content repository in a uniform way (platform independent and vendor independent way). The specification was initially released as JSR-170(JCR 1.0) and then later revised version 2 as (JCR-283).
The javax.jcr API provides the various classes and interfaces to access a content repository
Apache Jackrabbit is an open-source implementation of JCR- 2.0 specification.
It provides some wrapper classes and interfaces specific to jackrabbit plus many more functionalities on top of jcr.

The org.apache.jackrabbit packages are used to access Jackrabbit.