Skip to main content

Sling Servlet 03: Servlet Resource Provider


Sling Servlets

Servlet Resource Provider

A service listener org.apache.sling.servlets.resolver.internal.SlingServletResolver listens for the OSGi services implementing javax.servlet.Servlet interface and registers its reference.

When a request hits the server, this SlingServletResolver kicks in to execute its sling script resolution procedure to choose the right servlet to respond to the request.

Each individual servlet will have a dedicated service instance of ServletResourceProvider associated with it, which will provide ServletResources in the resource tree, based on the servlet's registration properties.

The actual resource path of such resources differs for servlets registered by type and those registered by path:

Servlet registered by
Full Resource Path
Path
(given path).servlet
ResourceType
for each selector, extension and method combination one resource with path resource type[/[<selector with separator '/'>.][extension][method]].servlet'.
If multiple servlets are registered for the same metadata the one with the highest service ranking is returned in the virtual resource tree.

The resources expose the following properties:

Property Name
Description
sling:resourceType
The resource type to which the servlet is registered. Is equal to the absolute resource path.
sling:resourceSuperType
The resource super type. Is sling/bundle/resource if not explicitly set.
servletName
The name of the servlet.
servletClass
The fully-qualified class name of the underlying servlet.
In addition, each such resource can be adapted to a Servlet.

Reference: Servlets and Scripts

Conclusion

In this short theoretical post, we discussed the details of a Servlet Resource Provider. You can find the complete code on my GitHub.

I hope you enjoyed this post. Your suggestions and feedback are always welcome. Feel free to befriend me on FacebookTwitter or Linked In or say Hi by email.

Happy Learning 😊

Comments

Popular posts from this blog

Day 00: AEM Developer Series

Hello everyone! Welcome to this AEM development series. We can all see that the revolution of Digital Marketing today. Companies are dying to be a part of it and they have made this a war for the Digital Marketing tools.

Adobe was way ahead in this war and have gained a lot of market capture. They are leaders in the Digital Marketing platforms since the 2014-15. One of the flagship product in its Digital Marketing suite is Adobe Experience Manager (AEM).

Since AEM is in huge demand, the people who know how to develop on AEM are also in huge demand. But developing on AEM is not easy as it is made up of various open-source technologies such as Apache Felix (OSGi), Apache Sling, Apache Oak and Adobe's own technologies like Granite, HTL etc. Learning all these technologies in conjunction can sometimes become confusing and frustrating 😫.

When I first started learning AEM in 2016, I was dumbfounded to see there is so much going on under the hood. I then spent months to gather all the …

Day 01: Introduction to AEM

Day 04: Developing first OSGi bundle