Processing Sling Request without the "sling.servlet.selectors" | Community
Skip to main content
Peter_Puzanovs
Community Advisor
Community Advisor
October 16, 2015
Solved

Processing Sling Request without the "sling.servlet.selectors"

  • October 16, 2015
  • 2 replies
  • 1907 views

Hi,

I want to process Servlet without the "sling.servlet.selectors", e.g. process the request with an empty selector.

Here is my current code that works with selector.

@Component(immediate = true, metatype = false) @Service(value = javax.servlet.Servlet.class) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Test"), @Property(name = Constants.SERVICE_VENDOR, value = OsgiServiceProperties.SERVICE_VENDOR), @Property(name = "sling.servlet.methods", value = {"GET" }), @Property(name = "sling.servlet.extensions", value = { "xml" }), @Property(name = "sling.servlet.selectors", value = { "foo" }) }) public class TestServlet extends PageServlet { // PageServlet == SlingSafeMethodsServlet with some improvements ... @Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.getWriter().print("I have been invoked.."); } }


Works fine but, when I remove the @Property(name = "sling.servlet.selectors", value = { "foo" }) the Servlet stops working. What property/setting should I use to process empty selector ?

 

Thanks in advance,

Peter

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

Hi, according to the documentation @ http://sling.apache.org/documentation/the-sling-engine/servlets.html

try to set either the path or the resourceType property. As i understand it you need to have something set for the servlet not to be ignored. 
https://blogs.adobe.com/aaa/2012/09/cq-tips-and-tricks-1-how-to-define-a-slingservlet-cq5-5-5-6.html
Once you set it to either, path resourceType or selector I'm quite sure that it will work :) As

/Johan

2 replies

Daniel_Gordon
Adobe Employee
Adobe Employee
October 16, 2015

You can use sling.servlet.paths to list an absolute path(s) that your servlet will be accessible: http://sling.apache.org/documentation/the-sling-engine/servlets.html, note that setting this property means that all other properties will be ignored...

Ojjis
OjjisAccepted solution
Level 7
October 16, 2015

Hi, according to the documentation @ http://sling.apache.org/documentation/the-sling-engine/servlets.html

try to set either the path or the resourceType property. As i understand it you need to have something set for the servlet not to be ignored. 
https://blogs.adobe.com/aaa/2012/09/cq-tips-and-tricks-1-how-to-define-a-slingservlet-cq5-5-5-6.html
Once you set it to either, path resourceType or selector I'm quite sure that it will work :) As

/Johan