|| !(servletResponse instanceof SlingHttpServletResponse)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;
/**
* Fail fast and early!
*
* Must be:
* - HTTP GET Request
* - Have Forms Sling Suffix
* - At this point, 99% of includes will be passed over
* - Must contain Form Selector Query Parameter
* - Include is not a product of a previous forward by this Filter
*/
if (!StringUtils.equals("GET", slingRequest.getMethod())
|| !formsRouter.hasValidSuffix(slingRequest)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
/* Ensure there is a valid form selector as part of Query Params */
final String formSelector = formsRouter.getFormSelector(slingRequest);
if (formSelector == null) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
/* Ensure this is not a product of a previous forward; This is to be absolutely sure we are not hitting an
* infinite loop condition */
if (slingRequest.getAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED) != null) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
final RequestDispatcherOptions options = new RequestDispatcherOptions();
options.setReplaceSelectors(formSelector);
options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix());
if (log.isDebugEnabled()) {
log.debug("POST-Redirect-GET Form Filter; Internal forward to resource: {} ",
slingRequest.getResource());
log.debug("POST-Redirect-GET Form Filter; Internal forward to path: {} ",
slingRequest.getResource().getPath());
log.debug("POST-Redirect-GET Filter; Internal forward w/ replace selectors: {} ",
options.getReplaceSelectors());
log.debug("POST-Redirect-GET Filter; Internal forward w/ suffix: {} ",
options.getReplaceSuffix());
}
// Avoid accidental infinite loops with API consumers doing their own Fws and Includes
slingRequest.setAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED, Boolean.TRUE);
slingRequest.getRequestDispatcher(slingRequest.getResource(), options).forward(slingRequest, slingResponse);
}