When we go for Sling Servlet registered by Path, Resource Type? | Community
Skip to main content
siva_vjwd
Level 2
Feb 23, 2018 8:30 AM UTC

When we go for Sling Servlet registered by Path, Resource Type?

Hi All

           I'm new to this Sling Servlets, trying to registering a servlet by path, as well as registering a Servlet by Resource Type that is fine.. when we go for Path and When we go for a Resource Type. give me a explanation here

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

cquser1
Level 7
Feb 23, 2018 12:00 PM UTC

Binding servlets by paths has several disadvantages when compared to binding by resource types, namely:

  • path-bound servlets cannot be access controlled using the default JCR repository ACLs
  • path-bound servlets can only be registered to a path and not a resource type (i.e. no suffix handling)
  • if a path-bound servlet is not active, e.g. if the bundle is missing or not started, a POST might result in unexpected results. usually creating a node at /bin/xyz which subsequently overlays the servlets path binding
  • the mapping is not transparent to a developer looking just at the repository

Given these drawbacks it is strongly recommended to bind servlets to resource types rather than paths.

Translate
smacdonald2008
Level 10
Feb 23, 2018 3:47 PM UTC

Binding by path is useful when you want a non-resource to post data to it. For example, a Java client app that posts data to an AEM Sling Servlet. Say the path is  /bin/upfile.

String aemPostUrl = host+"/bin/upfile";

The above string would represent the URL to post to.

Here are the supported ways to register a servelt.

Apache Sling :: Servlets and Scripts

As you can see - both Resource types and Paths are supported. 

Translate
joerghoh
Employee
Feb 23, 2018 7:22 PM UTC

Sorry Scott,

but even in this case it makes sense to bind the servlet to a resource instead of a path. Because as already stated by cquser1​ you can apply ACLs on that; that means that you control if a certain user has the ability to post at all for free (that means with no coding) and configurable during runtime. You need a lot of coding if you want to implement this logic in your servlet :-)

Jörg

Translate
joerghoh
Employee
Feb 23, 2018 11:46 AM UTC

By default you should register Servlets via Resource Types. I don't know reasons to bypass this rule.

Jörg

Translate