tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util InstanceSupport.java
Date Thu, 02 Nov 2000 23:04:50 GMT
craigmcc    00/11/02 15:04:50

  Modified:    catalina/src/share/org/apache/catalina InstanceEvent.java
               catalina/src/share/org/apache/catalina/core
                        ApplicationFilterChain.java
                        StandardWrapperValve.java
               catalina/src/share/org/apache/catalina/util
                        InstanceSupport.java
  Log:
  Extend the instance listener support to include events before and after
  individual filter instances are invoked, as well as before and after
  servlet instances are invoked.  The new event types are defined by the
  manifest constants InstanceEvent.BEFORE_FILTER_EVENT and
  InstanceEvent.AFTER_FILTER_EVENT, both of which pass the filter instance
  itself as a data object.
  
  Revision  Changes    Path
  1.2       +61 -7     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/InstanceEvent.java
  
  Index: InstanceEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/InstanceEvent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstanceEvent.java	2000/08/11 05:24:07	1.1
  +++ InstanceEvent.java	2000/11/02 23:04:48	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/InstanceEvent.java,v
1.1 2000/08/11 05:24:07 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 05:24:07 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/InstanceEvent.java,v
1.2 2000/11/02 23:04:48 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/02 23:04:48 $
    *
    * ====================================================================
    *
  @@ -66,16 +66,17 @@
   
   
   import java.util.EventObject;
  +import javax.servlet.Filter;
   import javax.servlet.Servlet;
   
   
   /**
    * General event for notifying listeners of significant events related to
  - * a specific instance of a servlet, as opposed to the Wrapper component
  - * that manages it.
  + * a specific instance of a Servlet, or a specific instance of a Filter,
  + * as opposed to the Wrapper component that manages it.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 05:24:07 $
  + * @version $Revision: 1.2 $ $Date: 2000/11/02 23:04:48 $
    */
   
   public final class InstanceEvent
  @@ -126,6 +127,22 @@
       public static final String AFTER_DESTROY_EVENT = "afterDestroy";
   
   
  +    /**
  +     * The event indicating that the <code>doFilter()</code> method of a
  +     * Filter is about to be called.  The <code>filter</code> property
  +     * contains a reference to the relevant filter instance.
  +     */
  +    public static final String BEFORE_FILTER_EVENT = "beforeFilter";
  +
  +
  +    /**
  +     * The event indicating that the <code>doFilter()</code> method of a
  +     * Filter has returned.  The <code>filter</code> property contains
  +     * a reference to the relevant filter instance.
  +     */
  +    public static final String AFTER_FILTER_EVENT = "afterFilter";
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -133,6 +150,24 @@
        * Construct a new InstanceEvent with the specified parameters.
        *
        * @param wrapper Wrapper managing this servlet instance
  +     * @param filter Filter instance for which this event occurred
  +     * @param type Event type (required)
  +     */
  +    public InstanceEvent(Wrapper wrapper, Filter filter, String type) {
  +
  +      super(wrapper);
  +      this.wrapper = wrapper;
  +      this.filter = filter;
  +      this.servlet = null;
  +      this.type = type;
  +
  +    }
  +
  +
  +    /**
  +     * Construct a new InstanceEvent with the specified parameters.
  +     *
  +     * @param wrapper Wrapper managing this servlet instance
        * @param servlet Servlet instance for which this event occurred
        * @param type Event type (required)
        */
  @@ -140,6 +175,7 @@
   
         super(wrapper);
         this.wrapper = wrapper;
  +      this.filter = null;
         this.servlet = servlet;
         this.type = type;
   
  @@ -149,8 +185,16 @@
       // ----------------------------------------------------- Instance Variables
   
   
  +    /**
  +     * The Filter instance for which this event occurred (BEFORE_FILTER_EVENT
  +     * and AFTER_FILTER_EVENT only).
  +     */
  +    private Filter filter = null;
  +
  +
       /**
  -     * The Servlet instance for which this event occurred.
  +     * The Servlet instance for which this event occurred (not present on
  +     * BEFORE_FILTER_EVENT or AFTER_FILTER_EVENT events).
        */
       private Servlet servlet = null;
   
  @@ -168,6 +212,16 @@
   
   
       // ------------------------------------------------------------- Properties
  +
  +
  +    /**
  +     * Return the filter instance for which this event occurred.
  +     */
  +    public Filter getFilter() {
  +
  +        return (this.filter);
  +
  +    }
   
   
       /**
  
  
  
  1.2       +55 -6     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
  
  Index: ApplicationFilterChain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationFilterChain.java	2000/10/22 09:55:51	1.1
  +++ ApplicationFilterChain.java	2000/11/02 23:04:49	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
1.1 2000/10/22 09:55:51 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/10/22 09:55:51 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
1.2 2000/11/02 23:04:49 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/02 23:04:49 $
    *
    * ====================================================================
    *
  @@ -68,6 +68,7 @@
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.Iterator;
  +import javax.servlet.Filter;
   import javax.servlet.FilterChain;
   import javax.servlet.FilterConfig;
   import javax.servlet.Servlet;
  @@ -76,6 +77,8 @@
   import javax.servlet.ServletResponse;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import org.apache.catalina.InstanceEvent;
  +import org.apache.catalina.util.InstanceSupport;
   import org.apache.catalina.util.StringManager;
   
   
  @@ -87,7 +90,7 @@
    * method itself.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/10/22 09:55:51 $
  + * @version $Revision: 1.2 $ $Date: 2000/11/02 23:04:49 $
    */
   
   final class ApplicationFilterChain implements FilterChain {
  @@ -136,12 +139,20 @@
         StringManager.getManager(Constants.Package);
   
   
  +    /**
  +     * The InstanceSupport instance associated with our Wrapper (used to
  +     * send "before filter" and "after filter" events.
  +     */
  +    private InstanceSupport support = null;
  +
  +
       // ---------------------------------------------------- FilterChain Methods
   
   
       /**
        * Invoke the next filter in this chain, passing the specified request
  -     * and response.
  +     * and response.  If there are no more filters in this chain, invoke
  +     * the <code>service()</code> method of the servlet itself.
        *
        * @param request The servlet request we are processing
        * @param response The servlet response we are creating
  @@ -160,13 +171,28 @@
           if (this.iterator.hasNext()) {
               ApplicationFilterConfig filterConfig =
                 (ApplicationFilterConfig) iterator.next();
  +            Filter filter = null;
               try {
  -                filterConfig.getFilter().doFilter(request, response, this);
  +                filter = filterConfig.getFilter();
  +                support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
  +                                          filter);
  +                filter.doFilter(request, response, this);
  +                support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
  +                                          filter);
               } catch (IOException e) {
  +                if (filter != null)
  +                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
  +                                              filter);
                   throw e;
               } catch (ServletException e) {
  +                if (filter != null)
  +                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
  +                                              filter);
                   throw e;
               } catch (Throwable e) {
  +                if (filter != null)
  +                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
  +                                              filter);
                   throw new ServletException
                     (sm.getString("filterChain.filter"), e);
               }
  @@ -175,17 +201,27 @@
   
           // We fell off the end of the chain -- call the servlet instance
           try {
  +            support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
  +                                      servlet);
               if ((request instanceof HttpServletRequest) &&
                   (response instanceof HttpServletResponse))
                   servlet.service((HttpServletRequest) request,
                                   (HttpServletResponse) response);
               else
                   servlet.service(request, response);
  +            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  +                                      servlet);
           } catch (IOException e) {
  +            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  +                                      servlet);
               throw e;
           } catch (ServletException e) {
  +            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  +                                      servlet);
               throw e;
           } catch (Throwable e) {
  +            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  +                                      servlet);
               throw new ServletException
                 (sm.getString("filterChain.servlet"), e);
           }
  @@ -229,6 +265,19 @@
       void setServlet(Servlet servlet) {
   
           this.servlet = servlet;
  +
  +    }
  +
  +
  +    /**
  +     * Set the InstanceSupport object used for event notifications
  +     * for this filter chain.
  +     *
  +     * @param support The InstanceSupport object for our Wrapper
  +     */
  +    void setSupport(InstanceSupport support) {
  +
  +        this.support = support;
   
       }
   
  
  
  
  1.14      +6 -19     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StandardWrapperValve.java	2000/10/22 09:55:52	1.13
  +++ StandardWrapperValve.java	2000/11/02 23:04:49	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.13 2000/10/22 09:55:52 craigmcc Exp $
  - * $Revision: 1.13 $
  - * $Date: 2000/10/22 09:55:52 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.14 2000/11/02 23:04:49 craigmcc Exp $
  + * $Revision: 1.14 $
  + * $Date: 2000/11/02 23:04:49 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,6 @@
   import org.apache.catalina.Globals;
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.HttpResponse;
  -import org.apache.catalina.InstanceEvent;
   import org.apache.catalina.Logger;
   import org.apache.catalina.Request;
   import org.apache.catalina.Response;
  @@ -102,7 +101,7 @@
    * <code>StandardWrapper</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.13 $ $Date: 2000/10/22 09:55:52 $
  + * @version $Revision: 1.14 $ $Date: 2000/11/02 23:04:49 $
    */
   
   final class StandardWrapperValve
  @@ -171,7 +170,6 @@
   	boolean unavailable = false;
   	Throwable throwable = null;
   	StandardWrapper wrapper = (StandardWrapper) getContainer();
  -	InstanceSupport support = wrapper.getInstanceSupport();
   	ServletRequest sreq = request.getRequest();
   	ServletResponse sres = response.getResponse();
   	Servlet servlet = null;
  @@ -250,37 +248,25 @@
           // NOTE: This also calls the servlet's service() method
   	try {
   	    if ((servlet != null) && (filterChain != null)) {
  -		support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
  -					  servlet);
                   filterChain.doFilter(sreq, sres);
  -		support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  -					  servlet);
   	    }
   	} catch (IOException e) {
  -	    support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  -				      servlet);
   	    log(sm.getString("standardWrapper.serviceException",
   			     wrapper.getName()), e);
   	    ;	// No reporting to the response
   	    ;	// No change in availability status
   	} catch (UnavailableException e) {
  -	    support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  -				      servlet);
   	    log(sm.getString("standardWrapper.serviceException",
   			     wrapper.getName()), e);
   	    throwable = e;
   	    exception(request, response, e);
   	    wrapper.unavailable(e);
   	} catch (ServletException e) {
  -	    support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  -				      servlet);
   	    log(sm.getString("standardWrapper.serviceException",
   			     wrapper.getName()), e);
   	    throwable = e;
   	    exception(request, response, e);
   	} catch (Throwable e) {
  -	    support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
  -				      servlet);
   	    log(sm.getString("standardWrapper.serviceException",
   			     wrapper.getName()), e);
   	    throwable = e;
  @@ -347,9 +333,10 @@
           ApplicationFilterChain filterChain =
             new ApplicationFilterChain();
           filterChain.setServlet(servlet);
  +        StandardWrapper wrapper = (StandardWrapper) getContainer();
  +        filterChain.setSupport(wrapper.getInstanceSupport());
   
           // Acquire the filter mappings for this Context
  -        Wrapper wrapper = (Wrapper) getContainer();
           StandardContext context = (StandardContext) wrapper.getParent();
           FilterMap filterMaps[] = context.findFilterMaps();
   
  
  
  
  1.2       +45 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java
  
  Index: InstanceSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstanceSupport.java	2000/08/11 17:01:50	1.1
  +++ InstanceSupport.java	2000/11/02 23:04:50	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java,v
1.1 2000/08/11 17:01:50 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 17:01:50 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java,v
1.2 2000/11/02 23:04:50 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/02 23:04:50 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   package org.apache.catalina.util;
   
   
  +import javax.servlet.Filter;
   import javax.servlet.Servlet;
   import org.apache.catalina.InstanceEvent;
   import org.apache.catalina.InstanceListener;
  @@ -76,7 +77,7 @@
    * registered InstanceListeners.
    *
    * @author Craig R. McClanahan
  - * @version $Id: InstanceSupport.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
  + * @version $Id: InstanceSupport.java,v 1.2 2000/11/02 23:04:50 craigmcc Exp $
    */
   
   public final class InstanceSupport {
  @@ -115,6 +116,19 @@
       private Wrapper wrapper = null;
   
   
  +    // ------------------------------------------------------------- Properties
  +
  +
  +    /**
  +     * Return the Wrapper with which we are associated.
  +     */
  +    public Wrapper getWrapper() {
  +
  +        return (this.wrapper);
  +
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -143,9 +157,36 @@
        * this notification synchronously using the calling thread.
        *
        * @param type Event type
  -     * @param data Event data
  +     * @param filter The relevant Filter for this event
        */
  +    public void fireInstanceEvent(String type, Filter filter) {
  +
  +        if (listeners.length == 0)
  +            return;
  +
  +	InstanceEvent event = new InstanceEvent(wrapper, filter, type);
  +	InstanceListener interested[] = null;
  +	synchronized (listeners) {
  +	    interested = (InstanceListener[]) listeners.clone();
  +	}
  +	for (int i = 0; i < interested.length; i++)
  +	    interested[i].instanceEvent(event);
  +
  +    }
  +
  +
  +    /**
  +     * Notify all lifecycle event listeners that a particular event has
  +     * occurred for this Container.  The default implementation performs
  +     * this notification synchronously using the calling thread.
  +     *
  +     * @param type Event type
  +     * @param servlet The relevant Servlet for this event
  +     */
       public void fireInstanceEvent(String type, Servlet servlet) {
  +
  +        if (listeners.length == 0)
  +            return;
   
   	InstanceEvent event = new InstanceEvent(wrapper, servlet, type);
   	InstanceListener interested[] = null;
  
  
  

Mime
View raw message