Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
aanchal-sikka
aanchal-sikkaAccepted solution
Community Advisor
April 23, 2024

I am trying to access resource like below with resource reoslver
try
(ResourceResolver serviceResourceResolver = resourceResolverFactory.getServiceResourceResolver(null)) {

Resource resource = serviceResourceResolver.resolve(path);

}

i try to access resource.getPath() , getting the correct path, with the tag as

"NonExistingResource"

What will be the reason


@yugansan 

 

Requesting you to please go through the video that I had shared earlier. There would be a lot of blogs also available.

 

This code isn't right

resourceResolverFactory.getServiceResourceResolver(null)) {

 

As service use mapping needs to exist against the bundle/Service with proper privileges.

Aanchal Sikka

9 replies

aanchal-sikka
Community Advisor
Community Advisor
April 16, 2024

@yugansan 

 

  • Ideally one should create a Service and use it in the Listener.
    • Extract the required code in a common abstract class, which can be used by both Servlet and Service.
  • Do not execute heavy operations in listeners. Use Sling jobs instead 
Translate
Aanchal Sikka
RikVanB
Level 2
April 16, 2024

Hi @yugansan 
It's indeed like @aanchal-sikka is stating, the idea should be that your Servlet is using an underlying service which includes the logic that needs to be executed when calling your Servlet. If that is the case you could reuse the same service from your servlet into your ResourceChangeListener.

Greetings

Rik

Translate
YuganSanAuthor
Level 2
April 16, 2024

How we can call our service inside onchange method

myservlet.doSomething() (dosomething method i wrote inside the servelt as we cant able to call dopost method)

Translate
aanchal-sikka
Community Advisor
Community Advisor
April 16, 2024

@yugansan 

 

Please create a separate service and declare the doSomething() in the Service. 

 

The following video should help you with better understanding of Services.

https://www.youtube.com/watch?v=cPylQu6I7Q0&ab_channel=SankhamMarTechChannel

 

To consume the service use @Reference annotation. That is also described in video around 9:17. They have used service in servlet. We need to use the same concept and use Service inside ResourceChangeListener  ( no intermediate servlet involved)

 

 

Translate
Aanchal Sikka
EstebanBustamante
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
April 18, 2024

@yugansan Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Esteban Bustamante