I have a SparkJava api filter that is called by my client every 30 seconds.
before("/app/*", {
req, _ ->
println(req.session().attributes().size)
println(req.session().id())
println(req.session().isNew)
req.session().attribute("test", "test")
})
The result is:
0 node0r3ulllnarwq5i62o2wcpxmu25 true 0 node0i0morm89ftci1tntiu38p8l5026 true 0 node09n12ooeo0t34wkpaqfhbbou227 true
You can see above, the session id is always different. Why the session is always a new session?
I was stupidly mistaken, but the behavior is correct. REST is stateless and has no session.
There is a good explanation:
If REST applications are supposed to be stateless, how do you manage sessions?