There are many possibilities in what may go wrong.
- There may be two different sessions.
- There may be some code that removes your configuration object from the session.
- Others?
Here you can check what exactly is happening.
There are two separate listener interfaces that you can implement to listen for specific session events: javax.servlet.http.HttpSessionListener and javax.servlet.http.HttpSessionAttributeListener
I would implement these two interfaces with a class that will register what happens during each event, and with what session the event occurs.
You should be able to easily add your listeners to your web.xml so that they are truly set as listeners in your tomcat sessions.
EDIT
Here is a class that you can place in your web.xml as a listener for your sessions. Both BalusC and I recommended that you try this approach to debug the problem. Please just humor us and let us know if you see anything interesting in how your “configuration” attribute is set?
import javax.servlet.http.HttpSessionActivationListener; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class SessionListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionActivationListener { public void valueBound(HttpSessionBindingEvent event) { System.out.println("valueBound: " + event.getName() + " : " + event.getValue()); System.out.println(" session: " + event.getSession().getId()); this.printStackTrace(); } public void valueUnbound(HttpSessionBindingEvent event) { System.out.println("valueUnbound: " + event.getName() + " : " + event.getValue()); System.out.println(" session: " + event.getSession().getId()); this.printStackTrace(); } public void attributeAdded(HttpSessionBindingEvent event) { System.out.println("attributeAdded: " + event.getName() + " : " + event.getValue()); System.out.println(" session: " + event.getSession().getId()); this.printStackTrace(); } public void attributeRemoved(HttpSessionBindingEvent event) { System.out.println("attributeRemoved: " + event.getName() + " : " + event.getValue()); System.out.println(" session: " + event.getSession().getId()); this.printStackTrace(); } public void attributeReplaced(HttpSessionBindingEvent event) { System.out.println("attributeReplaced: " + event.getName() + " : " + event.getValue()); System.out.println(" session: " + event.getSession().getId()); this.printStackTrace(); } public void sessionCreated(HttpSessionEvent event) { System.out.println("sessionCreated: " + event.getSession().getId()); this.printStackTrace(); } public void sessionDestroyed(HttpSessionEvent event) { System.out.println("sessionDestroyed: " + event.getSession().getId()); this.printStackTrace(); } public void sessionDidActivate(HttpSessionEvent event) { System.out.println("sessionDidActivate: " + event.getSession().getId()); this.printStackTrace(); } @Override public void sessionWillPassivate(HttpSessionEvent event) { System.out.println("sessionWillPassivate: " + event.getSession().getId()); this.printStackTrace(); } private void printStackTrace() { try { if (true) { throw new Exception(); } } catch (Exception e) { e.printStackTrace(); } } }
Please add the above class to your code, and then add the following to your web.xml file between your filter mappings and servlet mappings:
<listener> <listener-class><your.package.name>SessionListener</listener-class> </listener>
hooknc
source share