Apache Sling in AEM — Sling Architecture in AEM – Part 2
Understanding Sling Request Processing, Resource Resolution & Rendering Internals
Apache Sling in AEM — Sling Architecture in AEM – Part 2
Understanding Request Processing, Resource Resolution & Rendering Internals
Understanding Sling Architecture helps you:
✔ Debug production issues ✔ Understand rendering pipeline ✔ Improve performance ✔ Crack interviews confidently ✔ Understand AEM deeply
What is Sling Architecture?
- Apache Sling is built on a resource-driven architecture.
- Unlike traditional frameworks that process requests using controllers, Sling processes requests using:
Request → Resource → Script → Response
Sling Architecture
Browser Request
↓
Dispatcher / Web Server
↓
Sling Main Servlet
↓
Resource Resolver
↓
JCR Repository
↓
Resource
↓
Servlet / Script Resolution
↓
HTL / Servlet Execution
↓
HTML Response
📦
Core Components of Sling Architecture
1️⃣ Sling Engine
The Sling Engine is the core runtime that processes incoming HTTP requests.
It is responsible for:
✔ Receiving requests ✔ Resource resolution ✔ Script resolution ✔ Rendering response
Think of Sling Engine as:The “brain” of request processing.
2️⃣ Sling Main Servlet
This is one of the MOST important concepts.
What is Sling Main Servlet?
The Sling Main Servlet is the entry point for almost every request in AEM.
Every request goes through: org.apache.sling.engine.impl.SlingMainServlet
What Sling Main Servlet Does
When request comes:
/content/we-retail/us/en.html
Sling Main Servlet:
- Receives request
- Creates request object
- Calls ResourceResolver
- Finds resource
- Resolves script/servlet
- Generates response
Important Insight
Unlike Spring MVC: No explicit controller mapping needed
Instead: Sling dynamically resolves resources
Complete Request Lifecycle
This is the MOST important part of Sling architecture.
Step 1 — Browser Sends Request
Example:
/content/we-retail/us/en.html
Step 2 — Dispatcher/Web Server
Request first hits:
Apache Dispatcher
CDN/Web server
Dispatcher may:
✔ Serve cached page ✔ Forward request to AEM
Step 3 — Sling Main Servlet Receives Request
Sling Engine now starts processing.
Step 4 — Resource Resolution
This is where Sling becomes special.
What is Resource Resolution?
Resource Resolution is the process where Sling converts a URL into a repository resource.
Example
URL:
/content/we-retail/us/en.html
Resolved Resource:
/content/we-retail/us/en
Key Concept
Sling removes:
- extension (.html)
- selectors
- suffix and identifies actual resource path.
Resource Resolution Flow
URL
↓
ResourceResolver
↓
JCR Path
↓
Resource Object
What is ResourceResolver?
ResourceResolver is used to:
✔ Access resources ✔ Resolve paths ✔ Adapt resources ✔ Perform CRUD operations
Example
Resource resource = resolver.getResource("/content/we-retail/us/en");
ResourceResolver Internals
Internally it:
✔ Talks to JCR ✔ Maps virtual URLs ✔ Applies aliases/mappings ✔ Returns Resource objects
Resource Object
Once resolved:
/content/we-retail/us/en
becomes:
Resource resource
What Does Resource Contain?
A resource contains:
✔ Path ✔ Properties ✔ Resource type ✔ Child resources
Example Properties
jcr:title = "Home Page" sling:resourceType = "weretail/components/page"
Most Important Property
sling:resourceType
This tells Sling:bWhich component should render this content.
Step 5 — Servlet Resolution
Now Sling tries to determine:
Which servlet/script should handle the request.
Servlet Resolution
Sling checks:
✔ Resource type ✔ HTTP method ✔ Selectors ✔ Extension
Example
Resource type:
weretail/components/page
Sling searches for:
- Servlet
- HTL script
- JSP script
matching this resource type.
Servlet Resolution Order
Generally:
Servlets
↓
HTL Scripts
↓
JSP Scripts
Types of Servlets
1. Path-Based Servlet
@SlingServlet(paths="/bin/demo")
2. ResourceType-Based Servlet
@SlingServletResourceTypes( resourceTypes="myproject/components/page" )
Preferred in AEM.
Step 6 — Script Resolution
If no servlet handles request:
Sling searches for rendering scripts.
Script Resolution
Sling resolves scripts based on:
✔ Resource type ✔ Selectors ✔ Extension ✔ HTTP method
Example
Resource type:
myproject/components/page
Sling searches:
/apps/myproject/components/page/page.html
Script Resolution Hierarchy
Sling checks:
/apps ↓ /libs
Why?
Because:
/apps = custom overrides
/libs = Adobe default components
HTL Rendering Pipeline
Once script is found:
HTL rendering begins.
📍 Example
<h1>${properties.jcr:title}</h1>
HTL:
✔ Reads properties ✔ Executes expressions ✔ Generates HTML
Complete Rendering Pipeline
Request
↓
Resource Resolution
↓
Resource Type
↓
Script Resolution
↓
HTL Processing
↓
HTML Generation
↓
Response
Sling Engine Internals
🔹 URL Decomposition
Sling decomposes URL into:
/content/site/page.print.a4.html/suffix
Components
Part | Meaning
Path | /content/site/page
Selectors | print.a4
Extension | html
Suffix | /suffix
🔹 RequestPathInfo
Sling stores decomposed data inside:
request.getRequestPathInfo()
Example
requestPathInfo.getSelectors(); requestPathInfo.getExtension();
Resource Super Type
Sling supports inheritance.
Example
sling:resourceSuperType
Allows:
✔ Component inheritance ✔ Reuse of logic
Example
“myproject/components/custompage” inherits from “core/wcm/components/page/v3/page”
Real-World Example — Page Load
Now let’s trace a REAL request.
User Opens the below,
/content/we-retail/us/en.html
Internally What Happens?
Step 1 — Dispatcher
Checks cache.
If not cached: Sends request to AEM.
Step 2 — Sling Main Servlet
Receives request.
Step 3 — ResourceResolver
Resolves:
/content/we-retail/us/en
Step 4 — Resource Found
Properties:
sling:resourceType = weretail/components/page
Step 5 — Script Resolution
Sling searches:
/apps/weretail/components/page/page.html
Step 6 — HTL Executes
HTL loads:
- header
- footer
- container
- child components
Step 7 — Final HTML Generated
HTML returned to browser.
Debugging Scenario
Page returns 404-
Possible Reasons
✔ Resource missing ✔ Invalid mapping ✔ Permission issue ✔ ResourceResolver issue
Component not rendering- Possible Reasons
✔ Wrong sling:resourceType ✔ Missing HTL script ✔ Servlet conflict ✔ Invalid inheritance
Interview Questions & Answers
1. Explain Sling Request Flow
Request
↓
Sling Main Servlet
↓
Resource Resolution
↓
Servlet/Script Resolution
↓
HTL Rendering
↓
HTML Response
Sling converts URLs into resources and dynamically resolves components for rendering.
2. What happens internally when a page loads in AEM?
- Request hits Dispatcher
- Request forwarded to Sling
- Sling resolves resource
- Reads sling:resourceType
- Resolves matching servlet/script
- Executes HTL
- Generates HTML response
3. What is Resource Resolution?
The process of mapping a URL to a JCR resource.
4. What is Script Resolution?
The process of finding rendering scripts based on:
- resource type
- selectors
- extension
5. What is Sling Main Servlet?
The central servlet that handles all incoming requests in Sling.
6. What is ResourceResolver?
An API used to resolve and access resources from JCR.
7. Difference between Servlet Resolution and Script Resolution?
Servlet Resolution - Finds servlet class: Java-basedHTL
Script Resolution- Finds rendering script : JSP-based
8. What is sling:resourceType?
Defines which component/script should render the resource.
Tips (Real Project Experience)
✔ Always check sling:resourceType first during debugging ✔ Understand URL decomposition deeply ✔ Learn script resolution order ✔ Use ResourceResolver safely ✔ Avoid path-based servlets when possible
Key Takeaways
✔ Sling is resource-driven ✔ Every request goes through Sling Main Servlet ✔ URLs become resources ✔ Resources map to components ✔ HTL renders final HTML ✔ sling:resourceType is critical
Final Thoughts
Understanding Sling Architecture changes how you see AEM.
About Me
AEM Developer with 3+ years of experience building scalable applications. I share practical AEM and Java content to help developers grow faster.
Follow me for more AEM tutorials, real-world tips, and developer guides.
메타데이터
- post_id
- 6fa93e510b9f
- slug
- apache-sling-in-aem-sling-architecture-in-aem-part-2-6fa93e510b9f
- url
- https://medium.com/@swathikrishnamoorthi2001/apache-sling-in-aem-sling-architecture-in-aem-part-2-6fa93e510b9f
- canonical_url
- https://medium.com/@swathikrishnamoorthi2001/apache-sling-in-aem-sling-architecture-in-aem-part-2-6fa93e510b9f
- author_url
- https://medium.com/@swathikrishnamoorthi2001
- status
- ok
- fetched_at
- 2026-07-10 15:36:45