We define several filters like this:
@SlingServletFilter(
scope = { SlingServletFilterScope.REQUEST },
pattern = "/bin/api/.*",
methods = { "GET", "POST" }
)
@Designate(ocd = CorrelationLoggingFilter.Config.class)
public class CorrelationLoggingFilter implements Filter {
The question is, how do we specify the order the filters are executed in?
Is this documented anywhere?
Solved! Go to Solution.
Views
Replies
Total Likes
I found the solution, and it seems to work:
@SlingServletFilter(
scope = { SlingServletFilterScope.REQUEST },
pattern = "/bin/api/.*",
methods = { "GET", "POST" }
)
@ServiceRanking(-200)
@Designate(ocd = CorrelationLoggingFilter.Config.class)
The next question is which fitler is run first, lower or higher order/priority/ranking number?
Two service properties are relevant to define a Sling filter :
service.ranking |
Integer |
0 (Default) |
Any Integer value |
Indication of where to place the filter in the filter chain. The higher the number the earlier in the filter chain. This value may span the whole range of integer values. Two filters with equal service.ranking property value (explicitly set or default value of zero) will be ordered according to their service.id service property as described in section 5.2.5, Service Properties, of the OSGi Core Specification R 4.2. |
For more information refer - https://sling.apache.org/documentation/the-sling-engine/filters.html
FYI, we are not using this type of annotation, as its not clear how we convert form the annotations we are using to these different ones, and they appear to be incompatible (we dont know how to combine the two types). We are looking for a solution we an add to our exsting code.
Order of filters is handled by sling ranking. Indication of where to place the filter in the filter chain. The higher the number the earlier in the filter chain. This value may span the whole range of integer values. Two filters with equal service.ranking
property value (explicitly set or default value of zero) will be ordered according to their service.id. Syntax:
@Component(property=Constants.SERVICE_RANKING+":Integer=5000")
Refer https://sling.apache.org/documentation/the-sling-engine/filters.html for more details.
We have found this annotation:
@ServiceRanking
So we are guessing this might work:
@SlingServletFilter(
scope = { SlingServletFilterScope.REQUEST },
pattern = "/bin/api/.*",
methods = { "GET", "POST" }
)
@ServiceRanking( value = 1000)
@Designate(ocd = CorrelationLoggingFilter.Config.class)
public class CorrelationLoggingFilter implements Filter {
The question is, how do we see the order of the existing servlets which dont have rankings? is there some sort of tool, or do we need to add a lot of debug statements and look at the logs?
I found the solution, and it seems to work:
@SlingServletFilter(
scope = { SlingServletFilterScope.REQUEST },
pattern = "/bin/api/.*",
methods = { "GET", "POST" }
)
@ServiceRanking(-200)
@Designate(ocd = CorrelationLoggingFilter.Config.class)
The next question is which fitler is run first, lower or higher order/priority/ranking number?
Views
Likes
Replies