Injector returning OnDemandReaderRequest adaptable object everytime | Community
Skip to main content
Naga_Seran
Level 2
May 8, 2018 1:22 PM UTC
Solved

Injector returning OnDemandReaderRequest adaptable object everytime

Hi Team,

We are in process of upgrading our application from AEM 6.1 version to 6.3 version.Our application using injector, to inject custom object data into our homepage.We found that after AEM 6.3,OnDemandReaderRequest adapatable object is returning everytime, rather than resource object. Please find below our homepage injector class

@Component

@Service

@Property(name = Constants.SERVICE_RANKING, intValue = 1000)

public class HomePageInjector extends AbstractInjector implements Injector {

    @Override

    public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement annotatedElement, DisposalCallbackRegistry disposalCallbackRegistry) {

if (adaptable instanceof Resource) {

            System.out.println("resource");

        } else {

            System.out.println(adaptable.adaptable.getClass().toString());

        }

}

AEM 6.1 Ouput:

resource

AEM6.3 output:

org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest.

Please help

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Peter_Puzanovs
Peter_PuzanovsAccepted solution
New Participant
May 8, 2018 2:09 PM UTC

Dear Naga,

You should be able to check whether adaptable is Resource or in your case OnDemandReaderRequest[1] which essentially is a SlingHttpServletRequest that can be adapted to Resource, therefore, your standard logic for resource should still work.

E.g.:

if(adaptable instanceof Resource || adaptable instanceof SlingHttpServletRequest)

GC: OnDemandReaderRequest - org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest (.java) - GrepCode Class S…

Regards,

Peter

4 replies

krishna_sai
New Participant
May 16, 2022 8:38 AM UTC

Hi @peter_puzanovs @smacdonald2008 I am facing the similar issue. In my sling model I have adaptable as SlingHttpServletRequest.class and @SlingObject SlingHttpServletRequest request object . but I am getting request as org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest instead of org.apache.sling.api.SlingHttpServletRequest.

Could you please help me here if what I am doing wrong. Thanks for the help

Translate
smacdonald2008
Level 10
May 8, 2018 2:45 PM UTC

NIce answer!

Translate
Peter_Puzanovs
Peter_PuzanovsAccepted solution
New Participant
May 8, 2018 2:09 PM UTC

Dear Naga,

You should be able to check whether adaptable is Resource or in your case OnDemandReaderRequest[1] which essentially is a SlingHttpServletRequest that can be adapted to Resource, therefore, your standard logic for resource should still work.

E.g.:

if(adaptable instanceof Resource || adaptable instanceof SlingHttpServletRequest)

GC: OnDemandReaderRequest - org.apache.sling.scripting.core.impl.helper.OnDemandReaderRequest (.java) - GrepCode Class S…

Regards,

Peter

Translate
Peter_Puzanovs
New Participant
May 8, 2018 2:05 PM UTC

Dear Naga,

You should be able to check whether adaptable is Resource or in your case OnDemandReaderRequest which essentially is a request that can be adapted to Resource, therefore, your standard logic for resource should still work.

Regards,

Peter

Translate