Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Sling Filter pattern works in local but not in real environment

Avatar

Level 4

We have a sling filter to read some page properties. We have registered with the pattern. It all works great in local AEM instance but as soon as we deploy the code to our environments (DEV, QA, PROD), the filter is not even getting called.

@component
@SlingServletFilter(
    scope = {SlingServletFilterScope.REQUEST},
    pattern = "/content/myapp/.*",
    extensions = "html"
)

In the local instance, the URL is "/content/myapp/us/en/home/test.html". But in the environment, the URL is "myapp.com/test" which is handled through Dispatcher.

Is there anything I am missing here?

Just FYI, we are on AMS.

Thank you!

8 Replies

Avatar

Community Advisor

I believe the content might be cached in the DEV, QA, and PROD dispatchers. I would recommend to try again after clearing the dispatcher cache, specifically for the /content/myapp.

Avatar

Level 4

Hi @Mahedi_Sabuj,

Thanks for responding.

Even after removing the extension, it's still not working when pages are fetched from the publisher through the dispatcher. I have added the log and seems like it's working in the author instance though.

Avatar

Community Advisor

Please clear the dispatcher cache and try again.

In the author environment, it works because pages are not cached.

After clearing the dispatcher cache, the filter will be triggered only the first time you open any page. If you reload the page, the filter will not be triggered again.

If the requirement is to trigger the filter each time a page is browsed, ensure that the page is not cached in the dispatcher.

Avatar

Level 4

Hi @Mahedi_Sabuj,

Yes, I cleared the dispatcher cache as well but no luck. I would debug further if the filter gets called but I have LOG.info in the very first line of the doFilter method and not seeing it logged. In the Author instance, I can see the message printing in the log file.

Avatar

Administrator

@webdev91 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Administrator

@webdev91,

The issue is likely due to the difference in URL patterns between your local AEM instance and the production environment. In your local instance, you're using the pattern /content/myapp/.*, which matches the full URL /content/myapp/us/en/home/test.html. However, in the production environment, the Dispatcher is rewriting the URL to myapp.com/test, which doesn't match your filter pattern.

To address this, you need to modify your filter pattern to match the rewritten URLs. Since the Dispatcher is removing the /content/myapp/ prefix, you can adjust your pattern to simply match the remaining part of the URL, which is .*. This will ensure that your filter is called for all requests to your application, regardless of the Dispatcher's rewriting.

Here's the updated filter configuration:

@component
@SlingServletFilter(
    scope = {SlingServletFilterScope.REQUEST},
    pattern = ".*",
    extensions = "html"
)

With this updated pattern, your filter should be invoked for all requests to your application, even after being rewritten by the Dispatcher.



Kautuk Sahni

Avatar

Administrator

@webdev91 did the answer from us help you?



Kautuk Sahni