Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

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

Avatar

Level 2

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.resourceresolver.PNG

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

sanjanas3080058_0-1624355986754.png

 

Any help will be appreciated.

Thanks,

Sanjana

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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-st...

View solution in original post

7 Replies

Avatar

Community Advisor

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!

Avatar

Community Advisor

@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?la...

 

Avatar

Level 2
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.

Avatar

Correct answer by
Community Advisor

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-st...

Avatar

Level 2

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.

Avatar

Community Advisor

Hi @sanjanas3080058,

Thanks for the inputs.

Is it possible for you to provide details on

  • Conditions that we are trying to check in Lambda function.
  • And this flow from S3 to AEM is a one time activity? 
  • AEM version. Do you foresee use of AEMasCS in future?

Avatar

Level 4

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.