Expand my Community achievements bar.

SOLVED

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

Avatar

Community Advisor

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

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

2 Replies

Avatar

Employee Advisor

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...

Avatar

Correct answer by
Level 7

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