Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Injector returning OnDemandReaderRequest adaptable object everytime

Naga_Seran
Level 2
Level 2

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

1 Accepted Solution
PuzanovsP
Correct answer by
Community Advisor
Community Advisor

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

Regards,

Peter

View solution in original post

3 Replies
PuzanovsP
Community Advisor
Community Advisor

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

PuzanovsP
Correct answer by
Community Advisor
Community Advisor

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

Regards,

Peter

View solution in original post