April 25, 2020
Estimated Post Reading Time ~

AEM 6.1 - Filter RequestDispatcher Forward breaks i18n

I just noticed that on AEM 6, in my Filter, when I call RequestDispatcher forward, i.e. request.getRequestDispatcher(...).forward(req, res);, it cause i18n to break. Here's a snippet of my codes:

...
boolean filtered = false;

SlingHttpServletRequest request = req instanceof SlingHttpServletRequest ? (SlingHttpServletRequest) req : null;
SlingHttpServletResponse response = res instanceof SlingHttpServletResponse ? (SlingHttpServletResponse) res : null;
            
if (request != null && response != null) {
                
    // block of codes to resolve the request uri and get the new desired URI 
                    
    if (this.resolvedUriResource != null) {
        String uri = this.resolvedUriResource.getPath() + ".html";
        RequestDispatcherOptions options = new RequestDispatcherOptions();
        options.setAddSelectors(uriSelectors);
        this.filterConfig.getServletContext().getRequestDispatcher(uri).forward(req, res); // OR
        //request.getRequestDispatcher(this.resolvedUriResource, options).forward(req, res);
        filtered = true;
    }
}

if (!filtered) {
    chain.doFilter(req, res);
}
...

The exact same codes were working on AEM6.0 and AEM 5.6.x.
Download this package to try out and see the issue: AEM6.1-i18n-issue-samplepackage.zip.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.