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).

P.S. Forgive me my english :) I hope you understand me.

Best regards
Jacek


On Nov 16, 2007 12:49 PM, Pid <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote:
> >> Hi Chris,
> >>
> >> First of all thanks for reply.
> >>
> >> On Nov 15, 2007 8:09 PM, Christopher Schultz
> >> <[EMAIL PROTECTED]> 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:
> >>>
> >>> <?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
> >>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

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

Reply via email to