Mark Spritzler wrote:True REST, has a rule of always stateless. So no HttpSession involved.
Mark
Kathleen Angeles wrote:
Nico Martens wrote:
Is that a best practice to use HttpSession.
The http protocol is stateless.
Rest (when using http under it, and all other types of remote calls for that matter like XML Web Service), do not maintain state unless you make it so. Your way of putting your 'test_object' in the HttpSession indeed makes it stateful.
Your Rest service being stateful is bad in some ways; e.g. in service-oriented architecture, maintainability of code due to clean design, performance, etc. For example, the concerned service is no longer purely independent. But if this is what you want, and what your application calls for (for example, small web applications or modules), you can do so.
Nico Martens wrote: Should I initialize my HttpSession in my servlet?
You can access the HttpSession by adding an HttpSession into your controller method's parameters like below.
Nico Martens wrote: Does the rest controller knows from which session it is called?
Yes, because it is part of the servlet specification. For example, a session id is used (e.g. through cookies, or url parameter), which reminds the server which session it is for.
Kathleen Angeles wrote:You can use HttpSession attributes. It is persistent between calls.