My Question is not about how to use HTTP session or how values are being used in session. Question is more oriented about approach.
In my current application there are few values being stored in the Session and we require those values every now and than, here are few values we fetching from session
- Store
- Language
- Customer
- few others
I can fetch these values from session like
request.getSession().getAttribute( "name" )
I need those values not directly in my Controller, but in other layer (say Facade) so I have 2 options
- Pass each required values to Facade method by
request.getSession().getAttribute( "name" )
. - Create a method in each Facade Class like.
Method in Facade
private Object getSessionValue(final String key) {
ServletRequestAttributes reqAttr = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
return reqAttr.getRequest().getAttribute(key);
}
Though both are working find in my case, but with one exception, I need to have this method on each Facade Class or need to fetch each object in Controller.
Is there any other way or approach which might be more clean or my current approach is fine