This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Using sessions in a web / non-web environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using sessions in a web / non-web environment" Watch "Using sessions in a web / non-web environment" New topic
Author

Using sessions in a web / non-web environment

Ruben Matthews
Greenhorn

Joined: Jan 05, 2009
Posts: 26
Hi!

I am creating a content repository system in Java that should be able to serve either web or desktop applications. And now I want to create some kind of session management, but I can't use cookies, since the system is not strictly for use in a web environment. How would you retain session (credentials/login) information in this situation? Should I store sessions myself in a db? And if so, how would I retain the link between the stored session and the client?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41063
    
  43
I normally wouldn't store sessions in the DB, I'd keep them on the app server (or whatever kind of server it is that runs the repository system). A session is really just a glorified Map for each user. Assuming that there are persistent socket connections for each client, the server would effectively keep a Map<Socket, Map<String,Object>> where all session maps are stored with the socket as the key to retrieve them.


Ping & DNS - my free Android networking tools app
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What do you mean by a "non-web environment"? If the user is running an app there's no reason to keep session information--it's not a series of disconnected HTTP requests.

If you're actually talking about a desktop application using a web service, then it's still a web environment, just hidden: either use cookies, or get a session ID in the login response and use it in subsequence requests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using sessions in a web / non-web environment
 
Similar Threads
Tomcat - sessions do not expire
Servlets and Sessions and Memoryleaks OH MY!
change password
question about design of Stateless Session Bean
remove all user Sessions