Sling Filter pattern works in local but not in real environment | Community
Skip to main content
New Participant
November 14, 2023

Sling Filter pattern works in local but not in real environment

  • November 14, 2023
  • 4 replies
  • 1581 views

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.

@8220494 @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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

kautuk_sahni
Employee
November 20, 2023

@webdev91 did the answer from us help you?

Kautuk Sahni
kautuk_sahni
Employee
November 16, 2023

@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
kautuk_sahni
Employee
November 15, 2023

@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
webdev91Author
New Participant
November 15, 2023

Hi @kautuk_sahni,

I am still looking for the answer.

Mahedi_Sabuj
New Participant
November 14, 2023

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.

Mahedi Sabuj
webdev91Author
New Participant
November 15, 2023

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.

Mahedi_Sabuj
New Participant
November 15, 2023

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.

Mahedi Sabuj