Hi,
Just want to understand the diffrence between the approach to get a JCR session like below:
Approach 1
ResourceResolver lResourceResolver = pResolverFactory.getAdministrativeResourceResolver(null);
Session lSession = lResourceResolver.adaptTo(Session.class);
Approach 2
Session lSession = repository.loginAdministrative(null);
Also, do we need to call session.logout() after I complete my work with session?
Solved! Go to Solution.
Views
Replies
Total Likes
See these community articles:
https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html
you use:
//Create a connection to the CQ repository running on local host
Repository repository = JcrUtils.getRepository("http://localhost:4503/crx/server");
//Create a Session
javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
when you are using an external Java app. For example - a Java Swing app.
If you are using the JCR API from within an OSGi bundle - you can use:
ResourceResolver lResourceResolver = pResolverFactory.getAdministrativeResourceResolver(null);
Session lSession = lResourceResolver.adaptTo(Session.class);
This article shows you how to do this:
http://scottsdigitalcommunity.blogspot.ca/2013/02/querying-adobe-experience-manager-data.html
But some ppl do not like using getAdministrativeResourceResolver().
Instead - they recommend that you create a dedicated user account, specify permissions using ACL, and use sling mapping.
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 article shows you how to do this:
http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html
When you close your session and you modified the JCR - use these methods:
session.save();
session.logout();
Views
Replies
Total Likes
Always try to avoid admin-sessions..., that is the first advice I would say.
And if you find a reason still to use it, then if you *create* the session, you need the close it. Same applies for the resourceResolver.
Views
Replies
Total Likes
Thanks for your reply. Can you please elaborate ?
Always try to avoid admin-sessions - which are admin sessions ? I just need to run some SQL2 statement ? What should be the preferred way?
What do you mean by *create* a session ? Please advise about session.logout() also
Views
Replies
Total Likes
Firstly..when you create a session that belongs to the admin user(repo.loginAdministrative or pResolverFactory.getAdministrativeResourceResolver)
Then it is admin sessions. This MUST NOT be done. Please follow the approach that scott has mentioned above if you need sessions. Secondly, slign apis provide all the necessary methods to create,modify and deleite nodes(resources). We should always prefer to use sling apis to jcr apis.
Views
Replies
Total Likes
See these community articles:
https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html
you use:
//Create a connection to the CQ repository running on local host
Repository repository = JcrUtils.getRepository("http://localhost:4503/crx/server");
//Create a Session
javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
when you are using an external Java app. For example - a Java Swing app.
If you are using the JCR API from within an OSGi bundle - you can use:
ResourceResolver lResourceResolver = pResolverFactory.getAdministrativeResourceResolver(null);
Session lSession = lResourceResolver.adaptTo(Session.class);
This article shows you how to do this:
http://scottsdigitalcommunity.blogspot.ca/2013/02/querying-adobe-experience-manager-data.html
But some ppl do not like using getAdministrativeResourceResolver().
Instead - they recommend that you create a dedicated user account, specify permissions using ACL, and use sling mapping.
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 article shows you how to do this:
http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html
When you close your session and you modified the JCR - use these methods:
session.save();
session.logout();
Views
Replies
Total Likes
Does the same work in AEM 6.1?
I'm seeing a Login Exception, with the following message:
LoginException. org.apache.sling.api.resource.LoginException: Cannot derive user name for bundle group.tti.commons-service [395] and sub service writeService
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies