Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Management Problem

Status
Not open for further replies.

SON1

Programmer
Nov 21, 2004
51
CY
I am developing a webapp in java(using the webwork framework). When i am accessing the server directly i.e. , the session management works OK. If i configure a domain , i.e. which maps to an apache server which forwards the requestes to the internal server it always registers a new session with the server. (so the user is essentially logged in for 1 page, and then is seen as logged out for everypage thereafter)

For the session management i have a session listener and a session service.
The listener is configured inside web.xml as attached.
Attached also SessionService, SessionListener and Tomcat out

I would like any insights for solving this problem, or any solutions for replacing this code with something else that would work.

Thanx

C.




<listener>
<listener-class>cy.dating.utils.SessionListener</listener-class>
</listener>




SessionListener:
------------------------


import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;


public class SessionListener implements HttpSessionListener{

public void sessionCreated(HttpSessionEvent event) {
SessionService.getInstance().addSession(event.getSession());

}

public void sessionDestroyed(HttpSessionEvent event) {
SessionService.getInstance().removeSession(event.getSession());
}
}




SessionService:
-----------------------



import ....domainobjects.Registration;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Iterator;

import org.apache.log4j.Category;

public class SessionService {
private static SessionService ourInstance = new SessionService();
private HashMap sessions = new HashMap();
private static Category logger = Category.getInstance(SessionService.class);

public static SessionService getInstance() {
return ourInstance;
}

private SessionService() {
}

public void addSession(HttpSession ses){
sessions.put(ses.getId(), ses);
logger.debug("Registered new session: "+ses.getId());
}

public void removeSession(HttpSession ses){
sessions.remove(ses.getId());
logger.debug("Unregisterd seesion:"+ses.getId());
}

public HttpSession findSession(String nick){
Iterator it = sessions.values().iterator();
while(it.hasNext()){
HttpSession session = (HttpSession) it.next();
if(session.getAttribute("registration")!=null){
Registration registration = (Registration) session.getAttribute("registration");
if(registration.getNick().equals(nick))
return session;
}
}
return null;
}

public HttpSession findSession(int id_registration){
Iterator it = sessions.values().iterator();
while(it.hasNext()){
HttpSession session = (HttpSession) it.next();
if(session.getAttribute("registration")!=null){
Registration registration = (Registration) session.getAttribute("registration");
if(registration.getId()==id_registration)
return session;
}
}
return null;
}

public int countOnlineUsers(){
Iterator it = sessions.values().iterator();
int count=0;
while(it.hasNext()){
HttpSession session = (HttpSession) it.next();
if(session.getAttribute("registration")!=null)
count++;
}
return count;
}
}



The Tomcat output:
----------------------------
1 Jan 2006 09:27:44. DEBUG [http-9090-Processor24] - Registered new session: 3379890EF0750544FEDBA0201A4E7AA1
1 Jan 2006 09:27:50. DEBUG [http-9090-Processor23] - Registered new session: 79B7B95D97611A6D90756E741394324D
1 Jan 2006 09:27:54. DEBUG [http-9090-Processor24] - Registered new session: 28BBE0D1CBF1817C3F919A9E885A4A0B

etc...
 
How are you forwarding requests from Apache to Tomcat ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
the configuration is inside the apache configuration file. do you beleive it could play a role in this problem?
 
What I mean is ... are you using HTTP redirects from Apache to Tomcat, or are you using the mod_jk protocol ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
HTTP redirects, as my network admin said
 
Well I'm not sure thats going to work, as I think Tomcat will see the client IP as the Apache server, not the actual client - and so the cookie data (Tomcat stores cookies on the client to persist session info) will be lost each time the client is redirected from Apache to Tomcat.

If you want to use Apache as a front end to Tomcat, you should use the mod_jk protocol, not redirects.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
i printed out (in tomcat) the session id is giving out and i added it to the url as ;jsessionid... etc and it works out. Maybe somehow i can add this somehow automatic to the whole application ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top