Communication between Login BaseMVCActionCommand and Filter [Liferay 7.2]

Antonio Suano, modified 5 Years ago. New Member Posts: 2 Join Date: 8/5/20 Recent Posts
Hello,I'm currently migrating code from 6.2 to 7.2, and I've found myself stuck on something that should be trivial, but can't find a solution.

I have a BaseMVCActionCommand for the login action, where I recover three variables. Thus far, nothing troublesome, but now I need to pass these variables to a Filter class which is invoked on a certain range of urls to do some operations. Any ideas how to do this?
Antonio Javier Ortega Pérez, modified 5 Years ago. New Member Posts: 22 Join Date: 4/20/11 Recent Posts
Hi. I have exactly the same problem. Did you solve it? Does anyone have any ideas?
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
You could write the information in the session (Request Scope is probably sufficient) and retrieve it later on.
Antonio Suano, modified 5 Years ago. New Member Posts: 2 Join Date: 8/5/20 Recent Posts
I've considered using Session, but for some reason I can't get it to work. For example, I pass the variables in the Action like this:

HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
httpServletRequest.getSession().setAttribute("foo", foo);

And retrieve it in the Filter like this:
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession(false);
String foo = (String) session.getAttribute("foo");

But it always returns null. Any idea what's happening?
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Can you check if your filter is called in the same request? You probably can test this by throwing an exception in the action and the stacktrace should show your filter in it. Maybe exact timespamps help too, your filter should be after the Action.
Wild guess: The Request is often wrapped in a HttpServletRequestWrapper, maybe you need to check the "inner" requests.
HttpServletRequest wrappedHttpServletRequest = httpServletRequest;
while (wrappedHttpServletRequest instanceof HttpServletRequestWrapper) {
// Add debug info here, check session
wrappedHttpServletRequest =
(HttpServletRequest)httpServletRequestWrapper.getRequest();

}