Major session problem [GAE]

2011-06-09 Thread Zeldor
Hi,

I have really serious problems with my sessions - or rather getting and
displaying data with it. It works great when tested locally, but when
deployed to GAE it acts weird. In bad way. I have no idea if it's wicket or
GAE issue, but maybe I can get some hints here.

Problem is that:
- it quite often fails to load data, so when user logs it it shows blank
pages, without any data, that should com from session
[MySession.loggedInUser.get...]
- on very rare occasions it can show old values, that were changed long time
ago, some residue must be left over somewhere and is not cleaned and somehow
it can switch between
- and there was a case when one user could see data from other user [so
sessions switched?]

Of course situations 23 can never happen. Situation 1 neither - but maybe
it can be solved by some check and reload of data?

Some code to illustrate:

MySession:

public class MySession extends WebSession {

public MySession(Request request) {
super(request);
}

public boolean isAuthenticated() {
return (loggedInUser != null);
}

public static User loggedInUser;


public User getLoggedInUser() {
return loggedInUser;
}
public void setLoggedInUser(User loggedInUser) {
this.loggedInUser = loggedInUser;
}
}

In Login:

((MySession) MySession.get()).setLoggedInUser(user);


Later data is accessed by MySession.loggedInUser.[getters/setters here] and
persisted to datastore when anything changes.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3584894.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread i...@e-dog.hu
On 2011.06.09. 10:48, Zeldor wrote:
 public static User loggedInUser;
Is it correct? I think it is better without static!

GeZo

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread Pepijn de Geus
Storing the User in a static field doesn't seem wise: the static field is 
shared between all session instances, so this will break.
Besides that, I'd advise not to store the User instance itself in the session, 
but only the user ID (or username, or email). The User instance can be cached 
in a transient field, which can be checked and loaded on request by a 
(non-static) getUser() method.

Something like this:

public class MySession extends WebSession {

private int userId = -1;
private transient User user;

public void setUser(User user) {
userId = user.getId();
this.user = user;
}

public User getUser() {
if (userId == -1) return null;
if (user == null) {
user = UserDAO.loadUser(userId);
}
return user;
}

@Override
public void detach() {
user = null;
super.detach();
}

}


On 9 jun 2011, at 10:48, Zeldor wrote:

 Hi,
 
 I have really serious problems with my sessions - or rather getting and
 displaying data with it. It works great when tested locally, but when
 deployed to GAE it acts weird. In bad way. I have no idea if it's wicket or
 GAE issue, but maybe I can get some hints here.
 
 Problem is that:
 - it quite often fails to load data, so when user logs it it shows blank
 pages, without any data, that should com from session
 [MySession.loggedInUser.get...]
 - on very rare occasions it can show old values, that were changed long time
 ago, some residue must be left over somewhere and is not cleaned and somehow
 it can switch between
 - and there was a case when one user could see data from other user [so
 sessions switched?]
 
 Of course situations 23 can never happen. Situation 1 neither - but maybe
 it can be solved by some check and reload of data?
 
 Some code to illustrate:
 
 MySession:
 
 public class MySession extends WebSession {
   
   public MySession(Request request) {
   super(request);
   }
   
   public boolean isAuthenticated() {
   return (loggedInUser != null);
   }
   
   public static User loggedInUser;
   
   
   public User getLoggedInUser() {
   return loggedInUser;
   }
   public void setLoggedInUser(User loggedInUser) {
   this.loggedInUser = loggedInUser;
   }
 }
 
 In Login:
 
 ((MySession) MySession.get()).setLoggedInUser(user);
 
 
 Later data is accessed by MySession.loggedInUser.[getters/setters here] and
 persisted to datastore when anything changes.
 
 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3584894.html
 Sent from the Users forum mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org
 


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread Zeldor
Yeah, no idea why Static is there, must be some leftover from early code.
It's good to have someone else take a look at your code and point the
obvious :) I will check if it solves my problems.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3585007.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Major session problem [GAE]

2011-06-09 Thread Hielke Hoeve
Using static non-final fields in a multi user environment is very very
very very bad. The only cases you should use static are for example a
logger (log4j etc) a global variable defining a number or string.
If you do need to keep track of something using final then wrap this
using the ThreadLocal class.

final static Logger log;
final static String applicationName = Zeldors application;
final static String maxNumUsers = 2; 

Hielke

-Original Message-
From: Zeldor [mailto:pgronkiew...@gmail.com] 
Sent: donderdag 9 juni 2011 11:32
To: users@wicket.apache.org
Subject: Re: Major session problem [GAE]

Yeah, no idea why Static is there, must be some leftover from early
code.
It's good to have someone else take a look at your code and point the
obvious :) I will check if it solves my problems.

--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3
584894p3585007.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread Zeldor
norckon:

Getting whole entity is good in my case. User can modify only his data and
no one else can even access or see it. It speeds up things too. 

Anyway, how do you invoke the rest? Without static you of course get
non-static method cannot be referenced from a static context compilation
error.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3585460.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread Pepijn de Geus
The Wicket websession has a static .get(), which will always return the 
ThreadLocal session instance for the current user.
So you can use that and cast the result to your session, or add your own get() 
to your session:

public static MySession get() {
return (MySession) WebSession.get();
}

WebPage also has his own getSession() you could use.


On 9 jun 2011, at 15:02, Zeldor wrote:

 norckon:
 
 Getting whole entity is good in my case. User can modify only his data and
 no one else can even access or see it. It speeds up things too. 
 
 Anyway, how do you invoke the rest? Without static you of course get
 non-static method cannot be referenced from a static context compilation
 error.
 
 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3585460.html
 Sent from the Users forum mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org
 


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Major session problem [GAE]

2011-06-09 Thread Zeldor
So...

MySession.get().getUser().getLand() 

to properly get a value from session? Looks like it could have some
performance issues, or does it just look so scary? :)


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Major-session-problem-GAE-tp3584894p3585657.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org