Hi All
I am trying to understand something. I am writing a servlet for a page resourceType something like below. Now as you can see, my extension is "txt". But when I call the page from my browser , if we follow the sling principles , my servlet has to be invoked when I call the page path with .txt , but it gets invoked only if I call it will .html .
For e.g ,
1. I created a sample project with latest archetype.
2. In that the we have an OOTB sample servlet like below
3. Now run and deploy this servlet and try to invoke this servlet. If you hit the page with http://localhost:4502/content/demo-training/us/en/test-page.txt (as per the servlet , the page component invoked using .txt extension ) ; then it will give you an error page something like below .
When you check the request call , you can see that extension is "txt" but it is not invoking your servlet , but the default servlet
4. Now try to hit the URL as http://localhost:4510/content/demo-training/us/en/test-page.txt.html . This will actually invoke the servlet.
When you check the request call , you can see that extension is "html" and "txt" is a selector; but it is invoking your servlet .
First it calls the /libs/Page/Page.jsp to add jcr:content to the request and then actually resolves to find the servlet we registered for "txt" extension.
URI=/content/demo-training/us/en/test-page.txt.html handled by Servlet=/libs/cq/Page/Page.jsp
If you scroll down you will see this is then calling our servlet with below information. The request says it has "html" as extension and "txt" as selector.
63156 LOG Including resource JcrNodeResource, type=demo-training/components/page, superType=null, path=/content/demo-training/us/en/test-page/jcr:content (SlingRequestPathInfo: path='/content/demo-training/us/en/test-page/jcr:content', selectorString='txt', extension='html', suffix='null') 63159 TIMER_START{resolveServlet(/content/demo-training/us/en/test-page/jcr:content)} 63995 TIMER_END{835,resolveServlet(/content/demo-training/us/en/test-page/jcr:content)} Using servlet com.xxx.training.core.servlets.SimpleServlet
If I register a similar servlet for a component (not page rendering component) it works as expected .
What I want to understand is , why the behavior is different for only page components. It do not justify the servlet registration. If I am registering a servlet for .txt as extension , why I need to add .html before each request to invoke the servlet ?
Any help is appreciated
Thanks
Veena ✌
Solved! Go to Solution.
Views
Replies
Total Likes
Call it using http://localhost:4502/content/demo-training/us/en/test-page/_jcr_content.txt
You will have your answer
or register the servlet using resourcTypes=cq/Page then call it using http://localhost:4502/content/demo-training/us/en/test-page.txt
Call it using http://localhost:4502/content/demo-training/us/en/test-page/_jcr_content.txt
You will have your answer
or register the servlet using resourcTypes=cq/Page then call it using http://localhost:4502/content/demo-training/us/en/test-page.txt
If we use resourceTypes = cq/Page, then servlet will be called using any page path right? its not specific to page component. is my understanding right?
@arunpatidar is correct. I explained the details why this is working in exactly that way in https://cqdump.joerghoh.de/2019/01/07/how-does-sling-resolve-an-aem-page-to-the-correct-resource-typ...
Yeah @Jörg_Hoh I have referred that post and it makes sense now. Thanks @arunpatidar and @Jörg_Hoh
Views
Like
Replies