I'm trying to integrate Spring MVC with Spring WebFlow. In order to share session data between both of them I came up with this solution that actually works fine:
public String prepareForPayment(RequestContext context, Authentication currentUser) {
PaymentDetails paymentDetails = new PaymentDetails();
// CODE HERE
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getNativeRequest();
request.getSession().setAttribute("paymentDetails", paymentDetails);
// CODE HERE
}
Then in a Controller outside webflow I can easily get session data:
PaymentDetails paymentDetails = (PaymentDetails)session.getAttribute("paymentDetails");
So above code works fine and I'm able to set and get session attributes.
Now, when I write a test for this class I get:
java.lang.ClassCastException: java.lang.Object cannot be cast to javax.servlet.http.HttpServletRequest
Why my test is throwing ClassCastException
and how to solve it?
I checked my code again and I think the whole "problem" came from me trying to return
Object
instead ofHttpServletRequest
directly. Therefore, I causedClassCastException
. This piece of code works fine: