CQ5.5 order standard HTTP filters deployed as OSGI

2019-09-06 14:06发布

In CQ5.5 How I can order 2 standard HTTP Filters deployed as OSGI components?

The issue is that the 2 filters have to run in order where FilterA should run first and then FilterB in sequence.

How I can order my 2 filters in sequence?

Do you know if there is any OSGI or SCR property with which I can order the 2 filter so that one should run after another?

For example:

Filter A

@Component
@Service
@org.apache.felix.scr.annotations.Properties({
@Property(name = "pattern", value = "/.*"),
@Property(name = Constants.SERVICE_RANKING, intValue = 99999, propertyPrivate = false)
})
public class FilterA implements implements javax.servlet.Filter {
}

FilterB

@Component
@Service
@org.apache.felix.scr.annotations.Properties({
@Property(name = "pattern", value = "/.*"),
@Property(name = Constants.SERVICE_RANKING, intValue = 100000, propertyPrivate = false)
})
public class FilterB implements implements javax.servlet.Filter {
}

I would like to run FilterA first and then FilterB.

If I deploy the above filters as OSGI bundles on CQ5.5 I only see FilterB is triggered on the HTTP White board console. I do not see FilterA being even invoked during my CQ5.5 login request flow.

Thanks.

标签: aem sling
2条回答
▲ chillily
2楼-- · 2019-09-06 14:50

You need to add a filter.order attribute to your service:

@Property(name="filter.order",intValue=-2500)

The lower the value, the further ahead in the chain the filter will be placed.

查看更多
We Are One
3楼-- · 2019-09-06 14:52

Check http://sling.apache.org/site/filters.html Service Ranking is what you're looking for. Also note on sling/cq5 you can see which filters are active and their ranking by looking /system/console/config and Sling Servlet Filters.

Also see filter-scope and the changes made to introduce pattern based scopes (SLING-1213, SLING-1734)

查看更多
登录 后发表回答