Hello,
Below are two points I'm trying to cover via my Sling filter but seems not functional properly.
1. I want my filter to be chained on specific resource types e.g. /apps/a/p1 , /apps/a/p2 , /apps/a/p3
2. I want my filter to be chained only on specific query parameters in request (e.g. https://helloworld.xyz/parent/page-1.html?q=...., https://helloworld.xyz/parent/page-2.html?q=...., https://helloworld.xyz/parent/page-3.html?q=.... )etc.
Below are current state of my filter
1. Filter Scope is of "Request"
2. Tried multiple resource types as below syntax; Assume resource types of page-1 is " /apps/a/p1", resource types of page-2 is " /apps/a/p2" & resource types of page-3 is " /apps/a/p3". Also assume content path of pages are as /content/parent/page-1 etc.
@Component (service = Filter.class, property = {
EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,
EngineConstants.SLING_FILTER_METHODS + "=" + "GET",
EngineConstants.SLING_FILTER_EXTENSIONS + "=" + "html",
EngineConstants.SLING_FILTER_PATTERN + "=" + "/content/(parent)/.*",
EngineConstants.SLING_FILTER_RESOURCETYPES + "=['/apps/a/p1','/apps/a/p2',/apps/a/p3']"
})
But I'm unable to register (tried with comma separated values also) and also when i'm using @SlingServletFilter annotation, same issue is taking place.
@SlingServletFilter(scope = { SlingServletFilterScope.REQUEST},
resourceTypes = {"/apps/a/p1","/apps/a/p2","/apps/a/p3"},
pattern = "/content/(parent)/.*",
extensions = {".html"},
methods = {"GET"})
Views
Replies
Total Likes
Hi,
Can you check.
https://sling.apache.org/documentation/the-sling-engine/filters.html
I have achieve this in the past using regex pattern.
Hi Arun,
I tried with these two patterns for resourceTypes -- i) one with absolute path "/apps/a/(p1|p2|p3)" and ii) with relative path "a/(p1|p2|p3)"; Do I need to try something different?
Hi,
Not sure if this will work with resourceType because the resourcetype argument is for component scope. I am not 100% sure but I used this when I need to intercept the component rendering
e.g. https://github.com/arunpatidar02/aem63app-repo/blob/master/java/XFFilter.java
Thanks Arun for sharing the input ! seems the resourceType is not considered in request scope (as you mentioned) so it was not working e.g. For the page requests, the resource type seems actually synonymous to primary type of the page node i.e. "cq:Page"..
Views
Replies
Total Likes
Yes, all the primary node types also considered as resource type when registered for filter, servlet etc.
Views
Replies
Total Likes
Hi @DJSarkar
Is your resourceType getting resolved? Ignore below If not. (resourceType is an relative path just double check)
@Component (service = Filter.class, property = {
EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,
EngineConstants.SLING_FILTER_METHODS + "=" + "GET",
EngineConstants.SLING_FILTER_EXTENSIONS + "=" + "html",
EngineConstants.SLING_FILTER_PATTERN + "=" + "/content/(parent)/.*",
EngineConstants.SLING_FILTER_RESOURCETYPES + "=" + "/apps/a/p1",
EngineConstants.SLING_FILTER_RESOURCETYPES + "=" + "/apps/a/p2",
EngineConstants.SLING_FILTER_RESOURCETYPES + "=" + "/apps/a/p3",
})
Then get queryString parameter from the URL to check and filter chain.
Regards,
Santosh
Hi Santosh,
Thanks for the response. I tried multiple resource types the way you mentioned. But seems it didn't work. Also I tried with absolute and relative path as well. and at last, I tried with regex pattern as - "/apps/a/(p1|p2|p3)" but got no luck.
if I just remove the page resourceTypes and keep rest fields, it's working fine.
@DJSarkar
It seems OOTB, there's no possibility of associating Sling Filters with Sling Resource Types. Found one workaround here to achieve it: https://stackoverflow.com/questions/16886232/does-sling-allow-component-filters-configured-to-target...
Hope that Helps!
Hi Santosh,
Yes! seems the resourceType is not considered in request scope (as Arun mentioned) so it was not working e.g. For the page requests, the resource type seems actually synonymous to primary type of the page node i.e. "cq:Page".
i) COMPONENT SCOPE is working fine with the specific resource types with the format which you mentioned earlier.
ii) But REQUEST SCOPE is working with REQUEST/RESOURCE_PATTERN but seems can not cover resource type.
Views
Replies
Total Likes
Hi @DJSarkar -
Have you tried the relative paths with SlingServletFilter annotation like below?
@SlingServletFilter(scope = { SlingServletFilterScope.REQUEST},
resourceTypes = {"a/p1","a/p2","a/p3"},
pattern = "/content/(parent)/.*",
extensions = {".html"},
methods = {"GET"})
Views
Likes
Replies
Views
Likes
Replies