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

Avatar

Avatar
Validate 1
Level 1
sanjanas3080058
Level 1

Likes

0 likes

Total Posts

7 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
sanjanas3080058
Level 1

Likes

0 likes

Total Posts

7 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
sanjanas3080058
Level 1

22-06-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

573 likes

Total Posts

728 posts

Correct reply

240 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

573 likes

Total Posts

728 posts

Correct reply

240 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

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

Answers (3)

Answers (3)

Avatar

Avatar
Give Back 5
Level 4
SameerBhalerao
Level 4

Likes

35 likes

Total Posts

30 posts

Correct reply

16 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Give Back 5
Level 4
SameerBhalerao
Level 4

Likes

35 likes

Total Posts

30 posts

Correct reply

16 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 5
Boost 3
View profile
SameerBhalerao
Level 4

22-06-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.

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

607 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

22-06-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?la...

 

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

22-06-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!