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/startup EmbededTomcat.java
Date Thu, 27 Jul 2000 18:47:56 GMT
costin      00/07/27 11:47:55

  Modified:    src/share/org/apache/tomcat/context LoaderInterceptor.java
               src/share/org/apache/tomcat/core Context.java
                        ServletLoader.java ServletWrapper.java
               src/share/org/apache/tomcat/loader AdaptiveClassLoader.java
                        AdaptiveClassLoader12.java
                        AdaptiveServletLoader.java ClassRepository.java
                        SimpleFileFilter.java
               src/share/org/apache/tomcat/request Jdk12Interceptor.java
                        JspInterceptor.java
               src/share/org/apache/tomcat/session
                        StandardSessionInterceptor.java
               src/share/org/apache/tomcat/startup EmbededTomcat.java
  Log:
  Few changes in ClassLoading and reloading ( mostly cosmetic, preparing for
  the real fix ).
  
  - context will know about it's own class path directly and maintian the
  list
  - use URL, same conventions as in JDK1.2 URLClassLoader ( no need to invent
  something else).
  - context will deal with reloading himself, he need to clean up, etc.
  - ServletLoader is deprecated, same for AdaptiveClassLoader and all the
  class loading components. That means only a comment !! - everything will still
  work until the replacement is done, tested and stable.
  - replaced calls to ServletLoader and all dependencies.
  
  The deprecation of ServletLoader simplifies a bit everything - class loaders
  will just deal with class loading, and we can move dependencies in a separate
  component.
  
  Revision  Changes    Path
  1.3       +31 -9     jakarta-tomcat/src/share/org/apache/tomcat/context/LoaderInterceptor.java
  
  Index: LoaderInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/LoaderInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LoaderInterceptor.java	2000/06/23 02:16:17	1.2
  +++ LoaderInterceptor.java	2000/07/27 18:47:28	1.3
  @@ -86,16 +86,10 @@
       public LoaderInterceptor() {
       }
   
  -    public void contextInit( Context context)
  +    public void addContext( ContextManager cm, Context context)
   	throws TomcatException
       {
  -        ContextManager cm = context.getContextManager();
  -	AdaptiveServletLoader loader=new AdaptiveServletLoader();
  -	context.setServletLoader( loader );
  -
           String base = context.getDocBase();
  -	Object p = context.getPermissions();
  -	Object pd=context.getProtectionDomain();
   
   	// Add "WEB-INF/classes"
   	File dir = new File(base + "/WEB-INF/classes");
  @@ -104,7 +98,11 @@
           // Thanks for Kevin Jones for providing the fix.
           dir = cm.getAbsolute(dir);
   	if( dir.exists() ) {
  -	    loader.addRepository( dir, pd );
  +	    try {
  +		URL url=new URL( "file", null, dir.getAbsolutePath() + "/" );
  +		context.addClassPath( url );
  +	    } catch( MalformedURLException ex ) {
  +	    }
           }
   
           File f = cm.getAbsolute(new File(base + "/WEB-INF/lib"));
  @@ -114,8 +112,32 @@
   	for(int i=0; i < jars.size(); ++i) {
   	    String jarfile = (String) jars.elementAt(i);
   	    File jarF=new File(f, jarfile );
  -	    loader.addRepository( cm.getAbsolute( jarF ), pd );
  +	    File jf=cm.getAbsolute( jarF );
  +	    String absPath=jf.getAbsolutePath();
  +	    try {
  +		URL url=new URL( "file", null, absPath );
  +		context.addClassPath( url );
  +	    } catch( MalformedURLException ex ) {
  +	    }
   	}
  +    }
  +    
  +    public void contextInit( Context context)
  +	throws TomcatException
  +    {
  +        ContextManager cm = context.getContextManager();
  +	Object pd=context.getProtectionDomain();
  +	
  +	AdaptiveServletLoader loader=new AdaptiveServletLoader();
  +	context.setServletLoader( loader );
  +
  +	URL classP[]=context.getClassPath();
  +	for(int i=0; i<classP.length; i++ ) {
  +            URL cp = classP[i];
  +            String fName = cp.getFile();
  +	    File f=new File(fName);
  +	    loader.addRepository( f, pd );
  +        }
       }
   
       private void getJars(Vector v, File f) {
  
  
  
  1.103     +54 -2     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.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- Context.java	2000/07/25 20:17:42	1.102
  +++ Context.java	2000/07/27 18:47:31	1.103
  @@ -111,7 +111,6 @@
       private ContextManager contextM;
       private ServletContext contextFacade;
   
  -    private ServletLoader servletL;
       boolean reloadable=true; // XXX change default to false after testing
   
       private Hashtable attributes = new Hashtable();
  @@ -657,11 +656,64 @@
       }
   
       // -------------------- Loading and sessions --------------------
  +    ClassLoader classLoader;
  +    boolean reload;
  +    // Vector<URL>, using URLClassLoader conventions
  +    Vector classPath=new Vector();
  +    
  +    
  +    /** The current class loader. This value may change if reload
  +     *  is used, you shouldn't cache the result
  +     */
  +    public final ClassLoader getClassLoader() {
  +	if( servletL!=null) // backward compat
  +	    return servletL.getClassLoader();
  +	log( "getClassLoader(): " + classLoader);
  +	return classLoader;
  +    }
  +
  +    public final void setClassLoader(ClassLoader cl ) {
  +	classLoader=cl;
  +    }
  +
  +    // temp. properties until reloading is separated.
  +    public boolean shouldReload() {
  +	if( servletL!=null) // backward compat
  +	    return servletL.shouldReload();
  +	return reload;
  +    }
  +
  +    public void setReload( boolean b ) {
  +	reload=b;
  +    }
  +
  +    public void reload() {
  +	if( servletL!=null) // backward compat
  +	    servletL.reload();
  +	// XXX todo
  +    }
  +
  +    public void addClassPath( URL url ) {
  +	classPath.addElement( url);
  +    }
  +
  +    public URL[] getClassPath() {
  +	if( classPath==null ) return new URL[0];
  +	URL urls[]=new URL[classPath.size()];
  +	for( int i=0; i<urls.length; i++ ) {
  +	    urls[i]=(URL)classPath.elementAt( i );
  +	}
  +	return urls;
  +    }
  +	
  +    // deprecated
  +    private ServletLoader servletL;
  +
       public void setServletLoader(ServletLoader loader ) {
   	this.servletL=loader;
       }
   
  -    public ServletLoader getServletLoader() {
  +    private ServletLoader getServletLoader() {
   	return servletL;
       }
   
  
  
  
  1.11      +2 -0      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java
  
  Index: ServletLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletLoader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ServletLoader.java	2000/07/25 20:17:43	1.10
  +++ ServletLoader.java	2000/07/27 18:47:32	1.11
  @@ -70,6 +70,8 @@
   // XXX Should be named DynamicLoader - has nothing specific to servlets
   
   /** Handle servlet and resource reloading
  + *  @deprecated Standard class loaders should be used + external dependency
  + *  manager
    */
   public interface ServletLoader {
   
  
  
  
  1.63      +6 -7      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- ServletWrapper.java	2000/07/25 20:17:43	1.62
  +++ ServletWrapper.java	2000/07/27 18:47:32	1.63
  @@ -256,8 +256,7 @@
   		throw new IllegalStateException("Can't happen - classname "
   						+ "is null, who added this ?");
   	    }
  -	    ServletLoader loader=context.getServletLoader();
  -	    servletClass=loader.loadClass(servletClassName);
  +	    servletClass=context.getClassLoader().loadClass(servletClassName);
   	}
   	
   	servlet = (Servlet)servletClass.newInstance();
  @@ -384,10 +383,10 @@
   	// That will be reolved after we reset the context - and many
   	// other conflicts.
   	if( isReloadable ) {// && ! "invoker".equals( getServletName())) {
  -	    ServletLoader loader=context.getServletLoader();
  -	    if( loader!=null) {
  +// 	    ServletLoader loader=context.getServletLoader();
  +// 	    if( loader!=null) {
   		// XXX no need to check after we remove the old loader
  -		if( loader.shouldReload() ) {
  +		if( context.shouldReload() ) {
   		    // workaround for destroy 
   		    try {
   			destroy();
  @@ -395,7 +394,7 @@
   			log( "Error in destroy ", ex );
   		    }
   		    initialized=false;
  -		    loader.reload();
  +		    context.reload();
   		    
   		    ContextManager cm=context.getContextManager();
   		    cm.doReload( req, context );
  @@ -418,7 +417,7 @@
   		       // XXX shut down context, remove sessions, etc
   		    */
   		}
  -	    }
  +		//	}
   	}
       }
   
  
  
  
  1.11      +3 -1      jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader.java
  
  Index: AdaptiveClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AdaptiveClassLoader.java	2000/07/14 19:34:24	1.10
  +++ AdaptiveClassLoader.java	2000/07/27 18:47:35	1.11
  @@ -118,8 +118,10 @@
    * @author Martin Pool
    * @author Jim Heintz
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.10 $ $Date: 2000/07/14 19:34:24 $
  + * @version $Revision: 1.11 $ $Date: 2000/07/27 18:47:35 $
    * @see java.lang.ClassLoader
  + * @deprecated will be replaced by AdaptiveClassLoader1 and Depend, or URL
  + *             class loader in jdk1.2
    */
   public class AdaptiveClassLoader extends ClassLoader {
       private static final int debug=0;
  
  
  
  1.4       +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader12.java
  
  Index: AdaptiveClassLoader12.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader12.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AdaptiveClassLoader12.java	2000/06/19 21:53:14	1.3
  +++ AdaptiveClassLoader12.java	2000/07/27 18:47:35	1.4
  @@ -64,6 +64,7 @@
   import java.security.*;
   
   /** Fixes for 1.2
  + *  @deprecated Will be replaced by the standard URLClassLoader
    */
   public class AdaptiveClassLoader12 extends AdaptiveClassLoader {
       public static int debug=0;
  
  
  
  1.9       +3 -0      jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveServletLoader.java
  
  Index: AdaptiveServletLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveServletLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AdaptiveServletLoader.java	2000/06/19 21:53:14	1.8
  +++ AdaptiveServletLoader.java	2000/07/27 18:47:35	1.9
  @@ -69,6 +69,9 @@
   // method in ClassLoader. The alternative is to require a public method with
   // the equivalent functionality
   
  +/**
  + * @deprecated No longer needed.
  + */
   public class AdaptiveServletLoader  extends AdaptiveClassLoader
       implements ServletLoader
   {
  
  
  
  1.3       +2 -0      jakarta-tomcat/src/share/org/apache/tomcat/loader/ClassRepository.java
  
  Index: ClassRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/ClassRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClassRepository.java	2000/06/15 00:26:47	1.2
  +++ ClassRepository.java	2000/07/27 18:47:35	1.3
  @@ -62,6 +62,8 @@
   import java.lang.*;
   import java.util.*;
   
  +/** @deprecated Standard class loaders will be used
  + */
   public class ClassRepository {
       private File file;
       private Object protectionDomain;
  
  
  
  1.4       +2 -1      jakarta-tomcat/src/share/org/apache/tomcat/loader/SimpleFileFilter.java
  
  Index: SimpleFileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/SimpleFileFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleFileFilter.java	2000/02/16 07:36:24	1.3
  +++ SimpleFileFilter.java	2000/07/27 18:47:35	1.4
  @@ -64,7 +64,8 @@
    * interface.
    *
    * @author <a href="mailto:mjenning@islandnet.com">Mike Jennings</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
  + * @deprecated No longer used, AdaptiveClassLoader1 doesn't need it
    */
   public class SimpleFileFilter implements FilenameFilter {
        private String[] extensions;
  
  
  
  1.10      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java
  
  Index: Jdk12Interceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Jdk12Interceptor.java	2000/07/11 03:48:51	1.9
  +++ Jdk12Interceptor.java	2000/07/27 18:47:47	1.10
  @@ -125,7 +125,7 @@
       // if we are in JDK1.2
       // XXX move it to interceptor !!!
       final private void fixJDKContextClassLoader( Context ctx ) {
  -	final ClassLoader cl=ctx.getServletLoader().getClassLoader();
  +	final ClassLoader cl=ctx.getClassLoader();
   	if( cl==null ) {
   	    log("ERROR: Jdk12Interceptor: classloader==null");
   	    return;
  
  
  
  1.5       +24 -6     jakarta-tomcat/src/share/org/apache/tomcat/request/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JspInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspInterceptor.java	2000/07/11 04:15:58	1.4
  +++ JspInterceptor.java	2000/07/27 18:47:47	1.5
  @@ -62,6 +62,7 @@
   
   import java.util.*;
   import java.io.*;
  +import java.net.*;
   
   import org.apache.jasper.*;
   import org.apache.jasper.Constants;
  @@ -93,8 +94,11 @@
   	throws TomcatException 
       {
   	JspFactory.setDefaultFactory(new JspFactoryImpl());
  -	ctx.getServletLoader().addRepository( ctx.getWorkDir(),
  -					      ctx.getProtectionDomain());
  +	try {
  +	    ctx.addClassPath( new URL( "file", null,
  +					ctx.getWorkDir().getAbsolutePath()));
  +	} catch( MalformedURLException ex ) {
  +	}
       }
   
       public void preServletInit( Context ctx, ServletWrapper sw )
  @@ -105,7 +109,7 @@
   	    if( debug > 0 )
   		log( "PreServletInit: HttpJspBase.setParentClassLoader" + sw );
   	    HttpJspBase h = (HttpJspBase) theServlet;
  -	    h.setClassLoader(ctx.getServletLoader().getClassLoader());
  +	    h.setClassLoader(ctx.getClassLoader());
   	}
       }
   
  @@ -216,6 +220,20 @@
       
       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
  @@ -596,8 +614,8 @@
        */
       public String getClassPath() {
   	log("JspEngineContext1: getClassPath " +
  -			   req.getContext().getServletLoader().getClassPath());
  -	return req.getContext().getServletLoader().getClassPath();
  +	    JspInterceptor.getClassPath(req.getContext()));
  +	return JspInterceptor.getClassPath(req.getContext());
       }
       
       /**
  @@ -631,7 +649,7 @@
        */
       public ClassLoader getClassLoader() {
   	log("JspEngineContext1: getLoader " + loader );
  -        return req.getContext().getServletLoader().getClassLoader();
  +        return req.getContext().getClassLoader();
       }
   
       public void addJar( String jar ) throws IOException {
  
  
  
  1.6       +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java
  
  Index: StandardSessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StandardSessionInterceptor.java	2000/06/20 19:22:54	1.5
  +++ StandardSessionInterceptor.java	2000/07/27 18:47:52	1.6
  @@ -144,7 +144,7 @@
       }
       
       public void reload( Request req, Context ctx ) {
  -	ClassLoader newLoader = ctx.getServletLoader().getClassLoader();
  +	ClassLoader newLoader = ctx.getClassLoader();
   	StandardManager sM = getManager( ctx );    
   	sM.handleReload(req, newLoader);
       }
  
  
  
  1.15      +11 -4     jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java
  
  Index: EmbededTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EmbededTomcat.java	2000/07/11 03:48:59	1.14
  +++ EmbededTomcat.java	2000/07/27 18:47:52	1.15
  @@ -236,8 +236,6 @@
   	    Context ctx=facadeM.getRealContext( sctx );
   	    contextM.initContext( ctx );
   
  -	    ServletLoader sl=ctx.getServletLoader();
  -	    //	    log("ServletLoader: " + sl );
   	    Object pd=ctx.getProtectionDomain();
   	    //	    log("Ctx.pd " + pd);
   
  @@ -246,7 +244,16 @@
   	    if( cp!=null ) {
   		for( int i=0; i<cp.size(); i++ ) {
   		    String cpath=(String)cp.elementAt(i);
  -		    sl.addRepository( new File(cpath), pd);
  +		    File f=new File( cpath );
  +		    String absPath=f.getAbsolutePath();
  +		    if( ! absPath.endsWith("/" ) && f.isDirectory() ) {
  +			absPath+="/";
  +		    }
  +		    try {
  +			ctx.addClassPath( new URL( "file", null,
  +						   absPath ));
  +		    } catch( MalformedURLException ex ) {
  +		    }
   		}
   	    }
   
  @@ -330,7 +337,7 @@
   	PolicyInterceptor polI=new PolicyInterceptor();
   	addContextInterceptor( polI );
   	polI.setDebug(0);
  -
  +        
   	LoaderInterceptor loadI=new LoaderInterceptor();
   	addContextInterceptor( loadI );
   
  
  
  

Mime
View raw message