Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Communication between Login BaseMVCActionCommand and Filter [Liferay 7.2]
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?
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?
You could write the information in the session (Request Scope is probably sufficient) and retrieve it later on.
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?
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?
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.
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 |
| |
} |
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™