1
votes

I am registering a Sling Servlet using

@Component(service=Servlet.class,
           property={
                   Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",
                   "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                   "sling.servlet.resourceTypes="+ "myapp/components/structure/page",
                   "sling.servlet.extensions=" + "json",
                   "sling.servlet.selectors=" + "myselector"
 })

But when calling URL <host:port>/content/myapp/en.myselector.js I get error

Invalid recursion selector value 'myselector'
Cannot serve request to /content/myapp/en.myselector.json in 
org.apache.sling.servlets.get.DefaultGetServlet

If we remove "sling.servlet.extensions=" + "json", from annotation, we are able to hit the servlet using <host:port>/content/myapp/en.myselector.js or <host:port>/content/myapp/en.myselector.html but not <host:port>/content/myapp/en.myselector.json

Any additional configurations required? or its conflicting with DefaultGetServlet? We were trying to expose JSON out of resource using servlet and JSON extension semantically making sense.

1
Did you try using <host:port>/content/myapp/en/_jcr_content.myselector.json. Since you are registering the servlet against the resource, the resource type for the page would in the jcr:content node and not on the page node itself. - rakhi4110
Thanks @rakhi4110, it works with jcr:content. I think when both selector and extension is there path till jcr:content is required, else if only selector is there it works without jcr:content for .js of .html. You can post answer, I can accept it. - Sandeep Kumar

1 Answers

4
votes

Since you've registered the servlet against the resource instead of a path, the resource is actually the jcr:content node of the page, rather than the page node itself.

Hence, the servlet should work when accessed with the jcr:content in the URL as shown below

<host:port>/content/myapp/en/_jcr_content.myselector.json