Reputation: 213
Perhaps I've misunderstood what the annotations are for in a Sling servlet or what they control.
I have a servlet defined with the following:
@Component(immediate = true, metatype = false, label = "File Processor Servlet")
@Service(serviceFactory = false, value = javax.servlet.Servlet.class)
@Properties(value = {
@org.apache.felix.scr.annotations.Property(name = "sling.servlet.methods", value = { "GET" }),
@org.apache.felix.scr.annotations.Property(name = "sling.servlet.extensions", value = { "json" }),
@org.apache.felix.scr.annotations.Property(name = "sling.servlet.paths", value = { "/bin/FileProcessor" })
Now this can be deployed and works fine (I'm using a CQ5.3 environment btw), which is good and everyone is happy.
However it was only when I was taking someone through my code that I realised I'd implemented the doDelete()
method which also works fine, but as you can see, I have not declared it as a method in the sling.servlet.methods
property in the annotations.
I had assumed that the omission of DELETE as a method in the annotations would have caused problems and the servlet would be blocked from handling it.
Have I missed the point of these annotations?
Cheers.
Upvotes: 2
Views: 1268
Reputation: 9281
The sling.servlet.resourceTypes
, sling.servlet.selectors
, sling.servlet.extensions
and the sling.servlet.methods
values are valid only if the sling.servlet.paths property is not set. If the paths property is set then all the others are ignored.
Quoting from the sling docs.
sling.servlet.methods - The request methods supported by the servlet. The property value must either be a single String, an array of Strings or a Vector of Strings. This property is ignored if the sling.servlet.paths property is set. If this property is missing, the value defaults to GET, regardless of which methods are actually implemented/handled by the servlet.
Refer the Sling Engine Documentation for more info.
Edit Including @BertrandDelacretaz comments:
And BTW registering servlets on paths is not recommended in Sling, quoting the same docs "Creating a resource at the desired path, with a resource type that maps to a servlet, provides the same result in most cases while taking advantage of more Sling built-in features". Features like access control for example.
Upvotes: 3