Sling filter - restricting scope based on path and resource types

Aryan12345

16-12-2019

Hello,

 

Is it even possible to restrict sing filters based servlet paths or resource types? I tried those properties but no use. Every filter gets called for every request. sling.filter.pattern or sling.filter.pattern or sling.filter.resourceTypes does not seem to work. Am i doing something wrong?

 

THanks,

 

Accepted Solutions (1)

Accepted Solutions (1)

Basavaraj_K

17-12-2019

You can restrict request scope by the below filter patterns.

@component(service = { Filter.class },immediate = true, property = {
"osgi.http.whiteboard.filter.pattern=/content/*",
"osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=*)",
"osgi.http.whiteboard.context.path=/content",
"osgi.http.whiteboard.servlet.pattern=/content/*",
})

You can try out the above filter annotations.

Answers (1)

Answers (1)

alessandrod5385

16-12-2019

Hi, maybe you can try with this. these are properties of a servlet restricted for a specific resource type, on get method, with xml extension and a selector.

I use these for define a sitemap servlet on the homepage. (same as you can do with acs commons).

 

@Component(service = { Servlet.class }, property = {
"sling.servlet.resourceTypes=" + "fs_news/components/structure/hp_page", "sling.servlet.methods=" + "GET",
"sling.servlet.extensions=" + "xml", "sling.servlet.metatype=" + "true",
"sling.servlet.selector=" + "sitemap",
})

And this is the get method override:

@Override
protected void doGet(SlingHttpServletRequest slingRequest, SlingHttpServletResponse slingResponse)
throws ServletException, IOException {