multiple servlets with same resource type | Community
Skip to main content
New Participant
June 21, 2023
Solved

multiple servlets with same resource type

  • June 21, 2023
  • 2 replies
  • 1418 views

hi all , 

suppose i have two servlets registered with the same ResourceType .so how will Resource type will select which servlet will serve the request . this is my interview question actully. please answer  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

Hello @shivanandh 

 

In Adobe Experience Manager (AEM), when you have multiple servlets registered with the same resource type, the selection of which servlet will serve the request depends on the OSGi service ranking 

OSGi service ranking is a property that can be set when registering a service in AEM. The servlet with the highest service ranking value will be selected to serve the request. 

For example, let's say you have two servlets registered with the same resource type:

Servlet A:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 100

 

Servlet B:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 200

 

In this case, Servlet B will be selected to serve the request because it has a higher service ranking value. 

2 replies

EstebanBustamante
New Participant
June 21, 2023

@aanchal-sikka is correct, I am just adding the source in case you want to learn more about it. Here https://sling.apache.org/documentation/the-sling-engine/servlets.html#servlet-resolution-order-1 

Esteban Bustamante
aanchal-sikka
aanchal-sikkaAccepted solution
New Participant
June 21, 2023

Hello @shivanandh 

 

In Adobe Experience Manager (AEM), when you have multiple servlets registered with the same resource type, the selection of which servlet will serve the request depends on the OSGi service ranking 

OSGi service ranking is a property that can be set when registering a service in AEM. The servlet with the highest service ranking value will be selected to serve the request. 

For example, let's say you have two servlets registered with the same resource type:

Servlet A:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 100

 

Servlet B:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 200

 

In this case, Servlet B will be selected to serve the request because it has a higher service ranking value. 

Aanchal Sikka
New Participant
June 21, 2023

Thanks @aanchal-sikka  for the answer