0

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.

Navi
  • 109
  • 1
  • 2
  • 9
  • I have figured out I can use service.ranking to order the filters as OSGI components. [Sling service.ranking][1] [1]: http://sling.apache.org/site/filters.html – Navi Apr 02 '13 at 22:48
  • you should post this as an answer and then accept it. – Robert Munteanu Apr 03 '13 at 07:49

2 Answers2

2

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)

cwoeltge
  • 201
  • 1
  • 4
1

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.

ilikeorangutans
  • 1,753
  • 1
  • 11
  • 14
  • 1
    From the sling filter docs it _seems_ as though this was replaced by service.ranking. The [filter.order property is supported up to and including 2.1.0](http://sling.apache.org/documentation/the-sling-engine/filters.html#support-in-sling-engine-210). However, some of the sling filters still use this property and not service.ranking. The filter.order property is only used if service.ranking is not present. See [SLING-1735](https://issues.apache.org/jira/browse/SLING-1735) – diffa Apr 04 '13 at 15:47
  • Thanks diffa you are correct service.ranking is the right way to order standard filters for Apache Felix Http Service Whiteboard implementation – Navi Apr 05 '13 at 03:39