Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Intermittent loss of some session attributes  RSS feed

 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session attributes after logging into web-app:

Session Attributes
thisUsersAllowedRoles=45
username=hw
authenticatedUser=org.hw.client.payroll.model.User@2c8a09da
supervisorCode=
authenticated=true
isSupervisor=true
menu=org.hw.client.payroll.model.Menu@1a8cde0e
isPayroll=true
isAnalyst=false
isAdmin=true
isHR=false
isDirector=true

Every now and then while debugging I lose session attributes:

Session Attributes
thisUsersAllowedRoles=45
username=hw
supervisorCode=
authenticated=true
isSupervisor=true
isPayroll=true
isAnalyst=false
isAdmin=true
isHR=false
isDirector=true

The authenticatedUser and menu attributes are gone. I never know when it's going to happen so I can't trace it. Any guesses why those type session objects would die?

I attached an image of what menu object looks like.



menuObject.JPG
[Thumbnail for menuObject.JPG]
menuObjectImage
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WAG: are the missing objects Serializable?
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the answer to that, so I'll have to figure it out. I would not have expected to need them serialized, but that's as good a WAG as any.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your environment serializes the session (I have no idea if it does or not), it will not be able to do so for non-serializable scoped variables.
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm seeing this on my local machine, NetBeans7/Tomcat7. The user's menu object is constructed at login based on application permissions/roles, then saved to user's session and added to the JSP as an include file .jspf.
The jspf has <c:forEach items="${sessionScope.menu.submenus}" var="submenu" >.

The MenuBuilder class reads the users permissions previously stored on the session constructs the menu object and returns the object to PopulateNewSession class where it is stored on the session. PopulateNewSession is called within AuthenticateUserTask class.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would bet that those references are lost because those classes are not serializable.

Servlet containers are allowed to serialize sessions to disk whenever they want.

Who is responsible for the org.hw.client.payroll.model.User and org.hw.client.payroll.model.Menu classes?

Bill
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll take responsibility Bill. I looked at that after Bear mentioned it. Most results refer to a clustered environment. If I am missing something here in servlet design and you want to throw some hints at me, I won't duck. Some references suggest serializing the session because it's scalable.

And just curious, should I be able to reply to this from mobile. I saw new topic but not reply.
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:WAG: are the missing objects Serializable?

Yes sir, they are now.

William Brogden wrote:I would bet that those references are lost because those classes are not serializable.
Servlet containers are allowed to serialize sessions to disk whenever they want.

Thanks Bill.

http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts -- the <distributable> element is a huge boon.

Howard Watson wrote:I never know when it's going to happen so I can't trace it.

In the Conversational State section of HFSJ there's a discussion of HttpSessionAttributeListener that I am never supposed to need because "all my attributes are straightforward Serializable objects."


Thanks y'all!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Love it when WAGs work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!