Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 87225 invoked by uid 500); 18 Aug 2000 03:42:18 -0000 Delivered-To: apmail-jakarta-tomcat-cvs@apache.org Received: (qmail 87222 invoked by uid 1052); 18 Aug 2000 03:42:18 -0000 Date: 18 Aug 2000 03:42:18 -0000 Message-ID: <20000818034218.87221.qmail@locus.apache.org> From: costin@locus.apache.org To: jakarta-tomcat-cvs@apache.org Subject: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util SimpleClassLoader.java costin 00/08/17 20:42:17 Modified: . build.xml src/share/org/apache/tomcat/core ContextManager.java Request.java src/share/org/apache/tomcat/task StopTomcat.java src/share/org/apache/tomcat/util SimpleClassLoader.java Added: src/share/org/apache/tomcat/helper HostConfig.java ServerXmlHelper.java src/share/org/apache/tomcat/startup Main.java src/share/org/apache/tomcat/task StartTomcat.java Log: First chunk of code to simplify startup and allow customizable class loaders. startup/Main will use URLClassLoader or SimpleClassLoader ( if jdk1.1 is detected ) and load all the needed jars ( XXX make this customizable ). It will also set the parentLoader to its own loader, and that can be used ( later ) as the parent for servlets loaders ( so tomcat jars don't interfere ). We'll also build Main and the minimal set of required classes into tomcat.jar, that will get a MANIFEST - in the end we should be able to replace all the scripts with java -jar tomcat.jar ( if we find some tricks to detect TOMCAT_HOME from java) I also added a LoaderInterceptor11 - I think we should deprecate Adaptive ClassLoader and all other classes - the code is way too complex ( compared with DependManager and a simple class loader) and for 1.2 we are far away from the security checks of URLClassLoader. The only problem is that tomcat.policy will need to become a bit more verbose ( that can be automated ). startup/Main will use URLClassLoader or SimpleClassLoader ( if jdk1.1 is detected ) and load all the needed jars ( XXX make this customizable ). It will also set the parentLoader to its own loader, and that can be used ( later ) as the parent for servlets loaders ( so tomcat jars don't interfere ). We'll also build Main and the minimal set of required classes into tomcat.jar, that will get a MANIFEST - in the end we should be able to replace all the scripts with java -jar tomcat.jar ( if we find some tricks to detect TOMCAT_HOME from java) I also added a LoaderInterceptor11 - I think we should deprecate Adaptive ClassLoader and all other classes - the code is way too complex ( compared with DependManager and a simple class loader) and for 1.2 we are far away from the security checks of URLClassLoader. The only problem is that tomcat.policy will need to become a bit more verbose ( that can be automated ). startup/Main will use URLClassLoader or SimpleClassLoader ( if jdk1.1 is detected ) and load all the needed jars ( XXX make this customizable ). It will also set the parentLoader to its own loader, and that can be used ( later ) as the parent for servlets loaders ( so tomcat jars don't interfere ). We'll also build Main and the minimal set of required classes into tomcat.jar, that will get a MANIFEST - in the end we should be able to replace all the scripts with java -jar tomcat.jar ( if we find some tricks to detect TOMCAT_HOME from java) I also added a LoaderInterceptor11 - I think we should deprecate Adaptive ClassLoader and all other classes - the code is way too complex ( compared with DependManager and a simple class loader) and for 1.2 we are far away from the security checks of URLClassLoader. The only problem is that tomcat.policy will need to become a bit more verbose ( that can be automated ). The code consist mostly on additions, I hope it doesn't brake anything - I need feedback and help. Revision Changes Path 1.61 +15 -1 jakarta-tomcat/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat/build.xml,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- build.xml 2000/08/17 20:33:43 1.60 +++ build.xml 2000/08/18 03:42:13 1.61 @@ -94,7 +94,7 @@ - + @@ -104,9 +104,23 @@ + + + + + + + + + + + 1.119 +19 -0 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java Index: ContextManager.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v retrieving revision 1.118 retrieving revision 1.119 diff -u -r1.118 -r1.119 --- ContextManager.java 2000/08/15 23:45:13 1.118 +++ ContextManager.java 2000/08/18 03:42:14 1.119 @@ -154,6 +154,8 @@ Container defaultContainer; + ClassLoader parentLoader; + /** * Construct a new ContextManager instance with default values. */ @@ -283,7 +285,24 @@ this.permissions = permissions; } + /** Parent loader is the "base" class loader of the + * application that starts tomcat, and includes no + * tomcat classes. All servlet loaders will have it as + * a parent loader, as if the webapps would be loaded + * by the embeding app ( using parentLoader ). + * + * Tomcat will add servlet.jar and any other extension + * it is configured to - for example trusted webapps + * may have tomcat internal classes in classpath. + */ + public void setParentLoader( ClassLoader cl ) { + parentLoader=cl; + } + public ClassLoader getParentLoader() { + return parentLoader; + } + // -------------------- Support functions -------------------- /** Init() is called after the context manager is set up * and configured. It will init all internal components 1.54 +1 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java Index: Request.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v retrieving revision 1.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- Request.java 2000/08/15 23:03:18 1.53 +++ Request.java 2000/08/18 03:42:14 1.54 @@ -401,12 +401,8 @@ return userRoles; } + String checkRoles[]=new String[1]; public boolean isUserInRole(String role) { - // if (userRoles != null) { - // if( SecurityTools.haveRole( role, userRoles )) - // return true; - // } - String checkRoles[]=new String[1]; checkRoles[0]=role; int status=contextM.doAuthorize(this, response, checkRoles); return status==0; 1.1 jakarta-tomcat/src/share/org/apache/tomcat/helper/HostConfig.java Index: HostConfig.java =================================================================== package org.apache.tomcat.helper; import java.beans.*; import java.io.*; import java.io.IOException; import java.lang.reflect.*; import java.util.Hashtable; import java.util.*; import java.net.*; import org.apache.tomcat.util.*; import org.apache.tomcat.util.xml.*; import org.apache.tomcat.core.*; import org.xml.sax.*; /** Used by ServerXmlHelper.java, need to be public for Reflection in JDK11 */ public class HostConfig { ContextManager cm; String hostName; public HostConfig(ContextManager cm) { this.cm=cm; } public void setName( String name ) { hostName=name; } public void addContext( Context ctx ) { try { ctx.setContextManager( cm ); ctx.setHost( hostName ); cm.addContext( ctx ); } catch(Exception ex ) { if (cm != null) { cm.log("exception adding context " + ctx); } else if (ctx != null) { ctx.log("exception adding context " + ctx); } else { ex.printStackTrace(); } } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/helper/ServerXmlHelper.java Index: ServerXmlHelper.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 * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.helper; import java.beans.*; import java.io.*; import java.io.IOException; import java.lang.reflect.*; import java.util.Hashtable; import java.util.*; import java.net.*; import org.apache.tomcat.util.*; import org.apache.tomcat.util.xml.*; import org.apache.tomcat.core.*; import org.apache.tomcat.logging.*; import org.xml.sax.*; import org.apache.tomcat.core.Constants; /** * Helper for reading server.xml * * @author Costin */ public class ServerXmlHelper { private static StringManager sm = StringManager.getManager("org.apache.tomcat.resources"); public ServerXmlHelper() { } // Set the mappings public void setHelper( XmlMapper xh ) { xh.addRule( "ContextManager", xh.setProperties() ); xh.addRule( "ContextManager/ContextInterceptor", xh.objectCreate(null, "className")); xh.addRule( "ContextManager/ContextInterceptor", xh.setProperties() ); xh.addRule( "ContextManager/ContextInterceptor", xh.setParent("setContextManager") ); xh.addRule( "ContextManager/ContextInterceptor", xh.addChild( "addContextInterceptor", "org.apache.tomcat.core.ContextInterceptor")); xh.addRule( "ContextManager/RequestInterceptor", xh.objectCreate(null, "className")); xh.addRule( "ContextManager/RequestInterceptor", xh.setProperties() ); xh.addRule( "ContextManager/RequestInterceptor", xh.setParent("setContextManager") ); xh.addRule( "ContextManager/RequestInterceptor", xh.addChild( "addRequestInterceptor", "org.apache.tomcat.core.RequestInterceptor")); // Default host xh.addRule( "ContextManager/Context", xh.objectCreate("org.apache.tomcat.core.Context")); xh.addRule( "ContextManager/Context", xh.setParent( "setContextManager") ); xh.addRule( "ContextManager/Context", xh.setProperties() ); xh.addRule( "ContextManager/Context", xh.addChild( "addContext", null ) ); xh.addRule( "ContextManager/Context/RequestInterceptor", xh.objectCreate(null, "className")); xh.addRule( "ContextManager/Context/RequestInterceptor", xh.setProperties() ); xh.addRule( "ContextManager/Context/RequestInterceptor", xh.setParent("setContext") ); xh.addRule( "ContextManager/Context/RequestInterceptor", xh.addChild( "addRequestInterceptor", "org.apache.tomcat.core.RequestInterceptor")); // Virtual host support. // Push a host object on the stack xh.addRule( "ContextManager/Host", new XmlAction() { public void start( SaxContext ctx) throws Exception { Stack st=ctx.getObjectStack(); // get attributes int top=ctx.getTagCount()-1; AttributeList attributes = ctx.getAttributeList( top ); // get CM ContextManager cm=(ContextManager)st.peek(); // construct virtual host config helper HostConfig hc=new HostConfig(cm); // set the host name hc.setName( attributes.getValue("name")); st.push( hc ); } public void cleanup( SaxContext ctx) { Stack st=ctx.getObjectStack(); Object o=st.pop(); } }); xh.addRule( "ContextManager/Host", xh.setProperties()); xh.addRule( "ContextManager/Host/Context", xh.objectCreate("org.apache.tomcat.core.Context")); xh.addRule( "ContextManager/Host/Context", xh.setProperties() ); xh.addRule( "ContextManager/Host/Context", new XmlAction() { public void end( SaxContext ctx) throws Exception { Stack st=ctx.getObjectStack(); Context tcCtx=(Context)st.pop(); // get the Context HostConfig hc=(HostConfig)st.peek(); st.push( tcCtx ); // put back the context, to be cleaned up corectly hc.addContext( tcCtx ); } }); } public void setConnectorHelper( XmlMapper xh ) { xh.addRule( "ContextManager/Connector", xh.objectCreate(null, "className")); xh.addRule( "ContextManager/Connector", xh.setParent( "setContextManager", "org.apache.tomcat.core.ContextManager") ); xh.addRule( "ContextManager/Connector", xh.addChild( "addContextInterceptor", "org.apache.tomcat.core.ContextInterceptor")); xh.addRule( "ContextManager/Connector/Parameter", xh.methodSetter("setProperty",2) ); xh.addRule( "ContextManager/Connector/Parameter", xh.methodParam(0, "name") ); xh.addRule( "ContextManager/Connector/Parameter", xh.methodParam(1, "value") ); } /** Setup loggers when reading the configuration file - this will be * called only when starting tomcat as deamon, all other modes will * output to stderr * *** [I don't think that's true any more -Alex] */ public void setLogHelper( XmlMapper xh ) { xh.addRule("Server/Logger", xh.objectCreate("org.apache.tomcat.logging.TomcatLogger")); xh.addRule("Server/Logger", xh.setProperties()); xh.addRule("Server/Logger", xh.addChild("addLogger", "org.apache.tomcat.logging.Logger") ); } /** * Return the configuration file we are processing. If the * -config filename command line argument is not * used, the default configuration filename will be loaded from * the TOMCAT_HOME directory. * * If a relative config file is used, it will be relative to the current * working directory. * * @param cm The ContextManager we are configuring **/ public String getTomcatInstall() { // Use the "tomcat.home" property to resolve the default filename String tchome = System.getProperty("tomcat.home"); if (tchome == null) { System.out.println(sm.getString("tomcat.nohome")); tchome = "."; // Assume current working directory } return tchome; } public Vector getUserConfigFiles(File master) { File dir = new File(master.getParent()); String[] names = dir.list( new ConfigFilter(master) ); Vector v = new Vector(names.length); for (int i=0; i. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.startup; import java.beans.*; import java.io.*; import java.io.IOException; import java.lang.reflect.*; import java.util.Hashtable; import java.util.*; import java.net.*; import org.apache.tomcat.util.SimpleClassLoader; // XXX there is a nice trick to "guess" TOMCAT_HOME from // classpath - you open each component of cp and check if // it contains this file. When you find it just take the // path and use it. // Since the .sh will need to include it in CP probably it // already know where it is. // Thanks ANT /** * Starter for Tomcat. This is the standalone started - the only component that is * part of the system CLASSPATH. It will process command line options and * load the right jars ( like JAXP and anything else required to start tomcat). * * This is a replacement for all the scripting we use to do in tomcat.sh and tomcat.bat. * * This class have (only) the following dependencies( that need to be included in the * same jar): * - org.apache.tomcat.util.SimpleClassLoader - for JDK1.1 * * * Starting tomcat. * Add tcstarter.jar to CLASSPATH * Launch org.apache.tomcat.startup.Tomcat with TOMCAT_HOME parameter * pointing to the tomcat install directory. * * * @author Costin */ public class Main { String installDir; String homeDir; static final String DEFAULT_CONFIG="conf/server.xml"; boolean doStop=false; // if needed // null means user didn't set one String configFile; static boolean jdk12=false; static { try { Class.forName( "java.security.PrivilegedAction" ); jdk12=true; } catch(Throwable ex ) { } } public Main() { } public static void main(String args[] ) { try { Main tomcat=new Main(); tomcat.execute( args ); } catch(Exception ex ) { System.out.println("Fatal error"); ex.printStackTrace(); } } void log( String s ) { System.out.println("TomcatStartup: " + s ); } // -------------------- Command-line args processing -------------------- String libBase; public void setLibDir( String base ) { try { File f = new File(base); this.libBase = f.getCanonicalPath(); if( ! libBase.endsWith("/") ) libBase+="/"; } catch (IOException ioe) { ioe.printStackTrace(); libBase=base; } } public String getPackageDir() { String tcHome=System.getProperty("tomcat.home"); // XXX process args, find if -install is specified if( tcHome==null ) { log( "No tomcat.home specified, can't run"); return null; } return tcHome; } public String getLibDir() { if( libBase!=null ) return libBase; String pkg=getPackageDir(); if( pkg!=null ) setLibDir( pkg + "/lib"); else setLibDir("./lib"); return libBase; } ClassLoader getURLClassLoader( URL urls[], ClassLoader parent ) throws Exception { Class urlCL=Class.forName( "java.net.URLClassLoader"); Class paramT[]=new Class[2]; paramT[0]= urls.getClass(); paramT[1]=ClassLoader.class; Method m=urlCL.getMethod( "newInstance", paramT); ClassLoader cl=(ClassLoader)m.invoke( urlCL, new Object[] { urls, parent } ); return cl; } String cpComp[]=new String[] { "../classes/", "jaxp.jar", "parser.jar", "jasper.jar", "servlet.jar", "webserver.jar" }; void execute( String args[] ) throws Exception { try { int jarCount=cpComp.length; URL urls[]=new URL[jarCount + 1 ]; for( int i=0; i< jarCount ; i++ ) { urls[i]=new URL( "file", null, getLibDir() + cpComp[i] ); System.out.println( "Add to CP: " + urls[i] ); } // Add tools.jar if JDK1.2 String java_home=System.getProperty( "java.home" ); urls[jarCount]= new URL( "file", null , java_home + "/../lib/tools.jar"); System.out.println( "Add to CP: " + urls[jarCount] ); ClassLoader parentL=this.getClass().getClassLoader(); ClassLoader cl=null; if( jdk12 ) cl= getURLClassLoader( urls, parentL ); else cl=new SimpleClassLoader(urls, parentL); Object proxy=instantiate( cl, "org.apache.tomcat.task.StartTomcat"); processArgs( proxy, args ); setParentLoader( proxy, parentL ); execute( proxy ); return; } catch( Exception ex ) { ex.printStackTrace(); } } /** Create an instance of the target task */ Object instantiate( ClassLoader cl, String classN ) throws Exception { Class sXmlC=cl.loadClass(classN ); return sXmlC.newInstance(); } /** If the proxy has a setParentClassLoader() method, use it to allow it to access this class' loader */ void setParentLoader( Object proxy, ClassLoader cl) throws Exception { Method executeM=null; Class c=proxy.getClass(); Class params[]=new Class[1]; params[0]= ClassLoader.class; executeM=c.getMethod( "setParentClassLoader", params ); if( executeM == null ) { log("No setParentClassLoader in " + proxy.getClass() ); return; } log( "Setting parent loader " + cl); executeM.invoke(proxy, new Object[] { cl }); return; } /** Call execute() - any ant-like task should work */ void execute( Object proxy ) throws Exception { Method executeM=null; Class c=proxy.getClass(); Class params[]=new Class[0]; // params[0]=args.getClass(); executeM=c.getMethod( "execute", params ); if( executeM == null ) { log("No execute in " + proxy.getClass() ); return; } log( "Calling proxy "); executeM.invoke(proxy, null );//new Object[] { args }); return; } /** Read command line arguments and set properties in proxy, using ant-like patterns */ void processArgs(Object proxy, String args[] ) { for( int i=0; i< args.length; i++ ) { } } } 1.6 +81 -0 jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java Index: StopTomcat.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StopTomcat.java 2000/07/11 08:09:30 1.5 +++ StopTomcat.java 2000/08/18 03:42:16 1.6 @@ -60,6 +60,8 @@ import org.apache.tomcat.core.*; import org.apache.tomcat.util.*; +import org.apache.tomcat.helper.*; +import org.apache.tomcat.util.xml.*; import org.apache.tomcat.logging.*; import java.io.*; import java.net.*; @@ -75,13 +77,92 @@ * @author Costin Manolache */ public class StopTomcat { + static final String DEFAULT_CONFIG="conf/server.xml"; + private static StringManager sm = + StringManager.getManager("org.apache.tomcat.resources"); + String configFile; + String tomcatHome; Logger.Helper loghelper = new Logger.Helper("tc_log", "StopTomcat"); public StopTomcat() { } + // -------------------- Parameters -------------------- + + public void setConfig( String s ) { + configFile=s; + } + + /** -f option + */ + public void setF( String s ) { + configFile=s; + } + + public void setH( String s ) { + tomcatHome=s; + System.getProperties().put("tomcat.home", s); + } + + public void setHome( String s ) { + tomcatHome=s; + System.getProperties().put("tomcat.home", s); + } + + // -------------------- Ant execute -------------------- + public void execute() throws Exception { + System.out.println(sm.getString("tomcat.stop")); + try { + stopTomcat(); // stop serving + } + catch (TomcatException te) { + if (te.getRootCause() instanceof java.net.ConnectException) + System.out.println(sm.getString("tomcat.connectexception")); + else + throw te; + } + return; + } + + // -------------------- Implementation -------------------- + + /** Stop tomcat using the configured cm + * The manager is set up using the same configuration file, so + * it will have the same port as the original instance ( no need + * for a "log" file). + * It uses the Ajp12 connector, which has a built-in "stop" method, + * that will change when we add real callbacks ( it's equivalent + * with the previous RMI method from almost all points of view ) + */ + void stopTomcat() throws TomcatException { + XmlMapper xh=new XmlMapper(); + xh.setDebug( 0 ); + ContextManager cm=new ContextManager(); + + ServerXmlHelper sxml=new ServerXmlHelper(); + + sxml.setConnectorHelper( xh ); + // load server.xml + File f = null; + if (configFile != null) + f=new File(configFile); + + String tchome=sxml.getTomcatInstall(); + f=new File(tchome, DEFAULT_CONFIG); + cm.setInstallDir( tchome); + + try { + xh.readXml(f,cm); + } catch( Exception ex ) { + throw new TomcatException("Fatal exception reading " + f, ex); + } + + execute( cm ); + } + + /** This particular implementation will search for an AJP12 connector ( that have a special stop command ). */ 1.1 jakarta-tomcat/src/share/org/apache/tomcat/task/StartTomcat.java Index: StartTomcat.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 * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.task; import java.beans.*; import java.io.*; import java.io.IOException; import java.lang.reflect.*; import java.util.Hashtable; import java.util.*; import java.net.*; import org.apache.tomcat.util.*; import org.apache.tomcat.helper.*; import org.apache.tomcat.util.xml.*; import org.apache.tomcat.core.*; import org.apache.tomcat.logging.*; import org.xml.sax.*; import org.apache.tomcat.core.Constants; /** * Starter for Tomcat using server.XML. * Based on Ant. * * @author costin@dnt.ro */ public class StartTomcat { ClassLoader parentLoader; private static StringManager sm = StringManager.getManager("org.apache.tomcat.resources"); Logger.Helper loghelper = new Logger.Helper("tc_log", "StartTomcat"); public StartTomcat() { } public void execute() throws Exception { if( doHelp ) { printUsage(); return; } if( doStop ) { org.apache.tomcat.task.StopTomcat task= new org.apache.tomcat.task.StopTomcat(); task.setConfig( configFile ); task.execute(); return; } XmlMapper xh=new XmlMapper(); xh.setDebug( 0 ); ContextManager cm=new ContextManager(); cm.setParentLoader( parentLoader ); ServerXmlHelper sxml=new ServerXmlHelper(); sxml.setHelper( xh ); sxml.setConnectorHelper( xh ); sxml.setLogHelper( xh ); // load server.xml File f = null; if (configFile != null) f=new File(configFile); String tchome=sxml.getTomcatInstall(); f=new File(tchome, DEFAULT_CONFIG); cm.setInstallDir( tchome); loadConfigFile(xh,f,cm); // load server-*.xml Vector v = sxml.getUserConfigFiles(f); for (Enumeration e = v.elements(); e.hasMoreElements() ; ) { f = (File)e.nextElement(); loadConfigFile(xh,f,cm); } // by now, we should know where the log file is String path = cm.getLogger().getPath(); if (path == null) path = "console"; else path = new File(path).getAbsolutePath(); System.out.println(sm.getString("tomcat.start", new Object[] { path })); cm.init(); // set up contexts loghelper.log(Constants.TOMCAT_NAME + " " + Constants.TOMCAT_VERSION); // XXX Make this optional, and make sure it doesn't require // a full start. It is called after init to make sure // auto-configured contexts are initialized. generateServerConfig( cm ); try { cm.start(); // start serving } catch (java.net.BindException be) { loghelper.log("Starting Tomcat: " + be.getMessage(), Logger.ERROR); System.out.println(sm.getString("tomcat.bindexception")); try { cm.stop(); } catch (Exception e) { loghelper.log("Stopping ContextManager", e); } } } /** Special call to support a multiple class paths */ public void setParentClassLoader( ClassLoader cl ) { parentLoader=cl; } /** This method will generate Server config files that reflect the existing cm settings. It is called at startup, and may be called when a new context is added ( at runtime for example ). */ public static void generateServerConfig( ContextManager cm ) throws TomcatException { // Generate Apache configs // org.apache.tomcat.task.ApacheConfig apacheConfig= new org.apache.tomcat.task.ApacheConfig(); apacheConfig.execute( cm ); // Generate IIS configs // org.apache.tomcat.task.IISConfig iisConfig= new org.apache.tomcat.task.IISConfig(); iisConfig.execute( cm ); // Generate Netscape configs // org.apache.tomcat.task.NSConfig nsConfig= new org.apache.tomcat.task.NSConfig(); nsConfig.execute( cm ); } public static void printUsage() { System.out.println(sm.getString("tomcat.usage")); } public void loadConfigFile(XmlMapper xh, File f, ContextManager cm) throws Exception { loghelper.log(sm.getString("tomcat.loading") + " " + f); try { xh.readXml(f,cm); } catch( Exception ex ) { loghelper.log( sm.getString("tomcat.fatalconfigerror"), ex ); throw ex; } loghelper.log(sm.getString("tomcat.loaded") + " " + f); } // -------------------- Command-line args processing -------------------- // null means user didn't set one String configFile=null; boolean doHelp=false; boolean doStop=false; // relative to TOMCAT_HOME static final String DEFAULT_CONFIG="conf/server.xml"; /** Print help message */ public void setHelp(boolean b) { doHelp=true; } public void setStop( boolean b ) { doStop=true; } public void setConfig( String s ) { configFile=s; } public void setF( String s ) { configFile=s; } public void setH( String h ) { System.getProperties().put("tomcat.home", h); } public void setHome( String h ) { System.getProperties().put("tomcat.home", h); } } 1.2 +14 -7 jakarta-tomcat/src/share/org/apache/tomcat/util/SimpleClassLoader.java Index: SimpleClassLoader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SimpleClassLoader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleClassLoader.java 2000/07/27 19:02:33 1.1 +++ SimpleClassLoader.java 2000/08/18 03:42:17 1.2 @@ -140,7 +140,7 @@ // debug only void log( String s ) { - System.out.println("AdaptiveClassLoader1: " + s ); + System.out.println("SimpleClassLoader: " + s ); } //------------------------------------ Implementation of Classloader @@ -364,19 +364,26 @@ // Get this resource from system class loader s = getSystemResourceAsStream(name); - if (s != null) { + if( debug>0 ) log( "System resource " + s ); + if (s != null) { return s; } Resource r=doFindResource( name ); + if( r==null ) return null; + if( r.file!=null ) { + if( debug > 0 ) log( "Found " + r.file); try { - return new FileInputStream(r.file); - } catch (FileNotFoundException shouldnothappen) { - return null; + InputStream res=new FileInputStream(r.file); + return res; + } catch (IOException shouldnothappen) { + shouldnothappen.printStackTrace(); + return null; } } else if( r.zipEntry != null ) { + if( debug > 0 ) log( "Found " + r.zipEntry); // workaround - the better solution is to not close the // zipfile !!!! try { @@ -399,7 +406,6 @@ } } } - return s; } @@ -438,7 +444,8 @@ try { ZipFile zf = new ZipFile(file.getAbsolutePath()); ZipEntry ze = zf.getEntry(name); - + //if( debug > 0 ) log( "Searching " + file + " " + name ); + if (ze != null) { r.zipEntry=ze; r.zipFile=zf;