slingHttpServletRequest .sendRedirect not working in AEM as cloud Publisher filter | Community
Skip to main content
Level 2
February 18, 2026
Solved

slingHttpServletRequest .sendRedirect not working in AEM as cloud Publisher filter

  • February 18, 2026
  • 2 replies
  • 20 views

aem as cloud response.sendRedirect not working for query parameters with 4000 characters length and getting with 502 error response and no logs for exception's in AEM as cloud publisher where as in AEM On-premise there is no issue.

This issue was identified after migrating to AEM as cloud, below is code which was used.

slingHttpServletRequest .setStatus(302);
slingHttpServletRequest .sendRedirect(azureRegistrationUrl);

 

Kindly share your suggestion's / comments on this.

Best answer by AmitVishwakarma

Hi ​@raju_komari ,
sendRedirect() puts your entire azureRegistrationUrl into the Location response header. On AEM as a Cloud Service, that header goes through the CDN / Jetty chain, which has hard limits on header size (typically 8–16 KB total). Once the Location header (plus others) crosses that limit, the proxy returns a 502 before AEM logs anything.
You cannot tune these limits in AEMaaCS (unlike on‑prem). See the general guidance on header/URL limits in AEMaaCS: https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-22193

 

Try below solution:
Stop using sendRedirect() for that long URL and do a client‑side redirect instead:

  1. Return a small HTML page from your filter.
  2. That page uses JavaScript (or meta refresh) to navigate to azureRegistrationUrl.

Example:

String target = azureRegistrationUrl; // very long URL

response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/html;charset=UTF-8");

String html = "<!DOCTYPE html><html><head>" +
"<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; script-src 'self' 'unsafe-inline'\">" +
"<script>window.location.href='" + org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript(target) + "';</script>" +
"</head><body></body></html>";

response.getWriter().write(html);
  • The response headers stay small (no huge Location header).
  • The browser then performs the actual navigation to the long Azure URL, bypassing the AEM/CDN header limit.

If you can change the Azure side, also consider: 

  • Shortening the redirect URL (use a small state token + server‑side lookup instead of encoding everything in query params).

But with today’s AEMaaCS constraints, the only reliable fix on the AEM side is to avoid long Location headers and use a client‑side redirect page as shown above.  

Thanks,
Amit

2 replies

giuseppebaglio
Level 10
February 19, 2026

hi ​@raju_komari,

UPmgJk6yYnp883zD

The 502 error for long redirect URLs likely stems from response header size limits in the managed infrastructure, unlike on-premise setups where these can be tuned.
IMHO this occurs because response.sendRedirect() sets a Location header with the full azureRegistrationUrl, which exceeds the size limits in components like Jetty or the CDN/Dispatcher stack. No exception logs appear in AEM as the failure happens at the proxy/gateway level (e.g., bad gateway from oversized headers), not in AEM application code.

 

As noted in the AEM 6.5 section “Response header size can be greater than 4 KB”, the standard header size is typically 4KB. While I haven’t yet found a specific reference for AEM Cloud, it’s reasonable to assume this limitation remains similar.

Level 2
February 19, 2026

Thanks for the update ​@giuseppebaglio !

AmitVishwakarma
Community Advisor
AmitVishwakarmaCommunity AdvisorAccepted solution
Community Advisor
February 19, 2026

Hi ​@raju_komari ,
sendRedirect() puts your entire azureRegistrationUrl into the Location response header. On AEM as a Cloud Service, that header goes through the CDN / Jetty chain, which has hard limits on header size (typically 8–16 KB total). Once the Location header (plus others) crosses that limit, the proxy returns a 502 before AEM logs anything.
You cannot tune these limits in AEMaaCS (unlike on‑prem). See the general guidance on header/URL limits in AEMaaCS: https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-22193

 

Try below solution:
Stop using sendRedirect() for that long URL and do a client‑side redirect instead:

  1. Return a small HTML page from your filter.
  2. That page uses JavaScript (or meta refresh) to navigate to azureRegistrationUrl.

Example:

String target = azureRegistrationUrl; // very long URL

response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/html;charset=UTF-8");

String html = "<!DOCTYPE html><html><head>" +
"<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; script-src 'self' 'unsafe-inline'\">" +
"<script>window.location.href='" + org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript(target) + "';</script>" +
"</head><body></body></html>";

response.getWriter().write(html);
  • The response headers stay small (no huge Location header).
  • The browser then performs the actual navigation to the long Azure URL, bypassing the AEM/CDN header limit.

If you can change the Azure side, also consider: 

  • Shortening the redirect URL (use a small state token + server‑side lookup instead of encoding everything in query params).

But with today’s AEMaaCS constraints, the only reliable fix on the AEM side is to avoid long Location headers and use a client‑side redirect page as shown above.  

Thanks,
Amit

Level 2
February 19, 2026

HI ​@AmitVishwakarma 

Thank you so much for your time and sharing options.

we have fixed the issue same way which you mention.

Below is the code for fixing the issue, new code which is fixed the issue

httpServletResponse.setContentType("text/html");
PrintWriter out = httpServletResponse.getWriter();
out.println("<html><head>");
out.println("<meta http-equiv=\"refresh\" content=\"0;url=" + azureRegistrationUrl + "\">");
out.println("</head><body>Redirecting to Azure...</body></html>");
out.flush();

old code issue

httpServletResponse.setStatus(302);
httpServletResponse.sendRedirect(azureRegistrationUrl);