Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Override PageRedirectServlet 6.5

Avatar

Level 2

Hi good afternoon, i trying to modify the PageRedirectServlet to do a custom redirection in AEM. 

I have tried to put a selector in proxy.jsp file that points to the selector of my custom servlet but it has not worked. I have also tried the service.ranking property but it hasn't worked for me either.

Can someone help me with this and tell me how I should do it?

The version I use of AEM is the SDK version (2024.4.15977.20240418T174835Z)

Thank you

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

There is a typo in your servlet registration. Use 

sling.servlet.methods

instead of 

sling.servlets.methods

I tried 

@component(service = Servlet.class,
        property = {
                Constants.SERVICE_DESCRIPTION + "= Redirection Servlet",
                "sling.servlet.extensions=" + "html",
                "sling.servlet.selectors=" + "redirect",
                "sling.servlet.resourceTypes=" + "cq/Page",
                "sling.servlet.methods=" +"GET",
                Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE
        })

And this worked fine. So, just fix the typo and I think it should work.

View solution in original post

7 Replies

Avatar

Level 2

Hi MukeshYadav thanks for you answer.

I try with this, but it doesn't work.

Avatar

Community Advisor

Can you check if your serlvet is registered properly and is in active state at /system/console/components 
and also check at the servlet resolver /system/console/servletresolver which servlet is getting picked when you try to invoke 
/content/<your_content_path>.redirect.html

Avatar

Level 2

Hi h_kataria thank you for your answer.

The serlvet is registred and active.
Captura de pantalla 2024-07-19 a las 12.30.37.png

And is resolved by my server but also by the com.day.cq.wcm.foundation.PageRedirectServlet.
Captura de pantalla 2024-07-19 a las 12.33.22.png

Avatar

Community Advisor

As you can also see from the screenshot, OOB servlet is taking precedence. So, you should further try to increase the service ranking for your servlet till it appears on top in the servlet resolver.

Avatar

Level 2

Hi h_kataria I tryed with diferents values of service ranking and with the following definition

property = {
Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE,
Constants.SERVICE_DESCRIPTION + "= Redirect page request to target locations",
"sling.servlet.extensions=" + "html",
"sling.servlet.selectors=" + "redirect",
"sling.servlet.resourceTypes=" + "cq/Page",
"sling.servlets.methods=" + "GET"
}

, and its didnt work. can you share with me an example?

Thanks

Avatar

Correct answer by
Community Advisor

There is a typo in your servlet registration. Use 

sling.servlet.methods

instead of 

sling.servlets.methods

I tried 

@component(service = Servlet.class,
        property = {
                Constants.SERVICE_DESCRIPTION + "= Redirection Servlet",
                "sling.servlet.extensions=" + "html",
                "sling.servlet.selectors=" + "redirect",
                "sling.servlet.resourceTypes=" + "cq/Page",
                "sling.servlet.methods=" +"GET",
                Constants.SERVICE_RANKING + ":Integer=" + Integer.MAX_VALUE
        })

And this worked fine. So, just fix the typo and I think it should work.