Expand my Community achievements bar.

SOLVED

Sling filter - restricting scope based on path and resource types

Avatar

Level 3

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,

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

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.

View solution in original post

3 Replies

Avatar

Level 1

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 {

 

 

Avatar

Level 2

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.

Avatar

Correct answer by
Level 2

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.