Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session persistance across browser/server restart using google app-engine

How do I make sessions persist across browser/server restarts?
I'm using Google AppEngine.
I'm getting a new session id everytime I restart my browser and/or server.

String jSessionId=this.getThreadLocalRequest().getSession().getId();

End Goal
The big win I'm shooting for is long lived anonymous accounts.
For example, a user can do action A, have an anonymous account created on their behalf, then come back the next day and do action B with the same anonymous account they did action A with(assuming they didn't clear their cookies in between).

And at some point, once they've been drawn in, they can decide to validate/register their account and keep credit for the anonymous stuff they've already done.

like image 552
antony.trupe Avatar asked Nov 05 '22 19:11

antony.trupe


1 Answers

Unless I'm mistaken here, and I well could be (if Google changes the internals of GAE), GAE uses both memcache and DataStore for session management. Hence, session data will be present in the DataStore during the course of the session.

If you intend to have persistent sessions, you have two possible course of action:

  1. Use cookies, not the existing JSESSIONID cookie, since you will not be able to modify it. However, I'm not so sure whether new cookies can be created at all, since support for the Cookie class does not seem to be mentioned. You might be in luck though, since GAE uses Jetty internally. The downside however, is that this data will be lost if the user clears his browser cookies.
  2. Design session management of your application well enough, such that session data can be persisted into the DataStore. That way, whenever such data changes, you can persist it into the DataStore, and pick up from the DataStore the next time the user authenticates into the application. This is assuming that the existing session management infrastructure provided by GAE is purging what it has stored in the DataStore (expected out of any application that performs session management - it should clean up invalid sessions).

PS: Server restarts on GAE should ideally be considered far and few. Of course, don't count on this, since GAE could have an outage, in which case the application itself would be unavailable.

like image 98
Vineet Reynolds Avatar answered Nov 12 '22 19:11

Vineet Reynolds