craigmcc    02/01/18 17:58:24

  Modified:    catalina/src/share/org/apache/catalina/session
                        StandardManager.java StandardSession.java
               tester/src/tester/org/apache/tester Session01.java
                        Session04.java SessionListener01.java
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester SessionListener03.java
  Log:
  Correct the set of session related events fired at context startup and
  shutdown time by the StandardManager implementation, as follows:
  
  * At Tomcat shutdown (or in the shutdown portion of a
    context reload), ONLY fire sessionWillPassivate() events
    to session attributes that implement HttpSessionActivationListener.
    Previously, a spurious valueUnbound() event was being sent
    to session attributes that implemented HttpSessionBindingListener.
  
  * At Tomcat startup time (or in the reload portion of a
    context reload), ONLY fire sessionDidActivate() events
    to session attributes that implement HttpSessionActivationListener.
    Previously, a spurious sessionCreated() event was sent to
    registered HttpSessionListener listeners.
  
  None of this directly affects the behavior of PersistentManager, as reported
  in Bugzilla #5895, but that is the next thing to investigate.
  
  I consider this bugfix somewhat risky for the 4.0 branch, so I don't
  think we should necessarily port it.
  
  Revision  Changes    Path
  1.18      +5 -5      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardManager.java
  
  Index: StandardManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardManager.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- StandardManager.java      3 Jan 2002 13:31:50 -0000       1.17
  +++ StandardManager.java      19 Jan 2002 01:58:24 -0000      1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardManager.java,v
 1.17 2002/01/03 13:31:50 remm Exp $
  - * $Revision: 1.17 $
  - * $Date: 2002/01/03 13:31:50 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardManager.java,v
 1.18 2002/01/19 01:58:24 craigmcc Exp $
  + * $Revision: 1.18 $
  + * $Date: 2002/01/19 01:58:24 $
    *
    * ====================================================================
    *
  @@ -106,7 +106,7 @@
    * <code>stop()</code> methods of this class at the correct times.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.17 $ $Date: 2002/01/03 13:31:50 $
  + * @version $Revision: 1.18 $ $Date: 2002/01/19 01:58:24 $
    */
   
   public class StandardManager
  @@ -544,7 +544,7 @@
           while (expires.hasNext()) {
               StandardSession session = (StandardSession) expires.next();
               try {
  -                session.expire();
  +                session.expire(false);
               } catch (Throwable t) {
                   ;
               }
  
  
  
  1.27      +53 -8     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardSession.java
  
  Index: StandardSession.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardSession.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- StandardSession.java      18 Jan 2002 22:14:07 -0000      1.26
  +++ StandardSession.java      19 Jan 2002 01:58:24 -0000      1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardSession.java,v
 1.26 2002/01/18 22:14:07 craigmcc Exp $
  - * $Revision: 1.26 $
  - * $Date: 2002/01/18 22:14:07 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardSession.java,v
 1.27 2002/01/19 01:58:24 craigmcc Exp $
  + * $Revision: 1.27 $
  + * $Date: 2002/01/19 01:58:24 $
    *
    * ====================================================================
    *
  @@ -115,7 +115,7 @@
    * @author Craig R. McClanahan
    * @author Sean Legassick
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
  - * @version $Revision: 1.26 $ $Date: 2002/01/18 22:14:07 $
  + * @version $Revision: 1.27 $ $Date: 2002/01/19 01:58:24 $
    */
   
   class StandardSession
  @@ -580,6 +580,20 @@
        */
       public void expire() {
   
  +        expire(true);
  +
  +    }
  +
  +
  +    /**
  +     * Perform the internal processing required to invalidate this session,
  +     * without triggering an exception if the session has already expired.
  +     *
  +     * @param notify Should we notify listeners about the demise of
  +     *  this session?
  +     */
  +    public void expire(boolean notify) {
  +
           // Mark this session as "being expired" if needed
           if (expiring)
               return;
  @@ -593,16 +607,18 @@
           // Unbind any objects associated with this session
           String keys[] = keys();
           for (int i = 0; i < keys.length; i++)
  -            removeAttribute(keys[i]);
  +            removeAttribute(keys[i], notify);
   
           // Notify interested session event listeners
  -        fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
  +        if (notify) {
  +            fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
  +        }
   
           // Notify interested application event listeners
           // FIXME - Assumes we call listeners in reverse order
           StandardContext context = (StandardContext) manager.getContainer();
           Object listeners[] = context.getApplicationListeners();
  -        if (listeners != null) {
  +        if (notify && (listeners != null)) {
               HttpSessionEvent event =
                 new HttpSessionEvent(getSession());
               for (int i = 0; i < listeners.length; i++) {
  @@ -1047,6 +1063,29 @@
        */
       public void removeAttribute(String name) {
   
  +        removeAttribute(name, true);
  +
  +    }
  +
  +
  +    /**
  +     * Remove the object bound with the specified name from this session.  If
  +     * the session does not have an object bound with this name, this method
  +     * does nothing.
  +     * <p>
  +     * After this method executes, and if the object implements
  +     * <code>HttpSessionBindingListener</code>, the container calls
  +     * <code>valueUnbound()</code> on the object.
  +     *
  +     * @param name Name of the object to remove from this session.
  +     * @param notify Should we notify interested listeners that this
  +     *  attribute is being removed?
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     */
  +    public void removeAttribute(String name, boolean notify) {
  +
           // Validate our current state
           if (!expiring && !isValid)
               throw new IllegalStateException
  @@ -1065,6 +1104,11 @@
               }
           }
   
  +        // Do we need to do valueUnbound() and attributeRemoved() notification?
  +        if (!notify) {
  +            return;
  +        }
  +
           // Call the valueUnbound() method if necessary
           HttpSessionBindingEvent event =
             new HttpSessionBindingEvent((HttpSession) this, name, value);
  @@ -1253,7 +1297,8 @@
           isValid = ((Boolean) stream.readObject()).booleanValue();
           thisAccessedTime = ((Long) stream.readObject()).longValue();
           principal = null;        // Transient only
  -        setId((String) stream.readObject());
  +        //        setId((String) stream.readObject());
  +        id = (String) stream.readObject();
           if (debug >= 2)
               log("readObject() loading session " + id);
   
  
  
  
  1.5       +7 -1      
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session01.java
  
  Index: Session01.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session01.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Session01.java    15 Aug 2001 00:57:09 -0000      1.4
  +++ Session01.java    19 Jan 2002 01:58:24 -0000      1.5
  @@ -72,7 +72,7 @@
    * calling setAttribute("name", null) acts like removeAttribute().
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/08/15 00:57:09 $
  + * @version $Revision: 1.5 $ $Date: 2002/01/19 01:58:24 $
    */
   
   public class Session01 extends HttpServlet {
  @@ -99,6 +99,12 @@
                   writer.println("Session01 FAILED - No session created");
                   ok = false;
               }
  +        }
  +
  +        // Store an activation event listener in the session
  +        if (ok) {
  +            session.setAttribute("activationListener",
  +                                 new SessionListener03());
           }
   
           // Ensure that there is no existing attribute
  
  
  
  1.3       +5 -1      
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session04.java
  
  Index: Session04.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session04.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Session04.java    11 Dec 2001 03:51:34 -0000      1.2
  +++ Session04.java    19 Jan 2002 01:58:24 -0000      1.3
  @@ -69,7 +69,7 @@
    * identifier) while processing this request.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/12/11 03:51:34 $
  + * @version $Revision: 1.3 $ $Date: 2002/01/19 01:58:24 $
    */
   
   public class Session04 extends HttpServlet {
  @@ -171,6 +171,10 @@
               if (bean != null)
                   results.append(" New session has attribute already/");
           }
  +
  +        // Store an activation event listener in the session
  +        newSession.setAttribute("activationListener",
  +                                    new SessionListener03());
   
           // Report success if everything is still ok
           if (results.length() == 0)
  
  
  
  1.3       +10 -1     
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionListener01.java
  
  Index: SessionListener01.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionListener01.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SessionListener01.java    11 Dec 2001 03:51:34 -0000      1.2
  +++ SessionListener01.java    19 Jan 2002 01:58:24 -0000      1.3
  @@ -68,7 +68,7 @@
    * creation and destruction events are logged to the servlet context log.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/12/11 03:51:34 $
  + * @version $Revision: 1.3 $ $Date: 2002/01/19 01:58:24 $
    */
   
   public class SessionListener01
  @@ -78,16 +78,25 @@
       public void attributeAdded(HttpSessionBindingEvent event) {
           StaticLogger.write("SessionListener01: attributeAdded(" +
                              event.getName() + "," + event.getValue() + ")");
  +        event.getSession().getServletContext().log
  +            ("SessionListener01: attributeAdded(" + event.getSession().getId()
  +             + "," + event.getName() + ")");
       }
   
       public void attributeRemoved(HttpSessionBindingEvent event) {
           StaticLogger.write("SessionListener01: attributeRemoved(" +
                              event.getName() + "," + event.getValue() + ")");
  +        event.getSession().getServletContext().log
  +            ("SessionListener01: attributeRemoved(" +
  +             event.getSession().getId() + "," + event.getName() + ")");
       }
   
       public void attributeReplaced(HttpSessionBindingEvent event) {
           StaticLogger.write("SessionListener01: attributeReplaced(" +
                              event.getName() + "," + event.getValue() + ")");
  +        event.getSession().getServletContext().log
  +            ("SessionListener01: attributeReplaced(" +
  +             event.getSession().getId() + "," + event.getName() + ")");
       }
   
       public void sessionCreated(HttpSessionEvent event) {
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionListener03.java
  
  Index: SessionListener03.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *   Copyright (c) 1999, 2000, 2001, 2002  The Apache Software Foundation.   *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  
  /**
   * Session attribute that listens to passivation and activation events.
   * All events that occur are logged to the servlet context log.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/01/19 01:58:24 $
   */
  
  public class SessionListener03
      implements HttpSessionActivationListener, HttpSessionBindingListener,
                 Serializable {
  
      public void sessionDidActivate(HttpSessionEvent event) {
          event.getSession().getServletContext().log
              ("SessionListener03: sessionDidActivate(" +
               event.getSession().getId() + ")");
      }
  
      public void sessionWillPassivate(HttpSessionEvent event) {
          event.getSession().getServletContext().log
              ("SessionListener03: sessionWillPassivate(" +
               event.getSession().getId() + ")");
      }
  
      public void valueBound(HttpSessionBindingEvent event) {
          event.getSession().getServletContext().log
              ("SessionListener03: valueBound(" +
               event.getSession().getId() + "," +
               event.getName() + ")");
      }
  
      public void valueUnbound(HttpSessionBindingEvent event) {
          event.getSession().getServletContext().log
              ("SessionListener03: valueUnbound(" +
               event.getSession().getId() + "," +
               event.getName() + ")");
      }
  
  
  }
  
  
  
  1.56      +0 -1      jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- web.xml   12 Dec 2001 22:34:20 -0000      1.55
  +++ web.xml   19 Jan 2002 01:58:24 -0000      1.56
  @@ -436,7 +436,6 @@
   
       <!-- ========== Listener Definitions ================================== -->
   
  -
       <listener>
           <listener-class>org.apache.tester.ContextListener01</listener-class>
       </listener>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to