How to get resource resolver from session in Standalone Java Class outside AEM? | Community
Skip to main content
sanjanas3080058
Level 2
June 22, 2021
Solved

How to get resource resolver from session in Standalone Java Class outside AEM?

  • June 22, 2021
  • 4 replies
  • 6450 views

Hi All,

 

I am trying to get the session and resource resolver in a standalone Java code outside of AEM.

I am able to get the session but unable to get the resource resolver from the session.

Facing Null pointer exception.

 

Attaching screenshots for reference.

 getting below exception , please note that the session is not null.

 

Any help will be appreciated.

Thanks,

Sanjana

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vijayalakshmi_S

Hi @sanjanas3080058,

From the code snippet shared and name of Java class file(ImportAssetsToDam), could assume that are trying to Import Assets to DAM from Standalone Java code.

If it is for the reason of one time activity, you can make use of Groovy Scripts where accessing objects/APIs are ease or you can write a OSGI Servlet/ Service outside of project code base, so that same can be started/stopped independently. 

Please do share the reason/need for writing this as Standalone Java code. 

 

Accessing Sling Service APIs(ResourceResolverFactory) outside AEM is an overhead. Explanation justifying this on https://stackoverflow.com/questions/41708758/aem-sling-how-to-create-resourceresolverfactory-in-a-standalone-code

4 replies

Asutosh_Jena_
Community Advisor
Community Advisor
June 22, 2021

Hi @sanjanas3080058 

 

You should use the getServiceResourceResolver() to get the resource resolver from Resource Resolver Factory.

Here is the sample code to get the service resource resolver.

https://one-inside.com/aem6-resourceresolver-access-in-services/

 

Thanks!

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 22, 2021

@sanjanas3080058,

Can you let me know the use-case of why you might need the resource resolver from a non-AEM application? Because the javax.jcr.Session should allow CRUD (Create Read Update Delete) in your Java Content Repository.

Documentation here - https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/access-jcr.html?lang=en

 

sanjanas3080058
Level 2
June 23, 2021
Hi @briankasingli , I have referred the same documentation. As pointed out by @vijayalakshmi_s, I am trying to import the assets to AEM from S3 Bucket through AWS Lambda function and I was exploring if I can make use of Asset Manager API to import assets to DAM and for that I would need the resource resolver.
Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
June 22, 2021

Hi @sanjanas3080058,

From the code snippet shared and name of Java class file(ImportAssetsToDam), could assume that are trying to Import Assets to DAM from Standalone Java code.

If it is for the reason of one time activity, you can make use of Groovy Scripts where accessing objects/APIs are ease or you can write a OSGI Servlet/ Service outside of project code base, so that same can be started/stopped independently. 

Please do share the reason/need for writing this as Standalone Java code. 

 

Accessing Sling Service APIs(ResourceResolverFactory) outside AEM is an overhead. Explanation justifying this on https://stackoverflow.com/questions/41708758/aem-sling-how-to-create-resourceresolverfactory-in-a-standalone-code

sanjanas3080058
Level 2
June 23, 2021

Hi @vijayalakshmi_s,

 

Thanks for your reply. As you have rightly pointed out , I am trying to import the assets from S3 Bucket to AEM using a AWS lambda function.  I was trying to explore the Asset Manager API functionality to upload assets to DAM outside of AEM.  For this I would need the resource resolver to adapt to AssetManager class and hence was trying to fetch the resource resolver from the session.

Adobe Employee
June 22, 2021

Rightly pointed out by @briankasingli that it is supposed to be Jcr API so the concept of ResourceResolver is not applicable as it uses sling API which is higher abstract level. You need to use the node level operations using JCR node interface.