tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacek Olszak" <jacekols...@gmail.com>
Subject Re: Problem with session activation after restart
Date Fri, 16 Nov 2007 09:52:21 GMT
Hi again, I found that I've sent wrong log when stopping the server
(second log in my earlier post). The correct is:

INFO: Pausing Coyote HTTP/1.1 on http-8080
2007-11-16 10:50:35 org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
DEBUG 2007-11-16 10:50:35,625 test.SessionBean Session will passivate
DEBUG 2007-11-16 10:50:35,640 test.MyServletContextListener Context destroyed
2007-11-16 10:50:35 org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080

Best regards,
Jacek

On Nov 16, 2007 10:41 AM, Jacek Olszak <jacekolszak@gmail.com> wrote:
> Hi Chris,
>
> First of all thanks for reply.
>
> On Nov 15, 2007 8:09 PM, Christopher Schultz
> <chris@christopherschultz.net> wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Jacek,
> >
> > Jacek Olszak wrote:
> > > The problem is that the method
> > > HttpSessionActivationListener.sessionDidActivate() is called before
> > > any context listeners. I have a ContextLoaderListener configured in
> > > my web.xml which creates the Spring context.
> >
> > Do you mean a ServletContextListener?
> >
>
> Yes, I mean ServletContextListener.
>
> > > I want my session beans have access to this context, but they are
> > > activated before the context is done. Is there a way to change this
> > > behavior?
> >
> > Section 10.3.4 of the servlet spec says that, during shutdown, session
> > listeners are notified before context listeners, so I would imagine that
> > the opposite is true for startup (although the 2.4 spec doesn't
> > explicitly state that AFAICT).
> >
> > Looking at StandardContext in the TC 6.0 sources, I don't see any
> > mention of HttpSessionActivationListener, so I think those are ignored
> > during startup (and shutdown). Only when the session manager starts (or
> > stops) should you see notifications to your session listeners.
> >
> > Can you provide evidence to support your claim? Do you have log
> > statements in your ServletContextListener and your
> > HttpSessionActivationListener with timestamps that support your claim?
> > If so, please post them so we can take a look at them.
>
> I've created some simple application for testing - with one session
> bean "test.SessionBean" which implements HttpSessionActivationListener
> and context listener "test.MyServletContextListener" which implements
> ServletContextListener.
>
> And here is the log:
>
> Log when starting server without any session beans stored:
>
> 2007-11-16 10:36:38 org.apache.coyote.http11.Http11Protocol init
> INFO: Initializing Coyote HTTP/1.1 on http-8080
> 2007-11-16 10:36:38 org.apache.catalina.startup.Catalina load
> INFO: Initialization processed in 557 ms
> 2007-11-16 10:36:38 org.apache.catalina.core.StandardService start
> INFO: Starting service Catalina
> 2007-11-16 10:36:38 org.apache.catalina.core.StandardEngine start
> INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
> 2007-11-16 10:36:38 org.apache.catalina.loader.WebappClassLoader validateJarFile
> INFO: validateJarFile(C:\eclipse\workspaces\europa\tomcat-test\target\tomcat-test-1.0-SNAPSHOT\WEB-INF\lib\servlet-api-2.4.jar)
> - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending
> class: javax/servlet/Servlet.class
> DEBUG 2007-11-16 10:36:38,875 test.MyServletContextListener Context initialized
> 2007-11-16 10:36:38 org.apache.coyote.http11.Http11Protocol start
> INFO: Starting Coyote HTTP/1.1 on http-8080
> 2007-11-16 10:36:38 org.apache.jk.common.ChannelSocket init
> INFO: JK: ajp13 listening on /0.0.0.0:8009
> 2007-11-16 10:36:38 org.apache.jk.server.JkMain start
> INFO: Jk running ID=0 time=0/31  config=null
> 2007-11-16 10:36:38 org.apache.catalina.startup.Catalina start
> INFO: Server startup in 511 ms
>
>
> Log when stopping the server (with one attribute in session):
>
> 2007-11-16 10:38:06 org.apache.coyote.http11.Http11Protocol pause
> INFO: Pausing Coyote HTTP/1.1 on http-8080
> 2007-11-16 10:38:07 org.apache.catalina.core.StandardService stop
> INFO: Stopping service Catalina
> DEBUG 2007-11-16 10:38:07,140 test.MyServletContextListener Context destroyed
> 2007-11-16 10:38:07 org.apache.coyote.http11.Http11Protocol destroy
> INFO: Stopping Coyote HTTP/1.1 on http-8080
>
>
> Log when starting the server (with one session attribute stored in file):
>
> 2007-11-16 10:38:32 org.apache.coyote.http11.Http11Protocol init
> INFO: Initializing Coyote HTTP/1.1 on http-8080
> 2007-11-16 10:38:32 org.apache.catalina.startup.Catalina load
> INFO: Initialization processed in 570 ms
> 2007-11-16 10:38:33 org.apache.catalina.core.StandardService start
> INFO: Starting service Catalina
> 2007-11-16 10:38:33 org.apache.catalina.core.StandardEngine start
> INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
> 2007-11-16 10:38:33 org.apache.catalina.loader.WebappClassLoader validateJarFile
> INFO: validateJarFile(C:\eclipse\workspaces\europa\tomcat-test\target\tomcat-test-1.0-SNAPSHOT\WEB-INF\lib\servlet-api-2.4.jar)
> - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending
> class: javax/servlet/Servlet.class
> DEBUG 2007-11-16 10:38:33,375 test.SessionBean Session did activate
> DEBUG 2007-11-16 10:38:33,406 test.MyServletContextListener Context initialized
> 2007-11-16 10:38:33 org.apache.coyote.http11.Http11Protocol start
> INFO: Starting Coyote HTTP/1.1 on http-8080
> 2007-11-16 10:38:33 org.apache.jk.common.ChannelSocket init
> INFO: JK: ajp13 listening on /0.0.0.0:8009
> 2007-11-16 10:38:33 org.apache.jk.server.JkMain start
> INFO: Jk running ID=0 time=0/31  config=null
> 2007-11-16 10:38:33 org.apache.catalina.startup.Catalina start
> INFO: Server startup in 509 ms
>
> As you see session did activate before executing contextInitialized on
> test.MyServletContextListener.
>
> Here is the sources:
>
> MyServletContextListener.java:
>
> package test;
>
> import javax.servlet.ServletContextEvent;
> import javax.servlet.ServletContextListener;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> public class MyServletContextListener implements ServletContextListener {
>
>     private Log log = LogFactory.getLog(MyServletContextListener.class);
>
>     public void contextInitialized(ServletContextEvent sce) {
>         log.debug("Context initialized");
>     }
>
>     public void contextDestroyed(ServletContextEvent sce) {
>         log.debug("Context destroyed");
>     }
>
> }
>
> SessionBean.java:
>
> package test;
>
> import java.io.Serializable;
>
> import javax.servlet.http.HttpSessionActivationListener;
> import javax.servlet.http.HttpSessionEvent;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> public class SessionBean implements HttpSessionActivationListener,
> Serializable {
>
>     private static final long serialVersionUID = 1L;
>
>     private Log log = LogFactory.getLog(SessionBean.class);
>
>     public void sessionDidActivate(HttpSessionEvent se) {
>         log.debug("Session did activate");
>     }
>
>     public void sessionWillPassivate(HttpSessionEvent se) {
>         log.debug("Session will passivate");
>     }
>
> }
>
>
> SimpleServlet.java:
>
> package test;
>
> import java.io.IOException;
>
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> public class SimpleServlet extends HttpServlet {
>
>     private static final long serialVersionUID = 1L;
>
>     @Override
>     protected void doGet(HttpServletRequest req, HttpServletResponse
> resp) throws ServletException, IOException {
>         req.getSession().setAttribute("sessionBean", new SessionBean());
>     }
> }
>
> log4j.properties:
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.conversionPattern=%-5p %d %C %m%n
> log4j.logger.test=DEBUG,stdout
>
>
> 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">
>
>         <listener>
>                 <listener-class>test.MyServletContextListener</listener-class>
>         </listener>
>
>         <servlet>
>                 <servlet-name>simpleServlet</servlet-name>
>                 <servlet-class>test.SimpleServlet</servlet-class>
>         </servlet>
>
>         <servlet-mapping>
>                 <servlet-name>simpleServlet</servlet-name>
>                 <url-pattern>/simple</url-pattern>
>         </servlet-mapping>
>
> </web-app>
>
>
>
> Best regards,
> Jacek
>
>
>
> >
> > - -chris
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.7 (MingW32)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> > iD8DBQFHPJlO9CaO5/Lv0PARAtWbAJ9T4bmo6HOHCV6rBcIhvUpFRQLiMgCeKs5L
> > YJXop4aiJnZt+6xIrzrN4a8=
> > =q5+j
> > -----END PGP SIGNATURE-----
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>



-- 
Best regards
Jacek

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


Mime
View raw message