billbarker    2002/06/04 20:52:51

  Modified:    src/facade22/org/apache/tomcat/facade JspInterceptor.java
                        LoadOnStartupInterceptor.java ServletHandler.java
  Log:
  Implement preInitCheck. As discussed on tomcat-dev.
  
  postInitCheck is being left for a later commit (I've got to get my numbers up :).
  
  This passes the entire testing suite, as well as any other regression test that I 
could think of.  So I'm fairly certain that there are no regressions.  Performance 
should be much the same, since it is doing the same checks as before, only in a 
different order.
  
  However, now only people that care about recompiling JSPs get called, and not the 
other two or three that implement requestMap.
  
  Revision  Changes    Path
  1.38      +31 -31    
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- JspInterceptor.java       31 Jan 2002 03:34:10 -0000      1.37
  +++ JspInterceptor.java       5 Jun 2002 03:52:50 -0000       1.38
  @@ -362,8 +362,6 @@
            }
   
            jspServlet.setServletClassName(jspServletCN);
  -     } else {
  -         ctx.addServlet( new JspPrecompileH());
        }
   
           if( useWebAppCL ) {
  @@ -466,6 +464,20 @@
            if( jspFile==null )
                return 0; // not a jsp
        }
  +     return 0;
  +    }
  +
  +    /** Check if the JSP page needs to be re-compiled.
  +     */
  +    public int preInitCheck(Request req, Handler sw)
  +     throws TomcatException {
  +     
  +     if(sw == null || !(sw instanceof ServletHandler))
  +         return 0;
  +     ServletHandler handler = (ServletHandler)sw;
  +     String jspFile=handler.getServletInfo().getJspFile();
  +     if(jspFile == null)
  +         return 0;
   
        // if it's a jsp_precompile request, don't execute - just
        // compile ( if needed ). Since we'll compile the jsp on
  @@ -513,9 +525,8 @@
   
            // Future: detail information about compile results
            // and if indeed we had to do something or not
  -         Context ctxr = req.getContext();
  -         req.setHandler(  ctxr.
  -                          getServletByName( "tomcat.jspPrecompileHandler"));
  +         doPreCompileService(req);
  +         return 200;
        }
        
        return 0;
  @@ -569,35 +580,24 @@
        return wrapper;
       }
   
  -}
  -
  -// -------------------- Jsp_precompile handler --------------------
  -
  -/** What to do for jsp precompile
  - */
  -class JspPrecompileH extends Handler {
  -    static StringManager sm=StringManager.
  -     getManager("org.apache.tomcat.resources");
  -    
  -    JspPrecompileH() {
  -     name="tomcat.jspPrecompileHandler";
  -    }
  -
  -    public void doService(Request req, Response res)
  -     throws Exception
  -    {
  -     res.setContentType("text/html");        
  -
  -     String msg="<h1>Jsp Precompile Done</h1>";
  -
  -     res.setContentLength(msg.length());
  +    private void doPreCompileService(Request req) {
  +     Response res = req.getResponse();
  +     if( res == null || res.getBuffer() == null){
  +         return; // A load-on-startup Request
  +     }
  +     try {
  +         res.setContentType("text/html");    
   
  -     res.getBuffer().write( msg );
  +         String msg="<h1>Jsp Precompile Done</h1>";
  +         
  +         res.setContentLength(msg.length());
  +
  +         res.getBuffer().write( msg );
  +     } catch(IOException iex) {
  +         log("Pre-compile error",iex);
  +     }
       }
   }
  -
  -
  -
   
   // -------------------- The main Jasper Liaison --------------------
   
  
  
  
  1.6       +21 -1     
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/LoadOnStartupInterceptor.java
  
  Index: LoadOnStartupInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/LoadOnStartupInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LoadOnStartupInterceptor.java     11 Feb 2002 02:32:29 -0000      1.5
  +++ LoadOnStartupInterceptor.java     5 Jun 2002 03:52:50 -0000       1.6
  @@ -148,7 +148,27 @@
   
       void loadJsp( Context context, Handler result ) throws Exception {
        // A Jsp initialized in web.xml -
  -     // Moved to ServletHandler.
  +        BaseInterceptor ri[];
  +     String path=((ServletHandler)result).getServletInfo().getJspFile();
  +     String requestURI = path + "?jsp_precompile=true";
  +
  +     Request req = cm.createRequest(context, requestURI);
  +     ri=context.getContainer().
  +         getInterceptors(Container.H_preInitCheck);
  +     for( int i=0; i< ri.length; i++ ) {
  +         int status = ri[i].preInitCheck(req, result);
  +         if(status != 0) {
  +             return;
  +         }
  +     }
  +     ri=context.getContainer().
  +         getInterceptors(Container.H_postInitCheck);
  +     for( int i=0; i< ri.length; i++ ) {
  +         int status = ri[i].postInitCheck(req, result);
  +         if(status != 0) {
  +             return;
  +         }
  +     }
       }
       // -------------------- 
       // Old logic from Context - probably something cleaner can replace it.
  
  
  
  1.20      +21 -25    
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java
  
  Index: ServletHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ServletHandler.java       11 Feb 2002 02:32:29 -0000      1.19
  +++ ServletHandler.java       5 Jun 2002 03:52:50 -0000       1.20
  @@ -394,28 +394,6 @@
        }
       }
   
  -    /** Handle the case of a JSP servlet that JspInterceptor hasn't seen.
  -     *  This shouldn't be any of our business, but for the moment we have
  -     *  to help JspInterceptor out.
  -     */
  -     void loadJsp(  )  throws Exception{
  -        BaseInterceptor ri[];
  -     ContextManager cm=context.getContextManager();
  -     String path=sw.getJspFile();
  -     String requestURI = path + "?jsp_precompile=true";
  -     Request request = cm.createRequest(context, requestURI);
  -     Response response = request.getResponse();
  -     request.setHandler(this);
  -
  -     ri=context.getContainer().
  -         getInterceptors(Container.H_requestMap);
  -     for( int i=0; i< ri.length; i++ ) {
  -         if( debug > 1 )
  -             log( "RequestMap " + ri[i] );
  -         int status=ri[i].requestMap( request );
  -         if( status!=0 ) return ;
  -     }
  -    }
       // Special hook
       protected void preInit() throws Exception
       {
  @@ -428,9 +406,6 @@
            // remain in STATE_DELAYED_INIT state
            return;
        }
  -     if(sw.getJspFile() != null && 
  -        (servletClassName==null || servletClassName==name ))
  -         loadJsp();
        // clear STATE_DELAYED_INIT if set
        setState( STATE_ADDED );
        
  @@ -467,6 +442,18 @@
       public void service ( Request req, Response res )
        throws Exception
       {
  +        BaseInterceptor ri[];
  +     ri=context.getContainer().
  +         getInterceptors(Container.H_preInitCheck);
  +     for( int i=0; i< ri.length; i++ ) {
  +         int status = ri[i].preInitCheck(req, this);
  +         if(status != 0) {
  +             if(status >= 300){
  +                 contextM.handleStatus(req, res, status);
  +             }
  +             return;
  +         }
  +     }
        if( state!=STATE_READY ) {
            if( state!= STATE_DISABLED ) {
                init();
  @@ -480,6 +467,15 @@
                handleInitError( req, res, ex );
                return;
            } 
  +     }
  +     ri=context.getContainer().
  +         getInterceptors(Container.H_postInitCheck);
  +     for( int i=0; i< ri.length; i++ ) {
  +         int status = ri[i].postInitCheck(req, this);
  +         if(status != 0) {
  +             contextM.handleStatus(req, res, status);
  +             return;
  +         }
        }
   
        super.service( req, res );
  
  
  

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

Reply via email to