I am experiencing a problem while trying to make the RedirectAttributes' flashAttributes work. I've setup a website built with Spring MVC on Tomcat 7.0 and a reverse proxy using Apache mod_proxy and ajp.
The problem I am facing is also described in this question, but the answer provided there, simply does not apply in my case (I am using a single instance of Tomcat).
This is a snippet from the controller I am using for testing purposes:
@RequestMapping(value = "/land", method = RequestMethod.GET)
public String land(RedirectAttributes redirectAttrs, Model model) {
return "redirect_landing";
}
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect(RedirectAttributes redirectAttrs, HttpSession session) {
// add a session message
session.setAttribute("sessionMessage", "a session message");
// add a flash message
redirectAttrs.addFlashAttribute("flashMessage", "a flash message");
// define the base url
String baseUrl = "http://localhost:8080/MyApp/";
// String baseUrl = "http://dev.myapp.lan/";
return "redirect:" + baseUrl + "land";
}
And the template is as simple as this:
Flash message: ${flashMessage}
Session message: ${sessionMessage}
The same code gives different results, depending on whether I am accessing the website directly on Tomcat or via the apache reverse proxy:
Tomcat's response:
Flash message: a flash message
Session message: a session message
Behind apache mod_proxy:
Flash message:
Session message: a session message
Why is there no flash message when accessing the website via the proxy?
I checked out the code for RedirectAttributesModelMap.java and ModelMap.java but there is not enough info there (obviously the logic is implemented elsewhere).
Note: I can always fall back to the session attributes to achieve my goal, but this issue feels interesting enough for those who use Tomcat behind a reverse proxy
Proxy Configuration (snippet):
<VirtualHost *:80>
ServerName dev.myapp.lan
ProxyPass / ajp://localhost:8009/MyApp/
ProxyPassReverseCookiePath /MyApp /
ProxyPassReverseCookieDomain localhost MyApp
ErrorLog /var/log/apache2/phonebook-error.log
LogLevel warn
CustomLog /var/log/apache2/phonebook-access.log combined
</VirtualHost>
TIA.