tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session StandardSession.java
Date Fri, 01 Mar 2002 19:37:45 GMT
craigmcc    02/03/01 11:37:45

  Modified:    catalina/src/share/org/apache/catalina/authenticator
                        AuthenticatorBase.java
               catalina/src/share/org/apache/catalina/session
                        StandardSession.java
  Log:
  Use Java reflection to remove cross-package dependencies on
  org.apache.catalina.core.StandardContext in AuthenticatorBase and
  StandardSession.
  
  There are now no external package dependencies on anything in o.a.c.core
  except for:
  
  - org.apache.catalina.mbeans.* - Creation of the JMX MBeans that correspond
    to each of the standard implementation classes
  
  - org.apache.catalina.startup.* - Initial configuration and startup of the
    standard implementation clasess.
  
  Neither of which is useful in a "minimal Tomcat" scenario.
  
  Submitted by:	Christopher K.St.John <cks at distributopia.com>
  
  Revision  Changes    Path
  1.30      +18 -7     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java
  
  Index: AuthenticatorBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- AuthenticatorBase.java	27 Feb 2002 17:42:36 -0000	1.29
  +++ AuthenticatorBase.java	1 Mar 2002 19:37:44 -0000	1.30
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v
1.29 2002/02/27 17:42:36 remm Exp $
  - * $Revision: 1.29 $
  - * $Date: 2002/02/27 17:42:36 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v
1.30 2002/03/01 19:37:44 craigmcc Exp $
  + * $Revision: 1.30 $
  + * $Date: 2002/03/01 19:37:44 $
    *
    * ====================================================================
    *
  @@ -66,6 +66,7 @@
   
   
   import java.io.IOException;
  +import java.lang.reflect.Method;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.security.MessageDigest;
  @@ -95,7 +96,6 @@
   import org.apache.catalina.Session;
   import org.apache.catalina.Valve;
   import org.apache.catalina.ValveContext;
  -import org.apache.catalina.core.StandardContext;
   import org.apache.catalina.deploy.LoginConfig;
   import org.apache.catalina.deploy.SecurityConstraint;
   import org.apache.catalina.util.LifecycleSupport;
  @@ -121,7 +121,7 @@
    * requests.  Requests of any other type will simply be passed through.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.29 $ $Date: 2002/02/27 17:42:36 $
  + * @version $Revision: 1.30 $ $Date: 2002/03/01 19:37:44 $
    */
   
   
  @@ -1068,8 +1068,19 @@
               throw new LifecycleException
                   (sm.getString("authenticator.alreadyStarted"));
           lifecycle.fireLifecycleEvent(START_EVENT, null);
  -        if (context instanceof StandardContext)
  -            setDebug(((StandardContext) context).getDebug());
  +        if ("org.apache.catalina.core.StandardContext".equals
  +            (context.getClass().getName())) {
  +            try {
  +                Class paramTypes[] = new Class[0];
  +                Object paramValues[] = new Object[0];
  +                Method method =
  +                    context.getClass().getMethod("getDebug", paramTypes);
  +                Integer result = (Integer) method.invoke(context, paramValues);
  +                setDebug(result.intValue());
  +            } catch (Exception e) {
  +                log("Exception getting debug value", e);
  +            }
  +        }
           started = true;
   
           // Look up the SingleSignOn implementation in our request processing
  
  
  
  1.28      +124 -41   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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- StandardSession.java	19 Jan 2002 01:58:24 -0000	1.27
  +++ StandardSession.java	1 Mar 2002 19:37:45 -0000	1.28
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/StandardSession.java,v
1.28 2002/03/01 19:37:45 craigmcc Exp $
  + * $Revision: 1.28 $
  + * $Date: 2002/03/01 19:37:45 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.io.Serializable;
  +import java.lang.reflect.Method;
   import java.security.Principal;
   import java.util.ArrayList;
   import java.util.Enumeration;
  @@ -92,7 +93,6 @@
   import org.apache.catalina.Session;
   import org.apache.catalina.SessionEvent;
   import org.apache.catalina.SessionListener;
  -import org.apache.catalina.core.StandardContext;
   import org.apache.catalina.util.Enumerator;
   import org.apache.catalina.util.StringManager;
   
  @@ -115,7 +115,7 @@
    * @author Craig R. McClanahan
    * @author Sean Legassick
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Revision: 1.27 $ $Date: 2002/01/19 01:58:24 $
  + * @version $Revision: 1.28 $ $Date: 2002/03/01 19:37:45 $
    */
   
   class StandardSession
  @@ -166,6 +166,24 @@
   
   
       /**
  +     * The <code>java.lang.Method</code> for the
  +     * <code>fireContainerEvent()</code> method of the
  +     * <code>org.apache.catalina.core.StandardContext</code> method,
  +     * if our Context implementation is of this class.  This value is
  +     * computed dynamically the first time it is needed, or after
  +     * a session reload (since it is declared transient).
  +     */
  +    private transient Method containerEventMethod = null;
  +
  +
  +    /**
  +     * The method signature for the <code>fireContainerEvent</code> method.
  +     */
  +    private static final Class containerEventTypes[] =
  +    { String.class, Object.class };
  +
  +
  +    /**
        * The time this session was created, in milliseconds since midnight,
        * January 1, 1970 GMT.
        */
  @@ -360,7 +378,7 @@
           fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
   
           // Notify interested application event listeners
  -        StandardContext context = (StandardContext) manager.getContainer();
  +        Context context = (Context) manager.getContainer();
           Object listeners[] = context.getApplicationListeners();
           if (listeners != null) {
               HttpSessionEvent event =
  @@ -371,14 +389,21 @@
                   HttpSessionListener listener =
                       (HttpSessionListener) listeners[i];
                   try {
  -                    context.fireContainerEvent("beforeSessionCreated",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "beforeSessionCreated",
  +                                       listener);
                       listener.sessionCreated(event);
  -                    context.fireContainerEvent("afterSessionCreated",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "afterSessionCreated",
  +                                       listener);
                   } catch (Throwable t) {
  -                    context.fireContainerEvent("afterSessionCreated",
  -                                               listener);
  +                    try {
  +                        fireContainerEvent(context,
  +                                           "afterSessionCreated",
  +                                           listener);
  +                    } catch (Exception e) {
  +                        ;
  +                    }
                       // FIXME - should we do anything besides log these?
                       log(sm.getString("standardSession.sessionEvent"), t);
                   }
  @@ -616,7 +641,7 @@
   
           // Notify interested application event listeners
           // FIXME - Assumes we call listeners in reverse order
  -        StandardContext context = (StandardContext) manager.getContainer();
  +        Context context = (Context) manager.getContainer();
           Object listeners[] = context.getApplicationListeners();
           if (notify && (listeners != null)) {
               HttpSessionEvent event =
  @@ -628,14 +653,21 @@
                   HttpSessionListener listener =
                       (HttpSessionListener) listeners[j];
                   try {
  -                    context.fireContainerEvent("beforeSessionDestroyed",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "beforeSessionDestroyed",
  +                                       listener);
                       listener.sessionDestroyed(event);
  -                    context.fireContainerEvent("afterSessionDestroyed",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "afterSessionDestroyed",
  +                                       listener);
                   } catch (Throwable t) {
  -                    context.fireContainerEvent("afterSessionDestroyed",
  -                                               listener);
  +                    try {
  +                        fireContainerEvent(context,
  +                                           "afterSessionDestroyed",
  +                                           listener);
  +                    } catch (Exception e) {
  +                        ;
  +                    }
                       // FIXME - should we do anything besides log these?
                       log(sm.getString("standardSession.sessionEvent"), t);
                   }
  @@ -1117,7 +1149,7 @@
               ((HttpSessionBindingListener) value).valueUnbound(event);
   
           // Notify interested application event listeners
  -        StandardContext context = (StandardContext) manager.getContainer();
  +        Context context = (Context) manager.getContainer();
           Object listeners[] = context.getApplicationListeners();
           if (listeners == null)
               return;
  @@ -1127,14 +1159,21 @@
               HttpSessionAttributeListener listener =
                   (HttpSessionAttributeListener) listeners[i];
               try {
  -                context.fireContainerEvent("beforeSessionAttributeRemoved",
  -                                           listener);
  +                fireContainerEvent(context,
  +                                   "beforeSessionAttributeRemoved",
  +                                   listener);
                   listener.attributeRemoved(event);
  -                context.fireContainerEvent("afterSessionAttributeRemoved",
  -                                           listener);
  +                fireContainerEvent(context,
  +                                   "afterSessionAttributeRemoved",
  +                                   listener);
               } catch (Throwable t) {
  -                context.fireContainerEvent("afterSessionAttributeRemoved",
  -                                           listener);
  +                try {
  +                    fireContainerEvent(context,
  +                                       "afterSessionAttributeRemoved",
  +                                       listener);
  +                } catch (Exception e) {
  +                    ;
  +                }
                   // FIXME - should we do anything besides log these?
                   log(sm.getString("standardSession.attributeEvent"), t);
               }
  @@ -1232,7 +1271,7 @@
               ((HttpSessionBindingListener) value).valueBound(event);
   
           // Notify interested application event listeners
  -        StandardContext context = (StandardContext) manager.getContainer();
  +        Context context = (Context) manager.getContainer();
           Object listeners[] = context.getApplicationListeners();
           if (listeners == null)
               return;
  @@ -1243,25 +1282,36 @@
                   (HttpSessionAttributeListener) listeners[i];
               try {
                   if (unbound != null) {
  -                    context.fireContainerEvent("beforeSessionAttributeReplaced",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "beforeSessionAttributeReplaced",
  +                                       listener);
                       listener.attributeReplaced(event);
  -                    context.fireContainerEvent("afterSessionAttributeReplaced",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "afterSessionAttributeReplaced",
  +                                       listener);
                   } else {
  -                    context.fireContainerEvent("beforeSessionAttributeAdded",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "beforeSessionAttributeAdded",
  +                                       listener);
                       listener.attributeAdded(event);
  -                    context.fireContainerEvent("afterSessionAttributeAdded",
  -                                               listener);
  +                    fireContainerEvent(context,
  +                                       "afterSessionAttributeAdded",
  +                                       listener);
                   }
               } catch (Throwable t) {
  -                if (unbound != null)
  -                    context.fireContainerEvent("afterSessionAttributeReplaced",
  -                                               listener);
  -                else
  -                    context.fireContainerEvent("afterSessionAttributeAdded",
  -                                               listener);
  +                try {
  +                    if (unbound != null) {
  +                        fireContainerEvent(context,
  +                                           "afterSessionAttributeReplaced",
  +                                           listener);
  +                    } else {
  +                        fireContainerEvent(context,
  +                                           "afterSessionAttributeAdded",
  +                                           listener);
  +                    }
  +                } catch (Exception e) {
  +                    ;
  +                }
                   // FIXME - should we do anything besides log these?
                   log(sm.getString("standardSession.attributeEvent"), t);
               }
  @@ -1398,6 +1448,39 @@
   
   
       // -------------------------------------------------------- Private Methods
  +
  +
  +    /**
  +     * Fire container events if the Context implementation is the
  +     * <code>org.apache.catalina.core.StandardContext</code>.
  +     *
  +     * @param context Context for which to fire events
  +     * @param type Event type
  +     * @param data Event data
  +     *
  +     * @exception Exception occurred during event firing
  +     */
  +    private void fireContainerEvent(Context context,
  +                                    String type, Object data)
  +        throws Exception {
  +
  +        if (!"org.apache.catalina.core.StandardContext".equals
  +            (context.getClass().getName())) {
  +            return; // Container events are not supported
  +        }
  +        // NOTE:  Race condition is harmless, so do not synchronize
  +        if (containerEventMethod == null) {
  +            containerEventMethod =
  +                context.getClass().getMethod("fireContainerEvent",
  +                                             containerEventTypes);
  +        }
  +        Object containerEventParams[] = new Object[2];
  +        containerEventParams[0] = type;
  +        containerEventParams[1] = data;
  +        containerEventMethod.invoke(context, containerEventParams);
  +
  +    }
  +                                      
   
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message