views:

55

answers:

4

I'm developing a Java web application on GAE platform in which I'm storing an User object in session. When I test my code in local development server (Windows XP + Eclipse), I'm able to get the User object back from the session.

But when I deploy the same piece of code to GAE server, I'm facing issues with Session. I'm able to retrieve the session object but whatever the data I stored in session previously was missing.

Btw, I have enabled the sessions in appengine-web.xml file by using <sessions-enabled>true</sessions-enabled>.

Can anyone tell me if there is something that I'm missing here to use the sessions properly?

PS: I'm using struts2 and my actions implement SessionAware to get the current session in my code.

+1  A: 

From the GAE documentation:

Because App Engine stores session data in the datastore and memcache, all values stored in the session must implement the java.io.Serializable interface.

Do all of the values you store in session implement Serializable? Any objects referenced by the value you put in the Session must also be serializable - the entire object graph needs to be.

matt b
A: 

I'm using Struts1 and I have exactly the same problem, all classes do implement Serializable, they have all annotations... Is there a some tutorial on this topic? How to properly put object to Session and how to take it back from it?

Lada Riha
A: 

@Lada Riha You don't need to change anything, let's say you have a User class

class User implements Serializable{

}

In your controller(assuming you already made User instance), you can save your object in session like this.

request.getSession().setAttribute("loginUser",user);

so throught out your application(from JSP)

session.getAttribute("loginUser");

Or from other places(other controllers)

request.getSession().getAttribute("loginUser");

Struts 1 works on GAE with a few exceptions.

zawhtut
A: 

zawhtut: Thanks for answer. However, I think I have already have all this. In brief, user submits login form, some Action class (extends org.apache.struts.action.Action) process it. If values are ok, it saves instance of User to session:

request.getSession().setAttribute("us", u);

Then user is redirected to jsp page, where is something like this:

<jsp:useBean class="cz.sayit.beans.UserBean" scope="session" id="us" />
<c:when test="${us.email != null}">
<html:form action="logout.do" >
<html:submit value="Sign out ${us.name}"/>
</html:form>
</c:when>
<c:otherwise>

And so far it works fine, it shows button with user's name. But I have another form on this page for posting messages. When user submit message, another action class process this request and again it tries to found something about user using:

UserBean u = (UserBean) request.getSession().getAttribute("us");

But the "u" is null here. And I have no idea why, on localhost it works fine, but on GAE it's not :(

Sorry for this question, I recently deployed the application to GAE with new version but in app settings in appengine there was set old version as default... So many hours wasted :)

Lada Riha