I am creating a web application in java where I need to mock the following flow.
When user trigger a certain process (add product to cart), I need to pass through following steps
- Need to see in HTTP Session if user is logged in.
- Check HTTP Session if shopping cart is there
- If user exist in HTTP Session and his/her cart do not exist in HTTP Session
- Get user cart from the database.
- add item to cart and save it to HTTP session and update cart in DB.
- If cart does not exist in DB, create new cart and and save in it HTTP Session.
Though I missed a lot of use cases here (do not want question length to increase a lot), but most of the flow will be same as I described in above steps.
My flow will start from the Controller
and will go towards Service
Layer and than ends up in the DAO
layer.
Since there will be a lot of use cases where I need to check HTTP session and based on that need to call Service
layer, I was planning to add a Facade
layer which should be responsible to do this for me like checking Session
and interacting with Service
layer.
Please suggest if this is a valid approach or any other best approach can be implemented here?
One more point where I am confused is how to handle HTTP session
in facade layer? do I need to pass HTTP session object each time I call my Facade
or any other approach can be used here?
getAttribute()
andsetAttribute()
ofHttpSession
, do you really need a Facade ? In case you eventually follow that approach , then pass therequest
around and not theHttpSession
object .