Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 68284 invoked from network); 16 Nov 2007 15:50:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Nov 2007 15:50:24 -0000 Received: (qmail 63568 invoked by uid 500); 16 Nov 2007 15:50:01 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 62836 invoked by uid 500); 16 Nov 2007 15:49:59 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 62825 invoked by uid 99); 16 Nov 2007 15:49:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 07:49:59 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of p@pidster.com designates 87.106.82.221 as permitted sender) Received: from [87.106.82.221] (HELO s15243851.onlinehome-server.info) (87.106.82.221) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 15:49:45 +0000 Received: (qmail 29037 invoked from network); 16 Nov 2007 15:49:37 +0000 Received: from 78-86-122-68.zone2.bethere.co.uk (HELO phoenix.config) (78.86.122.68) by s15243851.onlinehome-server.info with SMTP; 16 Nov 2007 15:49:37 +0000 Message-ID: <473DBBF0.9060509@pidster.com> Date: Fri, 16 Nov 2007 15:49:04 +0000 From: Pid Reply-To: p@pidster.com Organization: Pid Inc User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Problem with session activation after restart References: <801970510711150215q2e651b12x2d5fa205c1297dd1@mail.gmail.com> <473C994E.6070900@christopherschultz.net> <801970510711160141x2159ca22lf44a6299ca85e78a@mail.gmail.com> <801970510711160152n21faa5b5ra6fd5547b98d45aa@mail.gmail.com> <473D83CD.3000805@pidster.com> <801970510711160513kfd61155qa331bb279b0b4a33@mail.gmail.com> In-Reply-To: <801970510711160513kfd61155qa331bb279b0b4a33@mail.gmail.com> X-Enigmail-Version: 0.95.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Jacek Olszak wrote: > Hi, > > I try to describe my situation. I have a couple of session beans which > have transient properties. Those properties are in fact references to > Spring application beans. When the session is activated after restart > I want to inject spring beans again into restored session beans. > Unfortunately Spring's ContextLoaderListener has not been executed > before, so the Spring Context is not yet created (so I can't get > application beans from it). yeah, you won't be able to do that with the HttpSessionActivationListener. I'm not quite sure what to suggest that might do the trick either. Maybe you could write a lazy loader that imports the beans you want when they're requested. I know very little about Spring, but there may be a way to achieve what you want using Spring components. Sorry I can't be of more help. p > P.S. Forgive me my english :) I hope you understand me. > > Best regards > Jacek > > > On Nov 16, 2007 12:49 PM, Pid wrote: >> I think your problem may be rooted in a misunderstanding* of this >> listeners purpose. Perhaps you can elaborate on what you're trying to >> achieve? >> >> >> HttpSessionActivationListener.sessionDidActivate() is called when a >> session is retrieved from a persisted state or moved to another JVM. >> It's counterpart is called when a session is being persisted, or >> prepared for a move to another JVM. >> >> The sessions, therefore, are loaded(HSAL notifications) in advance of >> applications being started(SCL notifications), where they are then ready >> to be used(HSL, HSBL, HSAtL). >> >> The activity is more of a housekeeping notification, rather than a >> useful in-application notification that a session has been created or >> destroyed, or have attributes added to it. >> >> HSAL HttpSessionActivationListener >> HSAtL HttpSessionAttributeListener >> HSL HttpSessionListener >> HSBL HttpSessionBindingListener >> SCL ServletContextListener >> >> >> >> >> p >> >> >> >> * Well, either I misunderstand it**, or you do, or I misunderstand what >> you're trying to achieve, or you misu... >> >> ** Not uncommon >> >> >> >> >> Jacek Olszak wrote: >>> 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 wrote: >>>> Hi Chris, >>>> >>>> First of all thanks for reply. >>>> >>>> On Nov 15, 2007 8:09 PM, Christopher Schultz >>>> wrote: >>> 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: >>>>> >>>>> >>>>> >>>> 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"> >>>>> >>>>> >>>>> test.MyServletContextListener >>>>> >>>>> >>>>> >>>>> simpleServlet >>>>> test.SimpleServlet >>>>> >>>>> >>>>> >>>>> simpleServlet >>>>> /simple >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Best regards, >>>>> Jacek >>>>> >>>>> >>>>> >>> -chris >> --------------------------------------------------------------------- >> 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 >>>>> >> >> --------------------------------------------------------------------- >> 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 >> >> > > --------------------------------------------------------------------- > 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 > > --------------------------------------------------------------------- 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