tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/request InvokerInterceptor.java JspInterceptor.java
Date Wed, 23 Aug 2000 06:53:14 GMT
costin      00/08/22 23:53:14

  Modified:    .        build.xml
               src/facade22/org/apache/tomcat/facade Servlet22Manager.java
                        ServletWrapper.java
               src/facade23/org/apache/tomcat/facade23
                        Servlet23Manager.java ServletWrapper.java
               src/share/org/apache/tomcat/context
                        LoadOnStartupInterceptor.java WebXmlReader.java
               src/share/org/apache/tomcat/core Context.java
                        FacadeManager.java Handler.java
               src/share/org/apache/tomcat/request InvokerInterceptor.java
  Added:       src/facade22/org/apache/tomcat/modules/facade22
                        JspInterceptor.java
               src/facade23 README
  Removed:     src/share/org/apache/tomcat/facade
                        HttpServletRequestFacade.java
                        HttpServletResponseFacade.java
                        HttpSessionFacade.java RequestDispatcherImpl.java
                        Servlet22Manager.java ServletConfigImpl.java
                        ServletContextFacade.java
                        ServletInputStreamFacade.java
                        ServletOutputStreamFacade.java ServletWrapper.java
                        ServletWriterFacade.java SessionContextImpl.java
                        package.html
               src/share/org/apache/tomcat/request JspInterceptor.java
  Log:
  - Moved tomcat/facade in a separate module ( src/facade22 ).
  
  - Changed build.xml to acomodate this.
  
  - fixed the code to remove all remaining dependencies.
  
  JspInterceptor is moved to facade22, it has too many deps
  on jasper and servlet22. I'll spend some more time on this
  when jsp1.2 implementation is available.
  
  WarInterceptor is also dependent on servlet2.2, but
  no compile deps - it should also be moved to facade22/../modules
  
  Revision  Changes    Path
  1.72      +8 -1      jakarta-tomcat/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/build.xml,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- build.xml	2000/08/23 04:06:42	1.71
  +++ build.xml	2000/08/23 06:53:04	1.72
  @@ -215,7 +215,7 @@
         debug="${debug}" 
         optimize="${optimize}"
         deprecation="off"
  -      srcdir="src/share" >
  +      srcdir="src/facade22" >
         <classpath>
   	<pathelement location="${servlet22.jar}" />
   	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
  @@ -331,6 +331,13 @@
         <exclude name="**/SSLSocketFactory.java"
   	unless="jsse.present" />
       </javac>
  +    <javac srcdir="src/facade22" destdir="${tomcat.build}/classes"
  +      classpath="${servlet.jar};${jaxp}/jaxp.jar" 
  +      debug="${debug}" 
  +      optimize="${optimize}"
  +      deprecation="off" >
  +    </javac>
  +
       <copydir src="src/share" dest="${tomcat.build}/classes"
         excludes="javax/**">
         <include name="**/*.properties" />
  
  
  
  1.2       +6 -0      jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Manager.java
  
  Index: Servlet22Manager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Manager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Servlet22Manager.java	2000/08/23 05:39:20	1.1
  +++ Servlet22Manager.java	2000/08/23 06:53:05	1.2
  @@ -101,6 +101,12 @@
   	this.ctx=ctx;
       }
   
  +    /** Create a new handler
  +     */
  +    public Handler createHandler() {
  +	return new ServletWrapper();
  +    }
  +
       public ServletContext createServletContextFacade(Context ctx) {
   	//if( ctx != this.ctx ) return null; // throw
   	return new ServletContextFacade(ctx.getContextManager() , ctx);
  
  
  
  1.2       +4 -10     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletWrapper.java	2000/08/23 05:39:20	1.1
  +++ ServletWrapper.java	2000/08/23 06:53:05	1.2
  @@ -78,9 +78,6 @@
    */
   public class ServletWrapper extends Handler {
   
  -    // servletName is stored in config!
  -    protected String servletName;
  -    protected String servletClassName; // required
       protected Class servletClass;
   
       protected Servlet servlet;
  @@ -88,8 +85,8 @@
       // facade
       protected ServletConfig configF;
   
  -    // Jsp pages
  -    private String path = null;
  +    //     // Jsp pages
  +    //     private String path = null;
   
       // optional informations
       protected String description = null;
  @@ -107,7 +104,7 @@
       protected long lastAccessed;
       protected int serviceCount = 0;
       
  -    int loadOnStartup=0;
  +    //    int loadOnStartup=0;
   
       Hashtable securityRoleRefs=new Hashtable();
   
  @@ -176,11 +173,9 @@
       }
   
       public void setServletClass(String servletClassName) {
  -	if( name==null ) name=servletClassName;
  -	this.servletClassName = servletClassName;
  +	super.setServletClass( servletClassName );
   	servlet=null; // reset the servlet, if it was set
   	servletClass=null;
  -	initialized=false;
       }
   
       public void reload() {
  @@ -213,7 +208,6 @@
       }
   
       // -------------------- Jsp specific code
  -    // Will go in JspHandler
       
       public String getPath() {
           return this.path;
  
  
  
  1.1                  jakarta-tomcat/src/facade22/org/apache/tomcat/modules/facade22/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 apache@apache.org.
   *
   * 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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  package org.apache.tomcat.modules.facade22;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  import javax.servlet.jsp.HttpJspPage;
  import javax.servlet.jsp.JspFactory;
  
  import java.util.*;
  import java.io.*;
  import java.net.*;
  
  import org.apache.jasper.*;
  import org.apache.jasper.Constants;
  import org.apache.jasper.runtime.*;
  import org.apache.jasper.compiler.*;
  import org.apache.tomcat.logging.Logger;
  import org.apache.jasper.compiler.Compiler;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.facade.ServletWrapper;
  
  /**
   * Plug in the JSP engine (a.k.a Jasper)! 
   *
   * @author Anil K. Vijendran
   * @author Harish Prabandham
   * @author Costin Manolache
   */
  public class JspInterceptor extends BaseInterceptor {
      int jspInfoNOTE;
  
      public void engineInit(ContextManager cm )
  	throws TomcatException
      {
  	super.engineInit(cm);
  	jspInfoNOTE=cm.getNoteId( ContextManager.HANDLER_NOTE,
  				  "tomcat.jspInfoNote");
      }
      
      public void contextInit(Context ctx)
  	throws TomcatException 
      {
  	JspFactory.setDefaultFactory(new JspFactoryImpl());
  	try {
  	    ctx.addClassPath( new URL( "file", null,
  					ctx.getWorkDir().getAbsolutePath()));
  	} catch( MalformedURLException ex ) {
  	}
      }
  
      public void preServletInit( Context ctx, Handler sw )
  	throws TomcatException
      {
  	Servlet theServlet = ((ServletWrapper)sw).getServlet();
  	if (theServlet instanceof HttpJspBase)  {
  	    if( debug > 0 )
  		log( "PreServletInit: HttpJspBase.setParentClassLoader" + sw );
  	    HttpJspBase h = (HttpJspBase) theServlet;
  	    h.setClassLoader(ctx.getClassLoader());
  	}
      }
  
      public int requestMap( Request req ) {
  	ServletWrapper wrapper=(ServletWrapper)req.getWrapper();
  	if( wrapper!=null && ! "jsp".equals( wrapper.getName())
  	    && wrapper.getPath() == null)
  	    return 0;
  
  	// XXX jsp handler is still needed
  	if( wrapper==null )
  	    return 0;
  	
  	Context ctx= req.getContext();
  
  	// If this Wrapper was already used, we have all the info
  	JspInfo jspInfo=(JspInfo)wrapper.getNote( jspInfoNOTE );
  	if( jspInfo == null ) {
  	    if( debug > 0 ) log("New jsp page - no jspInfo ");
  	    jspInfo=new JspInfo(req);
  	    mapJspPage( req, jspInfo, jspInfo.uri, jspInfo.fullClassN);
  	}
  
  	if( jspInfo.jspSource.lastModified() 
  	    > jspInfo.compileTime ) {
  	    //XXX 	    destroy();
  	    
  	    // jump version number - the file needs to
  	    // be recompiled, and we don't want a reload
  	    jspInfo.nextVersion();
  	    compile( req, jspInfo );
  	    mapJspPage( req , jspInfo, jspInfo.uri, jspInfo.fullClassN);
  	}
  
  	return 0;
      }
  
      /** Add an exact map that will avoid *.jsp mapping and intermediate
       *  steps
       */
      void mapJspPage( Request req, JspInfo jspInfo,
  		     String servletName, String classN )
      {
  	Context ctx=req.getContext();
  	ServletWrapper wrapper=null;
  	String servletPath=servletName;
  	// add the mapping - it's a "invoker" map ( i.e. it
  	// can be removed to keep memory under control.
  	// The memory usage is smaller than JspSerlvet anyway, but
  	// can be further improved.
  	try {
  	    wrapper=(ServletWrapper)ctx.getServletByName( servletName );
  	    // We may want to replace the class and reset it if changed
  	    
  	    if( wrapper==null ) {
  		wrapper=new ServletWrapper();
  		wrapper.setContext(ctx);
  		wrapper.setServletName(servletName);
  		wrapper.setPath(classN);
  		wrapper.setOrigin( Handler.ORIGIN_INVOKER );
  		ctx.addServlet( wrapper );
  		
  		ctx.addServletMapping( servletPath ,
  				       servletPath );
  		log( "Added mapping " + servletPath +
  		     " path=" + servletPath );
  	    }
  	    wrapper.setServletClass( classN );
  	    
  	    wrapper.setNote( jspInfoNOTE, jspInfo );
  	} catch( TomcatException ex ) {
  	    log("mapJspPage: request=" + req + ", jspInfo=" + jspInfo + ", servletName=" + servletName
+ ", classN=" + classN, ex);
  	    return ;
  	}
  	req.setWrapper( wrapper );
  	if( debug>0) log("Wrapper " + wrapper);
      }
  
      /** Convert the .jsp file to a java file, then compile it to class
       */
      void compile(Request req, JspInfo jspInfo ) {
  	log( "Compiling " + jspInfo.realClassPath);
  	try {
  	    // make sure we have the directories
  	    File dir=new File( jspInfo.outputDir + "/" + jspInfo.pkgDir);
  	    dir.mkdirs();
  	    
  	    JspMangler mangler= new JspMangler(jspInfo);
  	    TomcatOptions options=new TomcatOptions();
  	    JspEngineContext1 ctxt = new JspEngineContext1(req, mangler);
  	    ctxt.setOptions( options );
  	    
  	    Compiler compiler=new Compiler(ctxt);
  	    compiler.setMangler( mangler );
  		
  	    // we will compile ourself
  	    compiler.setJavaCompiler( null );
  	    
  	    synchronized ( this ) {
  		compiler.compile();
  	    }
  	    
  	    javac( createJavaCompiler( options ), ctxt, mangler );
  	    
  	    if(debug>0)log( "Compiled to " + jspInfo.realClassPath );
  	    jspInfo.touch();
  	} catch( Exception ex ) {
  	    log("compile: req="+req+", jspInfo=" + jspInfo, ex);
  	}
      }
      
      String javaEncoding = "UTF8";           // perhaps debatable?
      static String sep = System.getProperty("path.separator");
  
      static String getClassPath( Context ctx ) {
  	URL classP[]=ctx.getClassPath();
  	String separator = System.getProperty("path.separator", ":");
          String cpath = "";
  	
          for(int i=0; i< classP.length; i++ ) {
              URL cp = classP[i];
              File f = new File( cp.getFile());
              if (cpath.length()>0) cpath += separator;
              cpath += f;
          }
  	return cpath;
      }
      
      /** Compile a java to class. This should be moved to util, togheter
  	with JavaCompiler - it's a general purpose code, no need to
  	keep it part of jasper
      */
      public void javac(JavaCompiler javac, JspEngineContext1 ctxt,
  		      Mangler mangler)
  	throws JasperException
      {
  
          javac.setEncoding(javaEncoding);
  	String cp=System.getProperty("java.class.path")+ sep + 
  	    ctxt.getClassPath() + sep + ctxt.getOutputDir();
          javac.setClasspath( cp );
  	if( debug>0) log( "ClassPath " + cp);
  	
  	ByteArrayOutputStream out = new ByteArrayOutputStream (256);
  	javac.setOutputDir(ctxt.getOutputDir());
          javac.setMsgOutput(out);
  
  	String javaFileName = mangler.getJavaFileName();
  	/**
           * Execute the compiler
           */
          boolean status = javac.compile(javaFileName);
  
          if (!ctxt.keepGenerated()) {
              File javaFile = new File(javaFileName);
              javaFile.delete();
          }
      
          if (status == false) {
              String msg = out.toString ();
              throw new JasperException("Unable to compile "
                                        + msg);
          }
      }
  
      /** tool for customizing javac
       */
      public JavaCompiler createJavaCompiler(Options options)
  	throws JasperException
      {
  	String compilerPath = options.getJspCompilerPath();
  	Class jspCompilerPlugin = options.getJspCompilerPlugin();
          JavaCompiler javac;
  
  	if (jspCompilerPlugin != null) {
              try {
                  javac = (JavaCompiler) jspCompilerPlugin.newInstance();
              } catch (Exception ex) {
  		Constants.message("jsp.warning.compiler.class.cantcreate",
  				  new Object[] { jspCompilerPlugin, ex }, 
  				  Logger.FATAL);
                  javac = new SunJavaCompiler();
  	    }
  	} else {
              javac = new SunJavaCompiler();
  	}
  
          if (compilerPath != null)
              javac.setCompilerPath(compilerPath);
  
  	return javac;
      }
  
      // XXX need to implement precompile
      private void precompile() {
  	//         String qString = request.getQueryString();
  	//          if (qString != null &&
  	// 		 (qString.startsWith(Constants.PRECOMPILE) ||
  	// 		  qString.indexOf("&" + Constants.PRECOMPILE)
  	// 		  != -1))
  	//             precompile = true;
      }
  
  }
  
  /** Given a URL, generate pkg, class name, etc.
      This is an internal ( private ) object, we'll add get/set
      later ( after we pass the experimental stage) 
   */
  class JspInfo {
      Request request;
      
      String uri; // path 
  
      int version; // version
  
      String pkg;
      String pkgDir;
      String baseClassN;
      String fullClassN; // package.classN
      String classN; // no package
      String ext;
  
      String outputDir;
      String javaFilePath; // full path to the generated java file
      String realClassPath; // full path to the compiled java class
      String mapPath; // In even of server reload, keep last version
  
      File jspSource; // used to avoid File allocation for lastModified
      long compileTime;// tstamp - avoid one extra access
  
      JspInfo( Request req ) {
  	init( req );
      }
  
      public String toString() {
  	return uri +" " + version;
      }  
  
      /** Update compile time
       */
      public void touch() {
  	compileTime=System.currentTimeMillis();
      }
  
      /** A change was detected, move to a new class name
       */
      public void nextVersion() {
  	version++;
  	updateVersionedPaths();
      }
  
      /** Update all paths that contain version number
       */
      void updateVersionedPaths() {
  	classN = baseClassN + "_" + version;
  	realClassPath = outputDir + "/" + pkgDir + "/" +
  	    classN + ".class";
  	javaFilePath = outputDir + "/" + pkgDir + "/" +
  	    classN + ".java";
  	fullClassN = pkg +"." + classN;
  	
  // 	log("ClassN=" + classN +
  // 			   " realClassPath=" + realClassPath +
  // 			   " javaFilePath=" + javaFilePath +
  // 			   " fullClassN =" + fullClassN);
  	writeVersion();
  	// save to mapFile 
      }
  
      /** Compute various names used
       */
      void init(Request req ) {
  	this.request = req;
  	// 	String includeUri 
  	// 	    = (String) req.getAttribute(Constants.INC_SERVLET_PATH);
  	uri=req.getServletPath();
  	Context ctx=req.getContext();
  	outputDir = ctx.getWorkDir().getAbsolutePath();
  	String jspFilePath=ctx.getRealPath( uri );
  	jspSource = new File(jspFilePath);
  	
  	// extension
  	int lastComp=uri.lastIndexOf(  "/" );
  	String endUnproc=null;
  	if( lastComp > 0 ) {
  	    // has package
  	    pkgDir=uri.substring( 1, lastComp );
  	    endUnproc=uri.substring( lastComp+1 );
  	} else {
  	    endUnproc=uri.substring( 1 );
  	}
  
  	if( pkgDir!=null ) {
  	    pkgDir=pkgDir.replace('.', '_');
  	    pkg=pkgDir.replace('/', '.');
  	    //	    pkgDir=pkgDir.replace('/', File.separator );
  	}
  	
  	int extIdx=endUnproc.lastIndexOf( "." );
  
  	if( extIdx>=0 ) {
  	    baseClassN=endUnproc.substring( 0, extIdx );
  	    ext=endUnproc.substring( extIdx );
  	} else {
  	    baseClassN=endUnproc;
  	}
  	// XXX insert "mangle" to make names safer
  
  	mapPath = outputDir + "/" + pkgDir + "/" + baseClassN + ".ver";
  	File mapFile=new File(mapPath);
  	if( mapFile.exists() ) {
  	    // read version from file
  	    readVersion();
  	    updateVersionedPaths();
  	    updateCompileTime();
  	} else {
  	    version=0;
  	    updateVersionedPaths();
  	}
  
  // 	log("uri=" + uri +
  // 			   //" outputDir=" + outputDir +
  // 			   //" jspSource=" + jspSource +
  // 			   " pkgDir=" + pkgDir +
  // 			   " baseClassN=" + baseClassN +
  // 			   " ext=" + ext +
  // 			   " mapPath=" + mapPath +
  // 			   " version=" + version);
  	
  	
      }
      
      /** After startup we try to find if the file was precompiled
  	before
      */
      void readVersion() {
  	File mapFile=new File(mapPath);
  	version=0;
  	compileTime=0;
  	try {
  	    FileInputStream fis=new FileInputStream( mapFile );
  	    version=(int)fis.read();
  // 	    log("Version=" + version );
  	    fis.close();
  	} catch( Exception ex ) {
  	    log("readVersion() mapPath=" + mapPath, ex);
  	}
      }
  
      /** After we compile a page, we save the version in a
  	file with known name, so we can restore the state when we
  	restart. Note that this should move to a general-purpose
  	persist repository ( on my plans for next version of tomcat )
      */
      void writeVersion() {
  	File mapFile=new File(mapPath);
  	try {
  	    FileOutputStream fis=new FileOutputStream( mapFile );
  	    fis.write(version);
  // 	    log("WVersion=" + version );
  	    fis.close();
  	} catch( Exception ex ) {
  	    log("writeVersion() mapPath=" + mapPath, ex);
  	}
      }
  
      /** After a startup we read the compile time from the class
  	file lastModified. No further access to that file is done.
      */
      void updateCompileTime() {
  	File f=new File( realClassPath );
  	compileTime=0;
  	if( ! f.exists() ) return;
  	compileTime=f.lastModified();
      }
  
      void log(String s) {
  	if (request != null && request.getContext() != null) {
  	    request.getContext().log(s);
  	}
  	else {
  	    System.err.println(s);
  	}
      }
  
      void log(String s, Exception e) {
  	if (request != null && request.getContext() != null) {
  	    request.getContext().log(s, e);
  	}
  	else {
  	    System.err.println(s);
  	    e.printStackTrace();
  	}
      }
  }
  
  // XXX add code to set the options
  class TomcatOptions implements Options {
      public boolean keepGenerated = true;
      public boolean largeFile = false;
      public boolean mappedFile = false;
      public boolean sendErrorToClient = false;
      public String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
      public Class jspCompilerPlugin = null;
      public String jspCompilerPath = null;
  
      public File scratchDir;
      private Object protectionDomain;
      public String classpath = null;
  
      public boolean getKeepGenerated() {
          return keepGenerated;
      }
  
      public boolean getLargeFile() {
          return largeFile;
      }
  
      public boolean getMappedFile() {
          return mappedFile;
      }
      
      public boolean getSendErrorToClient() {
          return sendErrorToClient;
      }
   
      public String getIeClassId() {
          return ieClassId;
      }
  
      public void setScratchDir( File f ) {
  	scratchDir=f;
      }
      
      public File getScratchDir() {
  	log("Options: getScratchDir " + scratchDir);
          return scratchDir;
      }
  
      public final Object getProtectionDomain() {
  	log("Options: GetPD" );
  	return protectionDomain;
      }
  
      public String getClassPath() {
  	log("Options: GetCP " + classpath  );
          return classpath;
      }
  
      public Class getJspCompilerPlugin() {
          return jspCompilerPlugin;
      }
  
      public String getJspCompilerPath() {
          return jspCompilerPath;
      }
  
      void log(String s) {
  	System.err.println(s);
      }
      
  }
  
  
  class JspEngineContext1 implements JspCompilationContext {
      JspReader reader;
      ServletWriter writer;
      ServletContext context;
      JspLoader loader;
      String classpath; // for compiling JSPs.
      boolean isErrPage;
      String jspFile;
      String servletClassName;
      String servletPackageName;
      String servletJavaFileName;
      String contentType;
      Options options;
  
      Request req;
      Mangler m;
      
      public JspEngineContext1(Request req, Mangler m)
      {
  	this.req=req;
  	this.m=m;
      }
  
      public HttpServletRequest getRequest() {
  	log("JspEngineContext1: getRequest " + req );
          return req.getFacade();
      }
      
  
      /**
       * Get the http response we are using now...
       */
      public HttpServletResponse getResponse() {
  	log("JspEngineContext1: getResponse " );
          return req.getResponse().getFacade();
      }
  
      /**
       * The classpath that is passed off to the Java compiler. 
       */
      public String getClassPath() {
  	log("JspEngineContext1: getClassPath " +
  	    JspInterceptor.getClassPath(req.getContext()));
  	return JspInterceptor.getClassPath(req.getContext());
      }
      
      /**
       * Get the input reader for the JSP text. 
       */
      public JspReader getReader() {
  	log("JspEngineContext1: getReader " + reader );
          return reader;
      }
      
      /**
       * Where is the servlet being generated?
       */
      public ServletWriter getWriter() {
  	log("JspEngineContext1: getWriter " + writer );
          return writer;
      }
      
      /**
       * Get the ServletContext for the JSP we're processing now. 
       */
      public ServletContext getServletContext() {
  	log("JspEngineContext1: getCtx " +
  			   req.getContext().getFacade());
          return req.getContext().getFacade();
      }
      
      /**
       * What class loader to use for loading classes while compiling
       * this JSP? I don't think this is used right now -- akv. 
       */
      public ClassLoader getClassLoader() {
  	log("JspEngineContext1: getLoader " + loader );
          return req.getContext().getClassLoader();
      }
  
      public void addJar( String jar ) throws IOException {
  	log("Add jar " + jar);
  	//loader.addJar( jar );
      }
  
      /**
       * Are we processing something that has been declared as an
       * errorpage? 
       */
      public boolean isErrorPage() {
  	log("JspEngineContext1: isErrorPage " + isErrPage );
          return isErrPage;
      }
      
      /**
       * What is the scratch directory we are generating code into?
       * FIXME: In some places this is called scratchDir and in some
       * other places it is called outputDir.
       */
      public String getOutputDir() {
  	log("JspEngineContext1: getOutputDir " +
  			   req.getContext().getWorkDir().getAbsolutePath());
          return req.getContext().getWorkDir().getAbsolutePath();
      }
      
      /**
       * Path of the JSP URI. Note that this is not a file name. This is
       * the context rooted URI of the JSP file. 
       */
      public String getJspFile() {
  	String sP=req.getServletPath();
  	Context ctx=req.getContext();
  	log("JspEngineContext1: getJspFile " +
  			   sP);//   ctx.getRealPath( sP ) );
  	//        return ctx.getRealPath( sP );
  	return sP;
      }
      
      /**
       * Just the class name (does not include package name) of the
       * generated class. 
       */
      public String getServletClassName() {
  	log("JspEngineContext1: getServletClassName " +
  			   m.getClassName());
          return m.getClassName();
      }
      
      /**
       * The package name into which the servlet class is generated. 
       */
      public String getServletPackageName() {
  	log("JspEngineContext1: getServletPackageName " +
  			   servletPackageName );
          return servletPackageName;
      }
  
      /**
       * Utility method to get the full class name from the package and
       * class name. 
       */
      public final String getFullClassName() {
  	log("JspEngineContext1: getServletPackageName " +
  			   servletPackageName + "." + servletClassName);
          if (servletPackageName == null)
              return servletClassName;
          return servletPackageName + "." + servletClassName;
      }
  
      /**
       * Full path name of the Java file into which the servlet is being
       * generated. 
       */
      public String getServletJavaFileName() {
  	log("JspEngineContext1: getServletPackageName " +
  			   servletPackageName + "." + servletClassName);
          return servletJavaFileName;
      }
  
      /**
       * Are we keeping generated code around?
       */
      public boolean keepGenerated() {
          return options.getKeepGenerated();
      }
  
      /**
       * What's the content type of this JSP? Content type includes
       * content type and encoding. 
       */
      public String getContentType() {
          return contentType;
      }
  
      /**
       * Get hold of the Options object for this context. 
       */
      public Options getOptions() {
          return options;
      }
  
      public void setOptions(Options options) {
  	this.options=options;
      }
      
      public void setContentType(String contentType) {
          this.contentType = contentType;
      }
  
      public void setReader(JspReader reader) {
          this.reader = reader;
      }
      
      public void setWriter(ServletWriter writer) {
          this.writer = writer;
      }
      
      public void setServletClassName(String servletClassName) {
          this.servletClassName = servletClassName;
      }
      
      public void setServletPackageName(String servletPackageName) {
          this.servletPackageName = servletPackageName;
      }
      
      public void setServletJavaFileName(String servletJavaFileName) {
          this.servletJavaFileName = servletJavaFileName;
      }
      
      public void setErrorPage(boolean isErrPage) {
          this.isErrPage = isErrPage;
      }
  
      public Compiler createCompiler() throws JasperException {
  	log("JspEngineContext1: createCompiler ");
  	return null;
      }
      
      public String resolveRelativeUri(String uri)
      {
  	log("JspEngineContext1: resolveRelativeUri " + uri);
  	return null;
      };    
  
      public java.io.InputStream getResourceAsStream(String res)
      {
  	log("JspEngineContext1: getRAS " + res);
          return req.getContext().getFacade().getResourceAsStream(res);
      };
  
      /** 
       * Gets the actual path of a URI relative to the context of
       * the compilation.
       */
      public String getRealPath(String path)
      {
  	log("GetRP " + path + " " +
  			   req.getContext().getRealPath(path));
  	return req.getContext().getRealPath(path);
      };
  
      void log(String s, Exception e) {
  	if (this.req != null && this.req.getContext() != null) {
  	    this.req.getContext().log(s, e);
  	}
  	else {
  	    System.err.println(s);
  	    e.printStackTrace();
  	}
      }
  
      void log(String s) {
  	if (req != null && req.getContext() != null) {
  	    req.getContext().log(s);
  	}
  	else {
  	    System.err.println(s);
  	}
      }
  
  }
  
  
  class JspMangler implements Mangler{
      JspInfo jspInfo;
      
      public JspMangler(JspInfo info)  {
  	this.jspInfo=info;
      }
  
      public final String getClassName() {
          return jspInfo.classN;
      }
  
      public final String getJavaFileName() {
  	return jspInfo.javaFilePath;
      }
  
      public final String getPackageName() {
  	return jspInfo.pkg;
  	// It's not used, and shouldn't be used by compiler.
  	// ( well, it's used to rename the file after compile
  	// in JspServlet scheme - that must be out of compiler )
      }
  
      // Full path to the class file - without version.
      public final String getClassFileName() {
  	return null; // see getPackageName comment
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat/src/facade23/README
  
  Index: README
  ===================================================================
  How to build tomcat with servlet 2.3 ( in order to implement it).
  
  - get javax.servlet 
  
         cvs co -r SERVLET_23_JSP_12 jakarta-servletapi; 
         ant  -Dservletapi.build=../build/servletapi23 -Dservletapi.dist=../dist/servletapi23
dist 
  
  - build it
  
  - edit build.xml, uncomment the 2 lines ( setting servlet23.jar and servlet.jar to point
to
  the new jar )
  
  - use "ant tomcat-new" to build each individual module
  
  So far the facade is identical with 2.2 facade, all new functionality
  must be implemented ( and preferebly most code rewritten ).
  
  Good luck!
  
  
  1.2       +6 -0      jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/Servlet23Manager.java
  
  Index: Servlet23Manager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/Servlet23Manager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Servlet23Manager.java	2000/08/23 04:06:42	1.1
  +++ Servlet23Manager.java	2000/08/23 06:53:06	1.2
  @@ -100,6 +100,12 @@
   	this.ctx=ctx;
       }
   
  +    /** Create a new handler
  +     */
  +    public Handler createHandler() {
  +	return new ServletWrapper();
  +    }
  +
       public ServletContext createServletContextFacade(Context ctx) {
   	//if( ctx != this.ctx ) return null; // throw
   	return new ServletContextFacade(ctx.getContextManager() , ctx);
  
  
  
  1.2       +4 -10     jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/ServletWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletWrapper.java	2000/08/23 04:06:42	1.1
  +++ ServletWrapper.java	2000/08/23 06:53:06	1.2
  @@ -78,9 +78,6 @@
    */
   public class ServletWrapper extends Handler {
   
  -    // servletName is stored in config!
  -    protected String servletName;
  -    protected String servletClassName; // required
       protected Class servletClass;
   
       protected Servlet servlet;
  @@ -88,8 +85,8 @@
       // facade
       protected ServletConfig configF;
   
  -    // Jsp pages
  -    private String path = null;
  +    //     // Jsp pages
  +    //     private String path = null;
   
       // optional informations
       protected String description = null;
  @@ -107,7 +104,7 @@
       protected long lastAccessed;
       protected int serviceCount = 0;
       
  -    int loadOnStartup=0;
  +    //    int loadOnStartup=0;
   
       Hashtable securityRoleRefs=new Hashtable();
   
  @@ -176,11 +173,9 @@
       }
   
       public void setServletClass(String servletClassName) {
  -	if( name==null ) name=servletClassName;
  -	this.servletClassName = servletClassName;
  +	super.setServletClass( servletClassName );
   	servlet=null; // reset the servlet, if it was set
   	servletClass=null;
  -	initialized=false;
       }
   
       public void reload() {
  @@ -213,7 +208,6 @@
       }
   
       // -------------------- Jsp specific code
  -    // Will go in JspHandler
       
       public String getPath() {
           return this.path;
  
  
  
  1.21      +2 -3      jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java
  
  Index: LoadOnStartupInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- LoadOnStartupInterceptor.java	2000/08/12 04:55:45	1.20
  +++ LoadOnStartupInterceptor.java	2000/08/23 06:53:06	1.21
  @@ -63,7 +63,6 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.core.Constants;
   import org.apache.tomcat.util.*;
  -import org.apache.tomcat.facade.ServletWrapper;
   import org.apache.tomcat.logging.*;
   import java.io.*;
   import java.net.*;
  @@ -119,7 +118,7 @@
   	    Enumeration sOnLevel =  ((Vector)loadableServlets.get( key )).elements();
   	    while (sOnLevel.hasMoreElements()) {
   		String servletName = (String)sOnLevel.nextElement();
  -		ServletWrapper  result = (ServletWrapper)ctx.getServletByName(servletName);
  +		Handler result = ctx.getServletByName(servletName);
   
   		if( ctx.getDebug() > 0 ) ctx.log("Loading " + key + " "  + servletName );
   		if(result==null)
  @@ -141,7 +140,7 @@
   	}
       }
   
  -    void loadJsp( Context context, ServletWrapper result ) throws Exception {
  +    void loadJsp( Context context, Handler result ) throws Exception {
   	// A Jsp initialized in web.xml -
   
   	// Log ( since I never saw this code called, let me know if it does
  
  
  
  1.32      +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- WebXmlReader.java	2000/08/02 13:53:16	1.31
  +++ WebXmlReader.java	2000/08/23 06:53:07	1.32
  @@ -4,7 +4,6 @@
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.util.xml.*;
   import org.apache.tomcat.logging.*;
  -import org.apache.tomcat.facade.ServletWrapper;
   import java.beans.*;
   import java.io.*;
   import java.io.IOException;
  @@ -17,6 +16,8 @@
   import org.xml.sax.helpers.*;
   import org.w3c.dom.*;
   
  +// XXX XXX Specific to servlet 2.2 
  +
   /**
    * @author costin@dnt.ro
    */
  @@ -34,10 +35,10 @@
   	validate=b;
       }
   
  -    private ServletWrapper addServlet( Context ctx, String name, String classN )
  +    private Handler addServlet( Context ctx, String name, String classN )
   	throws TomcatException
       {
  -	ServletWrapper sw=new ServletWrapper();
  +	Handler sw=ctx.createHandler();
   	sw.setContext(ctx);
   	sw.setServletName( name );
   	sw.setServletClass( classN);
  @@ -51,7 +52,7 @@
       {
   	//	addServlet( ctx, "default", "org.apache.tomcat.servlets.DefaultServlet");
   // 	addServlet( ctx, "invoker", "org.apache.tomcat.servlets.InvokerServlet");
  -	ServletWrapper sw=addServlet( ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
  +	Handler sw=addServlet( ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
   	//	sw.addInitParam("jspCompilerPlugin", "org.apache.jasper.compiler.JikesJavaCompiler");
   
   // 	ctx.addServletMapping( "/servlet/*", "invoker");
  
  
  
  1.112     +4 -0      jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- Context.java	2000/08/22 05:16:38	1.111
  +++ Context.java	2000/08/23 06:53:07	1.112
  @@ -689,6 +689,10 @@
   	return (Handler)servlets.get(servletName);
       }
   
  +    public Handler createHandler() {
  +	return getFacadeManager().createHandler();
  +    }
  +    
       /**
        * Add a servlet with the given name to the container. The
        * servlet will be loaded by the container's class loader
  
  
  
  1.6       +3 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java
  
  Index: FacadeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FacadeManager.java	2000/08/14 17:49:13	1.5
  +++ FacadeManager.java	2000/08/23 06:53:07	1.6
  @@ -98,7 +98,9 @@
   
       public  HttpServletResponse createHttpServletResponseFacade(Response res);
   
  -
  +    /** Create a new handler
  +     */
  +    public Handler createHandler();
   
   
       public  void recycle( Request req );
  
  
  
  1.11      +49 -8     jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Handler.java	2000/08/02 03:50:31	1.10
  +++ Handler.java	2000/08/23 06:53:07	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.10
2000/08/02 03:50:31 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/08/02 03:50:31 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.11
2000/08/23 06:53:07 costin Exp $
  + * $Revision: 1.11 $
  + * $Date: 2000/08/23 06:53:07 $
    *
    * ====================================================================
    *
  @@ -111,7 +111,11 @@
       // who creates the servlet definition
       protected int origin;
       protected boolean internal=false;
  -
  +    protected String path;
  +    protected String servletClassName;
  +    protected String servletName;
  +    protected int loadOnStartup;
  +    
       // Debug
       protected int debug=0;
       protected String debugHead=null;
  @@ -132,10 +136,6 @@
       public void reload() {
       }
   
  -    public int getLoadOnStartUp() {
  -	return 0;
  -    }
  -    
       public boolean isInternal() {
   	return internal;
       }
  @@ -148,6 +148,47 @@
           this.name=servletName;
       }
   
  +    // -------------------- Common servlet attributes
  +    public String getServletName() {
  +	if(name!=null) return name;
  +	return path;
  +    }
  +
  +    public void setServletName(String servletName) {
  +        this.servletName=servletName;
  +	name=servletName;
  +    }
  +
  +    public String getServletClass() {
  +        return this.servletClassName;
  +    }
  +
  +    public void setServletClass(String servletClassName) {
  +	if( name==null ) name=servletClassName;
  +	this.servletClassName = servletClassName;
  +	initialized=false;
  +    }
  +
  +    public void setLoadOnStartUp( int level ) {
  +	loadOnStartup=level;
  +    }
  +
  +    public int getLoadOnStartUp() {
  +	return loadOnStartup;
  +    }
  +
  +    // -------------------- Jsp specific code
  +    
  +    public String getPath() {
  +        return this.path;
  +    }
  +
  +    public void setPath(String path) {
  +        this.path = path;
  +    }
  +
  +    // -------------------- Init params
  +    
       public void addInitParam( String name, String value ) {
   	if( initArgs==null) {
   	    initArgs=new Hashtable();
  
  
  
  1.8       +3 -3      jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java
  
  Index: InvokerInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InvokerInterceptor.java	2000/08/02 03:50:31	1.7
  +++ InvokerInterceptor.java	2000/08/23 06:53:13	1.8
  @@ -60,8 +60,8 @@
   
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.core.*;
  -import org.apache.tomcat.facade.ServletWrapper;
  -import org.apache.tomcat.facade.*;
  +//import org.apache.tomcat.facade.ServletWrapper;
  +//import org.apache.tomcat.facade.*;
   import org.apache.tomcat.logging.*;
   import org.apache.tomcat.core.Constants;
   import java.io.IOException;
  @@ -154,7 +154,7 @@
   	// it's a much cleaner way to construct the servlet and
   	// make sure all interceptors are up to date.
   	try {
  -	    ServletWrapper sw=new ServletWrapper();
  +	    Handler sw=ctx.createHandler();
   	    sw.setContext(ctx);
   	    sw.setServletName(servletName);
   	    sw.setServletClass( servletName );
  
  
  

Mime
View raw message