permaculture playing cards
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 Java Interview Guide this week in the Jobs Discussion 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

Using sessions in a web / non-web environment

Ruben Matthews

Joined: Jan 05, 2009
Posts: 26

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?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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.
David Newton

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:
subject: Using sessions in a web / non-web environment
It's not a secret anymore!