tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Bowen <kbo...@als.com>
Subject SessionListener not being invoked
Date Tue, 01 Dec 2009 17:56:49 GMT

My setup: Mac OS X 10.5.8, Tomcat/6.0.20[from apache],  java version  
"1.6.0_15"
I'm starting Tomcat with ~bin/startup.sh.

I have a SessionListener which is not being invoked when I connect to  
the webapp,
and I don't understand why.
The SessionListener works correctly in a a slight variation of the  
circumstances.

The problem circumstance is when the app is running as the default  
ROOT webapp,
by dropping ROOT.war into webapps.

The relevant part of web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- ============================================ Welcome File List -->
<welcome-file-list>
     <welcome-file>pages/welcome.jsp</welcome-file>
</welcome-file-list>
<!-- ============================================ Listener  
Registration -->
   <listener>
     <listener-class>com.strongbrain.listener.AppListener</listener- 
class>
   </listener>
   <listener>
     <listener-class>com.strongbrain.listener.SessionListener</ 
listener-class>
   </listener>
<!-- ============================================ Context Parameters -->
<context-param>
     <param-name>baseprefix</param-name>
     <param-value>/</param-value>
  </context-param>

.........etc........

The SessionListener class:

package com.strongbrain.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import com.strongbrain.ConfigBean;
import com.strongbrain.Constants;

public class SessionListener implements HttpSessionListener
{
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
System.out.println("++++Enter sessionCreated");
       HttpSession session = httpSessionEvent.getSession();
       ConfigBean  configBean = new ConfigBean();
       String baseprefix =
           
httpSessionEvent 
.getSession 
().getServletContext().getInitParameter(Constants.BASEPREFIX);

       if (baseprefix != null){
          configBean.setBaseprefix(baseprefix);
       }
System.out.println("+++++++++SessionListener: isNew="+session.isNew() 
+"  baseprefix="+baseprefix+"  
configBean.bp="+configBean.getBaseprefix());
       session.setAttribute(Constants.CONFIG_BEAN, configBean);
    }

    public void sessionDestroyed(HttpSessionEvent arg0) {
    }
}

When I start Tomcat with the app (as ROOT.war) in webapps, and then  
connect with a browser,
catalina.out looks like this:

.....(usual stuff)
Dec 1, 2009 12:14:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2823 ms
[Deprecated] Xalan:  
org.apache.xalan.processor.TransformerFactoryImpl     <<<<< Browser  
connect above here
adl=5                                                <<<<< Healthy  
trace output from class invoked on welcome.jsp

Notice that neither of the System.out.println's in the  
SessionListener.sessionCreated method appear.

BUT:  When I run this in the non-ROOT configuration, things work.  In  
that case, the only difference in the code above is in
web.xml:
     <context-param>
         <param-name>baseprefix</param-name>
         <param-value>/strongbrain/</param-value>
      </context-param>

In that case, catalina.out shows:

Dec 1, 2009 12:30:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3072 ms
++++Enter sessionCreated
+++++++++SessionListener: isNew=true  baseprefix=/strongbrain/  
configBean.bp=/strongbrain/
[Deprecated] Xalan: org.apache.xalan.processor.TransformerFactoryImpl
adl=5

This behavior is occurring both on my (development) Mac,
and on a remote CentOS 5 system running Tomcat/6.0.18 under java  
version "1.6.0_12"

In all cases, the browser connects to the expected welcome page.

At present, I'm at a loss as to what to look for;  I hope someone here  
can point me in the right direction.
Thanks in advance,
Ken Bowen





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message