views:

225

answers:

1

Hi,

I'm trying to build a Spring server for GWT (you can think of it as of Javascript AJAX client). But I can't decide on one point of architecture. How should session be created and used?

The obvious easiest way - is to use HTTP sessions (cookies and stuff). Looks fine, but I think that sending session ID separate from the headers would be better (SOAP style).

So, what is better: getMyPetsName(String sessionID, int petID) or getMyPetsName(int petID) + session ID through HTTP header (cookies or something).

Another question is, if I use the first way (which I like more) - how do I handle session in Spring? I'm really newbie in Spring, and googling did not help. What I mean is:

String getMyPetsName(String sessionID, int petID) {
    Session s = someWayToGetItById(sessionID);
}

Thanks in advance.

+2  A: 

If you can choose it I would opt for always sending the session id.

It will make things a lot easier, also when a user opens multiple tabs in the same session.

If you are not using Spring MVC I do not think Spring will put much constraints/assumptions on how you handle the session. There are many caches, like ehcache, which can be set up using spring and store your sessions. The better caches also allow the sessions to be distributed over machines and stored persistently without impacting on the code base.

Peter Tillemans
Yes, that's why I thought it would be better way to do it. However the second question is still open, I have no slightest idea how to get the session by ID in Spring.
Max
Yes, i edited my answer to include that. I would just use a good cache implementation which can be easily configured by Spring. Spring will then inject it in your components. Typically they have a singleton which allows to fetch your Session data.
Peter Tillemans
Hm, so you propose handling sessions separate from the container sessions. Isn't there any way to reuse the container sessions? For example to force it give me a session with specified ID?
Max
That is more what WebMVC,WebFlow does, but I fear if you use GWT on the browser these sessions will start fighting with each other since their assumptions on what they suppose to be doing will be slightly different.These container sessions start from the assumption that there the browser keeps almost no state (HTTP is a stateless protocol), however with GWT and the other Javascript frameworks this is no longer valid. And you'll keep fighting with the multiple open tabs issues. With a stupid cache there are much less moving parts which might interact badly
Peter Tillemans