Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 37468 invoked from network); 30 Sep 2002 22:03:20 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 30 Sep 2002 22:03:20 -0000 Received: (qmail 23365 invoked by uid 97); 30 Sep 2002 22:04:06 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 23299 invoked by uid 97); 30 Sep 2002 22:04:06 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 23288 invoked by uid 97); 30 Sep 2002 22:04:05 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 30 Sep 2002 22:03:13 -0000 Message-ID: <20020930220313.47106.qmail@icarus.apache.org> From: hammant@apache.org To: jakarta-avalon-apps-cvs@apache.org Subject: cvs commit: jakarta-avalon-apps/sevak/src/conf manifest.mf sevak-assembly.xml sevak-config.xml sevak-environment.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N hammant 2002/09/30 15:03:12 Modified: sevak ant.properties.sample build.xml catalina.xml sevak/src/demo/conf catalina-assembly.xml catalina-config.xml catalina-environment.xml sevak/src/demo/java/org/apache/avalon/apps/sevak/demo MultihostSevakTest.java SevakTest.java sevak/src/java/org/apache/avalon/apps/sevak Sevak.java sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina CatalinaSevak.java CatalinaSevakBootstrap.java CatalinaSevakClassLoaderFactory.java CatalinaSevakServer.java Added: sevak/src/demo/conf tomcat-users.xml sevak/src/demo/webapps/sevak-test/WEB-INF/classes/num NumberGuessBean.class NumberGuessBean.java sevak/src/demo/webapps/sevak-test/WEB-INF web.xml sevak/src/demo/webapps/sevak-test index.jsp Removed: sevak/src/conf manifest.mf sevak-assembly.xml sevak-config.xml sevak-environment.xml Log: More patches for Catalina Sevak from Daniel Krieg. Revision Changes Path 1.2 +7 -1 jakarta-avalon-apps/sevak/ant.properties.sample Index: ant.properties.sample =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/ant.properties.sample,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ant.properties.sample 29 Sep 2002 11:38:42 -0000 1.1 +++ ant.properties.sample 30 Sep 2002 22:03:11 -0000 1.2 @@ -30,4 +30,10 @@ checkstyle.lib=${checkstyle.home} checkstyle.jar=${checkstyle.lib}/checkstyle-all-2.3.jar +# ----------------------------------------------------------------------------- +# CATALINA SEVAK PROPERTIES +# Uncomment catalina-zip-suffix to build using JDK 1.4 LE +# (lightweight binary distribution of Tomcat 4, designed to be run on JDK 1.4.) +# ----------------------------------------------------------------------------- +#catalina-zip-suffix=-LE-jdk14 1.15 +56 -0 jakarta-avalon-apps/sevak/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/build.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- build.xml 29 Sep 2002 11:38:42 -0000 1.14 +++ build.xml 30 Sep 2002 22:03:11 -0000 1.15 @@ -275,6 +275,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.4 +14 -21 jakarta-avalon-apps/sevak/catalina.xml Index: catalina.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/catalina.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- catalina.xml 22 Sep 2002 21:39:12 -0000 1.3 +++ catalina.xml 30 Sep 2002 22:03:11 -0000 1.4 @@ -45,7 +45,9 @@ - + + + @@ -55,13 +57,15 @@ - - + + - + - + + + @@ -119,7 +123,6 @@ - @@ -177,8 +180,8 @@ - - + + @@ -191,23 +194,13 @@ + - + - - - - - - - - - - - - + 1.3 +2 -3 jakarta-avalon-apps/sevak/src/demo/conf/catalina-assembly.xml Index: catalina-assembly.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-assembly.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- catalina-assembly.xml 29 Sep 2002 11:38:42 -0000 1.2 +++ catalina-assembly.xml 30 Sep 2002 22:03:11 -0000 1.3 @@ -3,9 +3,8 @@ "http://jakarta.apache.org/phoenix/assembly_1_0.dtd"> - - + - + 1.3 +3 -4 jakarta-avalon-apps/sevak/src/demo/conf/catalina-config.xml Index: catalina-config.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-config.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- catalina-config.xml 29 Sep 2002 11:38:42 -0000 1.2 +++ catalina-config.xml 30 Sep 2002 22:03:11 -0000 1.3 @@ -7,12 +7,11 @@ --> - - true + conf/server-noexamples.xml.config - + - + 1.3 +1 -2 jakarta-avalon-apps/sevak/src/demo/conf/catalina-environment.xml Index: catalina-environment.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-environment.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- catalina-environment.xml 29 Sep 2002 11:38:42 -0000 1.2 +++ catalina-environment.xml 30 Sep 2002 22:03:11 -0000 1.3 @@ -8,12 +8,11 @@ - + location="/logs/avalon-sevak.log" /> 1.1 jakarta-avalon-apps/sevak/src/demo/conf/tomcat-users.xml Index: tomcat-users.xml =================================================================== 1.2 +3 -2 jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo/MultihostSevakTest.java Index: MultihostSevakTest.java =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo/MultihostSevakTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MultihostSevakTest.java 29 Sep 2002 11:38:43 -0000 1.1 +++ MultihostSevakTest.java 30 Sep 2002 22:03:12 -0000 1.2 @@ -58,9 +58,10 @@ String ctxPath = contexts[ i ].getAttribute( "path" ); ctxPath = ctxPath.replace( '/', File.separatorChar ); ctxPath = ctxPath.replace( '\\', File.separatorChar ); - String ctxFullPath = m_context.getBaseDirectory().getAbsolutePath() + File.separatorChar + ctxPath; + String ctxFullPath = m_context.getBaseDirectory().getAbsolutePath() + File.separatorChar + "SAR-INF" + + File.separatorChar + "lib" + File.separatorChar + ctxPath; //System.out.println("Ctx = " + ctx + ", path = " + ctxFullPath); - m_mulihostSevak.deploy( "loclhost", ctx, new File( ctxFullPath ) ); + m_mulihostSevak.deploy( "localhost", ctx, new File( ctxFullPath ) ); } } } 1.3 +25 -31 jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo/SevakTest.java Index: SevakTest.java =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo/SevakTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SevakTest.java 29 Jun 2002 13:20:21 -0000 1.2 +++ SevakTest.java 30 Sep 2002 22:03:12 -0000 1.3 @@ -33,53 +33,47 @@ */ public class SevakTest extends AbstractLogEnabled - implements Contextualizable, Serviceable, Configurable, Initializable -{ + implements Contextualizable, Serviceable, Configurable, Initializable { private BlockContext m_context; - private Configuration m_configuration; - private Sevak m_sevak; - - public void contextualize(final Context context) - { - getLogger().info("SevakTest.contextualize()"); + private Configuration m_configuration; + private Sevak m_sevak; + + public void contextualize( final Context context ) { + getLogger().info( "SevakTest.contextualize()" ); m_context = (BlockContext) context; } - public void configure(final Configuration configuration) - throws ConfigurationException - { - - m_configuration=configuration; - + public void configure( final Configuration configuration ) + throws ConfigurationException { + + m_configuration = configuration; + } /** * @see org.apache.avalon.framework.service.Serviceable * @phoenix:dependency name="org.apache.avalon.apps.sevak.Sevak" */ - public void service(final ServiceManager serviceManager) - throws ServiceException - { - getLogger().info("SevakTest.service()"); - m_sevak=(Sevak)serviceManager.lookup(Sevak.class.getName()); + public void service( final ServiceManager serviceManager ) + throws ServiceException { + getLogger().info( "SevakTest.service()" ); + m_sevak = (Sevak) serviceManager.lookup( Sevak.class.getName() ); } public void initialize() - throws Exception - { - getLogger().info("SevakTest.initialize()"); - Configuration[] contexts=m_configuration.getChildren("Context"); - for(int i=0;iTomcat Project Page * * @author Daniel Krieg - * @version $Revision$ $Date$ + * @version 1.0 */ -public class CatalinaSevak -{ +public class CatalinaSevak { private ClassLoader m_parentLoader = ClassLoader.getSystemClassLoader(); private Server m_server = null; private String m_configFile; private boolean m_useNaming = true; - /** - * Set the parent classloader - * @param parentLoader the parent classloader - */ - public void setParentClassLoader(ClassLoader parentLoader) - { + public void setParentClassLoader( ClassLoader parentLoader ) { m_parentLoader = parentLoader; } - /** - * set the configuration file - * @param configFile the config file - */ - public void setConfigFile(String configFile) - { + public void setConfigFile( String configFile ) { m_configFile = configFile; } - /** - * Set the use naming - * @param useNaming the use naming - */ - public void setUseNaming(boolean useNaming) - { + public void setUseNaming( boolean useNaming ) { m_useNaming = useNaming; } - /** - * Set the server - * @param server the server - */ - public void setServer(Server server) - { + public void setServer( Server server ) { this.m_server = server; } - /** - * Initialize - * @throws Exception if a problem - */ - public void initialize() throws Exception - { + public void initialize() throws Exception { Digester digester = createStartDigester(); - File file = getConfigFile(); - try - { + File file = configFile(); + try { InputSource is = - new InputSource("file://" + file.getAbsolutePath()); - FileInputStream fis = new FileInputStream(file); - is.setByteStream(fis); - digester.push(this); - digester.parse(is); + new InputSource( "file://" + file.getAbsolutePath() ); + FileInputStream fis = new FileInputStream( file ); + is.setByteStream( fis ); + digester.push( this ); + digester.parse( is ); fis.close(); - } - catch (Exception e) - { + } catch( Exception e ) { e.printStackTrace(); return; } - if (!m_useNaming) - { - System.setProperty("catalina.useNaming", "false"); - } - else - { - System.setProperty("catalina.useNaming", "true"); + if( !m_useNaming ) { + System.setProperty( "catalina.useNaming", "false" ); + } else { + System.setProperty( "catalina.useNaming", "true" ); String value = "org.apache.naming"; String oldValue = - System.getProperty(javax.naming.Context.URL_PKG_PREFIXES); - if (oldValue != null) - { + System.getProperty( javax.naming.Context.URL_PKG_PREFIXES ); + if( oldValue != null ) { value = value + ":" + oldValue; } - System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value); + System.setProperty( javax.naming.Context.URL_PKG_PREFIXES, value ); value = System.getProperty - (javax.naming.Context.INITIAL_CONTEXT_FACTORY); - if (value == null) - { + ( javax.naming.Context.INITIAL_CONTEXT_FACTORY ); + if( value == null ) { System.setProperty - (javax.naming.Context.INITIAL_CONTEXT_FACTORY, - "org.apache.naming.java.javaURLContextFactory"); + ( javax.naming.Context.INITIAL_CONTEXT_FACTORY, + "org.apache.naming.java.javaURLContextFactory" ); } } - if (System.getSecurityManager() != null) - { - String access = Security.getProperty("package.access"); - if (access != null && access.length() > 0) - { + if( System.getSecurityManager() != null ) { + String access = Security.getProperty( "package.access" ); + if( access != null && access.length() > 0 ) access += ","; - } else - { access = "sun.,"; - } - Security.setProperty("package.access", - access + "org.apache.catalina.,org.apache.jasper."); - String definition = Security.getProperty("package.definition"); - if (definition != null && definition.length() > 0) - { + Security.setProperty( "package.access", + access + "org.apache.catalina.,org.apache.jasper." ); + String definition = Security.getProperty( "package.definition" ); + if( definition != null && definition.length() > 0 ) definition += ","; - } else - { definition = "sun.,"; - } - Security.setProperty("package.definition", - // FIX ME package "javax." was removed to prevent HotSpot - // fatal internal errors - definition + "java.,org.apache.catalina.,org.apache.jasper."); + Security.setProperty( "package.definition", + // FIX ME package "javax." was removed to prevent HotSpot + // fatal internal errors + definition + "java.,org.apache.catalina.,org.apache.jasper." ); } - if (m_server instanceof Lifecycle) - { + if( m_server instanceof Lifecycle ) { m_server.initialize(); } // Service[] services = m_server.findServices(); @@ -177,260 +131,193 @@ // } // System.out.println(); // } - System.out.println("CatalinaSevak Server initialized"); + System.out.println( "CatalinaSevak Server initialized" ); } - /** - * Start the server - * @throws Exception if a problem - */ - public void start() throws Exception - { - if (m_server instanceof Lifecycle) - { - try - { - ((Lifecycle) m_server).start(); + public void start() throws Exception { + if( m_server instanceof Lifecycle ) { + try { + ( (Lifecycle) m_server ).start(); m_server.await(); - } - catch (LifecycleException e) - { - System.out.println("Catalina.start: " + e); - e.printStackTrace(System.out); - if (e.getThrowable() != null) - { - System.out.println("----- Root Cause -----"); - e.getThrowable().printStackTrace(System.out); + } catch( LifecycleException e ) { + System.out.println( "Catalina.start: " + e ); + e.printStackTrace( System.out ); + if( e.getThrowable() != null ) { + System.out.println( "----- Root Cause -----" ); + e.getThrowable().printStackTrace( System.out ); } - } - catch (Throwable throwable) - { + } catch( Throwable throwable ) { throwable.printStackTrace(); } - } - else - { - throw new Exception("Unable to start CatalinSevak Server: " - + m_server.getClass().getName()); + } else { + throw new Exception( "Unable to start CatalinSevak Server: " + m_server.getClass().getName() ); } } - /** - * Stop the server - * @throws Exception if a problem - */ - public void stop() throws Exception - { - if (m_server instanceof Lifecycle) - { - try - { - ((Lifecycle) m_server).stop(); - } - catch (LifecycleException e) - { - System.out.println("Catalina.stop: " + e); - e.printStackTrace(System.out); - if (e.getThrowable() != null) - { - System.out.println("----- Root Cause -----"); - e.getThrowable().printStackTrace(System.out); + public void stop() throws Exception { + if( m_server instanceof Lifecycle ) { + try { + ( (Lifecycle) m_server ).stop(); + } catch( LifecycleException e ) { + System.out.println( "Catalina.stop: " + e ); + e.printStackTrace( System.out ); + if( e.getThrowable() != null ) { + System.out.println( "----- Root Cause -----" ); + e.getThrowable().printStackTrace( System.out ); } } - } - else - { - throw new Exception("Unable to start CatalinSevak Server: " - + m_server.getClass().getName()); + } else { + throw new Exception( "Unable to start CatalinSevak Server: " + m_server.getClass().getName() ); } } - /** - * Deploy a webapp - * @param host the host - * @param context the server context - * @param pathToWebAppFolder the path to the war file - * @throws Exception if aproblem - */ - public void deploy(String host, String context, File pathToWebAppFolder) throws Exception - { + public void deploy( String host, String context, File pathToWebAppFolder ) throws Exception { Service[] services = m_server.findServices(); Container child = null; found_host: { - for (int i = 0; i < services.length; i++) - { - Service service = services[i]; + for( int i = 0; i < services.length; i++ ) { + Service service = services[ i ]; Container[] children = service.getContainer().findChildren(); - for (int j = 0; j < children.length; j++) - { - child = children[j]; - if (child.getName().equals(host)) - { + for( int j = 0; j < children.length; j++ ) { + child = children[ j ]; + if( child.getName().equals( host ) ) { break found_host; } } } } - if (child == null) - { - throw new IllegalArgumentException(host + ": no such host."); - } - if (!(child instanceof Deployer)) - { - throw new Exception(host + ": not able to deploy " + context); + if( child == null ) { + throw new IllegalArgumentException( host + ": no such host." ); + } + if( !( child instanceof Deployer ) ) { + throw new Exception( host + ": not able to deploy " + context ); } final Deployer deployer = (Deployer) child; - if (deployer.findDeployedApp(context) != null) - { - throw new Exception(context + " already deployed to host " + host); + if( deployer.findDeployedApp( context ) != null ) { + throw new Exception( context + " already deployed to host " + host ); } - deployer.install(context, pathToWebAppFolder.toURL()); - deployer.start(context); + deployer.install( context, pathToWebAppFolder.toURL() ); +// deployer.start( context ); } - /** - * Undeploy a web app - * @param host the host - * @param context the context - * @throws Exception if a problem - */ - public void undeploy(String host, String context) throws Exception - { + public void undeploy( String host, String context ) throws Exception { Service[] services = m_server.findServices(); Container child = null; found_host: { - for (int i = 0; i < services.length; i++) - { - Service service = services[i]; + for( int i = 0; i < services.length; i++ ) { + Service service = services[ i ]; Container[] children = service.getContainer().findChildren(); - for (int j = 0; j < children.length; j++) - { - child = children[j]; - if (child.getName().equals(host)) - { + for( int j = 0; j < children.length; j++ ) { + child = children[ j ]; + if( child.getName().equals( host ) ) { break found_host; } } } } - if (child == null) - { - throw new IllegalArgumentException(host + ": no such host."); - } - if (!(child instanceof Deployer)) - { - throw new Exception(host + ": not able to undeploy " + context); + if( child == null ) { + throw new IllegalArgumentException( host + ": no such host." ); + } + if( !( child instanceof Deployer ) ) { + throw new Exception( host + ": not able to undeploy " + context ); } final Deployer deployer = (Deployer) child; - if (deployer.findDeployedApp(context) == null) - { - throw new Exception(context + " does not exist in host " + host); + if( deployer.findDeployedApp( context ) == null ) { + throw new Exception( context + " does not exist in host " + host ); } - deployer.start(context); - deployer.remove(context); +// deployer.start( context ); + deployer.remove( context ); } - /** - * Create a digester to start with - * @return the digester - */ - protected Digester createStartDigester() - { + protected Digester createStartDigester() { Digester digester = new Digester(); - digester.setValidating(false); + digester.setValidating( false ); - digester.addObjectCreate("Server", - "org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevakServer"); - digester.addSetProperties("Server"); - digester.addSetNext("Server", - "setServer", - "org.apache.catalina.Server"); - - digester.addObjectCreate("Server/GlobalNamingResources", - "org.apache.catalina.deploy.NamingResources"); - digester.addSetProperties("Server/GlobalNamingResources"); - digester.addSetNext("Server/GlobalNamingResources", - "setGlobalNamingResources", - "org.apache.catalina.deploy.NamingResources"); - - digester.addObjectCreate("Server/Listener", - null, // MUST be specified in the element - "className"); - digester.addSetProperties("Server/Listener"); - digester.addSetNext("Server/Listener", - "addLifecycleListener", - "org.apache.catalina.LifecycleListener"); - - digester.addObjectCreate("Server/Service", - "org.apache.catalina.core.StandardService", - "className"); - digester.addSetProperties("Server/Service"); - digester.addSetNext("Server/Service", - "addService", - "org.apache.catalina.Service"); - - digester.addObjectCreate("Server/Service/Listener", - null, // MUST be specified in the element - "className"); - digester.addSetProperties("Server/Service/Listener"); - digester.addSetNext("Server/Service/Listener", - "addLifecycleListener", - "org.apache.catalina.LifecycleListener"); - - digester.addObjectCreate("Server/Service/Connector", - "org.apache.catalina.connector.http.HttpConnector", - "className"); - digester.addSetProperties("Server/Service/Connector"); - digester.addSetNext("Server/Service/Connector", - "addConnector", - "org.apache.catalina.Connector"); - - digester.addObjectCreate("Server/Service/Connector/Factory", - "org.apache.catalina.net.DefaultServerSocketFactory", - "className"); - digester.addSetProperties("Server/Service/Connector/Factory"); - digester.addSetNext("Server/Service/Connector/Factory", - "setFactory", - "org.apache.catalina.net.ServerSocketFactory"); - - digester.addObjectCreate("Server/Service/Connector/Listener", - null, // MUST be specified in the element - "className"); - digester.addSetProperties("Server/Service/Connector/Listener"); - digester.addSetNext("Server/Service/Connector/Listener", - "addLifecycleListener", - "org.apache.catalina.LifecycleListener"); - - digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/")); - digester.addRuleSet(new EngineRuleSet("Server/Service/")); - digester.addRuleSet(new HostRuleSet("Server/Service/Engine/")); - digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Default")); - digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/DefaultContext/")); - digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/Default")); - digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/DefaultContext/")); - digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/")); - digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/")); - - digester.addRule("Server/Service/Engine", - new ParentClassLoaderRule(digester, - m_parentLoader)); - return (digester); + digester.addObjectCreate( "Server", + "org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevakServer" ); + digester.addSetProperties( "Server" ); + digester.addSetNext( "Server", + "setServer", + "org.apache.catalina.Server" ); + + digester.addObjectCreate( "Server/GlobalNamingResources", + "org.apache.catalina.deploy.NamingResources" ); + digester.addSetProperties( "Server/GlobalNamingResources" ); + digester.addSetNext( "Server/GlobalNamingResources", + "setGlobalNamingResources", + "org.apache.catalina.deploy.NamingResources" ); + + digester.addObjectCreate( "Server/Listener", + null, // MUST be specified in the element + "className" ); + digester.addSetProperties( "Server/Listener" ); + digester.addSetNext( "Server/Listener", + "addLifecycleListener", + "org.apache.catalina.LifecycleListener" ); + + digester.addObjectCreate( "Server/Service", + "org.apache.catalina.core.StandardService", + "className" ); + digester.addSetProperties( "Server/Service" ); + digester.addSetNext( "Server/Service", + "addService", + "org.apache.catalina.Service" ); + + digester.addObjectCreate( "Server/Service/Listener", + null, // MUST be specified in the element + "className" ); + digester.addSetProperties( "Server/Service/Listener" ); + digester.addSetNext( "Server/Service/Listener", + "addLifecycleListener", + "org.apache.catalina.LifecycleListener" ); + + digester.addObjectCreate( "Server/Service/Connector", + "org.apache.catalina.connector.http.HttpConnector", + "className" ); + digester.addSetProperties( "Server/Service/Connector" ); + digester.addSetNext( "Server/Service/Connector", + "addConnector", + "org.apache.catalina.Connector" ); + + digester.addObjectCreate( "Server/Service/Connector/Factory", + "org.apache.catalina.net.DefaultServerSocketFactory", + "className" ); + digester.addSetProperties( "Server/Service/Connector/Factory" ); + digester.addSetNext( "Server/Service/Connector/Factory", + "setFactory", + "org.apache.catalina.net.ServerSocketFactory" ); + + digester.addObjectCreate( "Server/Service/Connector/Listener", + null, // MUST be specified in the element + "className" ); + digester.addSetProperties( "Server/Service/Connector/Listener" ); + digester.addSetNext( "Server/Service/Connector/Listener", + "addLifecycleListener", + "org.apache.catalina.LifecycleListener" ); + + digester.addRuleSet( new NamingRuleSet( "Server/GlobalNamingResources/" ) ); + digester.addRuleSet( new EngineRuleSet( "Server/Service/" ) ); + digester.addRuleSet( new HostRuleSet( "Server/Service/Engine/" ) ); + digester.addRuleSet( new ContextRuleSet( "Server/Service/Engine/Default" ) ); + digester.addRuleSet( new NamingRuleSet( "Server/Service/Engine/DefaultContext/" ) ); + digester.addRuleSet( new ContextRuleSet( "Server/Service/Engine/Host/Default" ) ); + digester.addRuleSet( new NamingRuleSet( "Server/Service/Engine/Host/DefaultContext/" ) ); + digester.addRuleSet( new ContextRuleSet( "Server/Service/Engine/Host/" ) ); + digester.addRuleSet( new NamingRuleSet( "Server/Service/Engine/Host/Context/" ) ); + + digester.addRule( "Server/Service/Engine", + new SetParentClassLoaderRule( digester, + m_parentLoader ) ); + return ( digester ); } - /** - * get the config file - * @return the File - */ - protected File getConfigFile() - { - - File file = new File(m_configFile); - if (!file.isAbsolute()) - { - file = new File(System.getProperty("catalina.base"), m_configFile); - } - return (file); + protected File configFile() { + + File file = new File( m_configFile ); + if( !file.isAbsolute() ) + file = new File( System.getProperty( "catalina.base" ), m_configFile ); + return ( file ); } } 1.2 +163 -257 jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakBootstrap.java Index: CatalinaSevakBootstrap.java =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakBootstrap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CatalinaSevakBootstrap.java 29 Sep 2002 11:38:42 -0000 1.1 +++ CatalinaSevakBootstrap.java 30 Sep 2002 22:03:12 -0000 1.2 @@ -8,6 +8,7 @@ package org.apache.avalon.apps.sevak.blocks.catalina; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import org.apache.avalon.apps.sevak.Sevak; import org.apache.avalon.apps.sevak.SevakException; import org.apache.avalon.apps.sevak.MultihostSevak; @@ -20,6 +21,7 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.phoenix.BlockContext; import java.io.File; @@ -27,318 +29,222 @@ * @phoenix:block * @phoenix:service name="org.apache.avalon.apps.sevak.MultihostSevak" * - * Catalina Sevak Bootstrapper. This class will bootstrap all Tomcat libraries dynamically. - * It also acts as a Wrapper around the CatalinaSevak class which directly utilizes Tomcat - * libraries and therefore cannot be loaded directly by Phoenix without creating hard linkages - * between the two. + * Catalina Sevak Bootstrapper. This class will bootstrap all Tomcat libraries dynamically. It also acts + * as a Wrapper around the CatalinaSevak class which directly utilizes Tomcat libraries and therefore cannot + * be loaded directly by Phoenix without creating hard linkages between the two. * - * Catalina Sevak provides the true service by directly manipulating Tomcat classes. All Catalina - * Sevak clients will call to the CatalinaSevakBootstrap which will delegate the true work to - * CatalinaSevak. + * Catalina Sevak provides the true service by directly manipulating Tomcat classes. All Catalina Sevak clients + * will call to the CatalinaSevakBootstrap which will delegate the true work to CatalinaSevak. * - * This bootstrap approach allows Tomcat to be embedded into Phoenix directly and administrated - * as a standard installation while providing the ability for other Phoenix services to deploy - * and undeploy Web Applications. + * This bootstrap approach allows Tomcat to be embedded into Phoenix directly and administrated as a standard + * installation while providing the ability for other Phoenix services to deploy and undeploy Web Applications. * * * @see Tomcat Project Page * * @author Daniel Krieg - * @version $Revision$ $Date$ + * @version 1.0 */ public class CatalinaSevakBootstrap extends AbstractLogEnabled - implements Contextualizable, Configurable, Initializable, Startable, Sevak, MultihostSevak -{ - private Context m_context; + implements Contextualizable, Configurable, Initializable, Startable, Sevak, MultihostSevak { + private BlockContext m_context; private Configuration m_configuration; private Object m_sevak; private String m_catalinaHome; private String m_catalinaBase; private boolean m_useNaming; private String m_configFile; + private final static String C_HOST = "localhost"; - /** - * Contextualize - * @param context the context - * @throws ContextException if a problem - */ - public void contextualize(Context context) throws ContextException - { - getLogger().debug("CatalinaSevakBootstrap.contextualize()"); - m_context = context; - } - - /** - * Configure block - * @param configuration the configuration - * @throws ConfigurationException if a problem - */ - public void configure(Configuration configuration) throws ConfigurationException - { - getLogger().debug("CatalinaSevakBootstrap.configure()"); + public void contextualize( Context context ) throws ContextException { + getLogger().debug( "CatalinaSevakBootstrap.contextualize()" ); + m_context = (BlockContext)context; + } + + public void configure( Configuration configuration ) throws ConfigurationException { + getLogger().debug( "CatalinaSevakBootstrap.configure()" ); m_configuration = configuration; - m_catalinaHome = m_configuration.getChild("catalina-home").getValue("default"); - m_catalinaBase = m_configuration.getChild("catalina-base").getValue("default"); - m_configFile = m_configuration.getChild("config-file").getValue("conf/server.xml"); - m_useNaming = m_configuration.getChild("use-naming").getValueAsBoolean(true); + m_catalinaHome = m_configuration.getChild( "catalina-home" ).getValue( m_context.getBaseDirectory().getAbsolutePath() + ); + m_catalinaBase = m_configuration.getChild( "catalina-base" ).getValue( m_context.getBaseDirectory().getAbsolutePath() ); + m_configFile = m_configuration.getChild( "config-file" ).getValue( "conf/server.xml" ); + m_useNaming = m_configuration.getChild( "use-naming" ).getValueAsBoolean( true ); setCatalinaHome(); setCatalinaBase(); - getLogger().debug("Catalina Home: " + getCatalinaHome()); - getLogger().debug("Catalina Base: " + getCatalinaBase()); + getLogger().debug( "Catalina Home: " + getCatalinaHome() ); + getLogger().debug( "Catalina Base: " + getCatalinaBase() ); } - /** - * Initialize - * @throws Exception if a problem - */ - public void initialize() throws Exception - { - getLogger().debug("CatalinaSevakBootstrap.initialize()"); - CatalinaSevakClassLoaderFactory catalinaSevakClassLoaderFactory - = new CatalinaSevakClassLoaderFactory(); - catalinaSevakClassLoaderFactory.enableLogging(getLogger()); + public void initialize() throws Exception { + getLogger().debug( "CatalinaSevakBootstrap.initialize()" ); + CatalinaSevakClassLoaderFactory.setLogger( getLogger() ); // Construct the class loaders we will need ClassLoader bootstrapLoader = null; ClassLoader commonLoader = null; ClassLoader sevakLoader = null; ClassLoader sharedLoader = null; - File[] unpacked = new File[1]; - File[] packed = new File[1]; - File[] packed2 = new File[2]; - - // load bootstrap classes - packed[0] = new File(getCatalinaHome(), "bin"); - bootstrapLoader = catalinaSevakClassLoaderFactory.createClassLoader(null, packed, null); - getLogger().debug("Loaded bin dir..."); - - // load common directory - unpacked[0] = new File(getCatalinaHome(), "common" + File.separator + "classes"); - packed2[0] = new File(getCatalinaHome(), "common" + File.separator + "endorsed"); - packed2[1] = new File(getCatalinaHome(), "common" + File.separator + "lib"); - commonLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed2, - bootstrapLoader); - getLogger().debug("Loaded common dir..."); - - // load server directory - unpacked[0] = new File(getCatalinaHome(), "server" + File.separator + "classes"); - packed2[0] = new File(getCatalinaHome(), "server" + File.separator + "lib"); - packed2[1] = new File(getStartupDir()); - sevakLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed2, - commonLoader); - getLogger().debug("Loaded server dir..."); - getLogger().debug("Loaded startup dir..." + packed2[1].getAbsoluteFile()); - - // load shared directory - unpacked[0] = new File(getCatalinaBase(), "shared" + File.separator + "classes"); - packed[0] = new File(getCatalinaBase(), "shared" + File.separator + "lib"); - sharedLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed, - commonLoader); - getLogger().debug("Loaded shared dir..."); - - // Load our startup class and run its lifecycle - Thread.currentThread().setContextClassLoader(commonLoader); - catalinaSevakClassLoaderFactory.securityClassLoad(commonLoader); - - // Instantiate a startup class instance - getLogger().debug("Loading startup class"); - Class startupClass = - sevakLoader.loadClass("org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevak"); - getLogger().debug("Startup class loaded: " + startupClass); - m_sevak = startupClass.newInstance(); - - // Set the shared extensions class loader - Class paramTypes[] = new Class[1]; - Object paramValues[] = new Object[1]; - getLogger().debug("Setting startup class properties"); - - String methodName = "setParentClassLoader"; - paramTypes[0] = Class.forName("java.lang.ClassLoader"); - paramValues[0] = commonLoader; - Method method = m_sevak.getClass().getMethod(methodName, paramTypes); - method.invoke(m_sevak, paramValues); - - methodName = "setUseNaming"; - paramTypes[0] = Boolean.TYPE; - paramValues[0] = (m_useNaming) ? Boolean.TRUE : Boolean.FALSE; - method = m_sevak.getClass().getMethod(methodName, paramTypes); - method.invoke(m_sevak, paramValues); - - methodName = "setConfigFile"; - paramTypes[0] = String.class; - paramValues[0] = m_configFile; - method = m_sevak.getClass().getMethod(methodName, paramTypes); - method.invoke(m_sevak, paramValues); - - methodName = "initialize"; - method = m_sevak.getClass().getMethod(methodName, null); - method.invoke(m_sevak, null); - - getLogger().debug("CatalinaSevakBootstrap complete."); - } - - /** - * Start the server - * @throws Exception if aproblem - */ - public void start() throws Exception - { - getLogger().debug("CatalinaSevakBootstrap.start()"); - m_sevak.getClass().getMethod("start", null).invoke(m_sevak, null); - } - - /** - * Stop the server - * @throws Exception if a problem - */ - public void stop() throws Exception - { - getLogger().debug("CatalinaSevakBootstrap.stop()"); - m_sevak.getClass().getMethod("stop", null).invoke(m_sevak, null); - } - - /** - * Deploy the a webapp - * @param context the context to use - * @param pathToWebAppFolder the path to the war file - * @throws SevakException if a problem - */ - public void deploy(String context, File pathToWebAppFolder) throws SevakException - { - getLogger().debug("CatalinaSevakBootstrap.deploy()"); - deploy(LOCALHOST, context, pathToWebAppFolder); - } - - /** - * Undeploy a webapp - * @param context the context - * @throws SevakException if a problem - */ - public void undeploy(String context) throws SevakException - { - getLogger().debug("CatalinaSevakBootstrap.undeploy()"); - undeploy(LOCALHOST, context); - } - - /** - * Deploy a webapp - * @param host the host to bind to - * @param context the context to use - * @param pathToWebAppFolder the path to the web app - * @throws SevakException if a problem - */ - public void deploy(String host, String context, File pathToWebAppFolder) throws SevakException - { + try { + File[] unpacked = new File[ 1 ]; + File[] packed = new File[ 1 ]; + File[] packed2 = new File[ 2 ]; + + // load bootstrap classes + packed[ 0 ] = new File( getCatalinaHome(), "bin" ); + bootstrapLoader = CatalinaSevakClassLoaderFactory.createClassLoader( null, packed, null ); + getLogger().debug( "Loaded bin dir..." ); + + // load common directory + unpacked[ 0 ] = new File( getCatalinaHome(), "common" + File.separator + "classes" ); + packed2[ 0 ] = new File( getCatalinaHome(), "common" + File.separator + "endorsed" ); + packed2[ 1 ] = new File( getCatalinaHome(), "common" + File.separator + "lib" ); + commonLoader = CatalinaSevakClassLoaderFactory.createClassLoader( unpacked, packed2, bootstrapLoader ); + getLogger().debug( "Loaded common dir..." ); + + // load server directory + unpacked[ 0 ] = new File( getCatalinaHome(), "server" + File.separator + "classes" ); + packed2[ 0 ] = new File( getCatalinaHome(), "server" + File.separator + "lib" ); + packed2[ 1 ] = new File( getStartupDir() ); + sevakLoader = CatalinaSevakClassLoaderFactory.createClassLoader( unpacked, packed2, commonLoader ); + getLogger().debug( "Loaded server dir..." ); + getLogger().debug( "Loaded startup dir..." + packed2[ 1 ].getAbsoluteFile() ); + + // load shared directory + unpacked[ 0 ] = new File( getCatalinaBase(), "shared" + File.separator + "classes" ); + packed[ 0 ] = new File( getCatalinaBase(), "shared" + File.separator + "lib" ); + sharedLoader = CatalinaSevakClassLoaderFactory.createClassLoader( unpacked, packed, commonLoader ); + getLogger().debug( "Loaded shared dir..." ); + } catch( Exception e ) { + getLogger().fatalError( "Class loader creation threw exception", e ); + throw e; + } + + try { + // Load our startup class and run its lifecycle + Thread.currentThread().setContextClassLoader( sevakLoader ); + CatalinaSevakClassLoaderFactory.securityClassLoad( sevakLoader ); + + // Instantiate a startup class instance + getLogger().debug( "Loading startup class" ); + Class startupClass = + sevakLoader.loadClass( "org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevak" ); + getLogger().debug( "Startup class loaded: " + startupClass ); + m_sevak = startupClass.newInstance(); + + // Set the shared extensions class loader + Class paramTypes[] = new Class[ 1 ]; + Object paramValues[] = new Object[ 1 ]; + getLogger().debug( "Setting startup class properties" ); + + String methodName = "setParentClassLoader"; + paramTypes[ 0 ] = Class.forName( "java.lang.ClassLoader" ); + paramValues[ 0 ] = commonLoader; + Method method = m_sevak.getClass().getMethod( methodName, paramTypes ); + method.invoke( m_sevak, paramValues ); + + methodName = "setUseNaming"; + paramTypes[ 0 ] = Boolean.TYPE; + paramValues[ 0 ] = ( m_useNaming ) ? Boolean.TRUE : Boolean.FALSE; + method = m_sevak.getClass().getMethod( methodName, paramTypes ); + method.invoke( m_sevak, paramValues ); + + methodName = "setConfigFile"; + paramTypes[ 0 ] = String.class; + paramValues[ 0 ] = m_configFile; + method = m_sevak.getClass().getMethod( methodName, paramTypes ); + method.invoke( m_sevak, paramValues ); + + methodName = "initialize"; + method = m_sevak.getClass().getMethod( methodName, null ); + method.invoke( m_sevak, null ); + } catch( Exception e ) { + getLogger().fatalError( "Exception during startup processing", e ); + throw e; + } + getLogger().debug( "CatalinaSevakBootstrap complete." ); + } + + public void start() throws Exception { + getLogger().debug( "CatalinaSevakBootstrap.start()" ); + m_sevak.getClass().getMethod( "start", null ).invoke( m_sevak, null ); + } + + public void stop() throws Exception { + getLogger().debug( "CatalinaSevakBootstrap.stop()" ); + m_sevak.getClass().getMethod( "stop", null ).invoke( m_sevak, null ); + } + + public void deploy( String context, File pathToWebAppFolder ) throws SevakException { + getLogger().debug( "CatalinaSevakBootstrap.deploy()" ); + deploy( C_HOST, context, pathToWebAppFolder ); + } + + public void undeploy( String context ) throws SevakException { + getLogger().debug( "CatalinaSevakBootstrap.undeploy()" ); + undeploy( C_HOST, context ); + } + + public void deploy( String host, String context, File pathToWebAppFolder ) throws SevakException { Class[] paramTypes = {String.class, String.class, File.class}; Object[] paramValues = {host, context, pathToWebAppFolder}; - try - { - m_sevak.getClass().getMethod("deploy", paramTypes).invoke(m_sevak, paramValues); - } - catch (Exception e) - { - throw new SevakException("Unable to deploy", e); + try { + m_sevak.getClass().getMethod( "deploy", paramTypes ).invoke( m_sevak, paramValues ); + } catch( Exception e ) { + throw new SevakException( "Unable to deploy", e ); } } - /** - * Undeploy a webapp - * @param host The host to bind to - * @param context the context for teh webapp - * @throws SevakException if a problem - */ - public void undeploy(String host, String context) throws SevakException - { + public void undeploy( String host, String context ) throws SevakException { Class[] paramTypes = {String.class, String.class}; Object[] paramValues = {host, context}; - try - { - m_sevak.getClass().getMethod("undeploy", paramTypes).invoke(m_sevak, paramValues); - } - catch (Exception e) - { - throw new SevakException("Unable to undeploy", e); + try { + m_sevak.getClass().getMethod( "undeploy", paramTypes ).invoke( m_sevak, paramValues ); + } catch( Exception e ) { + throw new SevakException( "Unable to undeploy", e ); } } - - /** - * Set the base for catalina - * This a bit dirty for Phoenix but necessary - */ - private void setCatalinaBase() - { - if (m_catalinaBase.equals("default")) - { - System.setProperty("catalina.base", getCatalinaHome()); - } - else if (m_catalinaBase.equals("user.dir")) - { - System.setProperty("catalina.base", System.getProperty("user.dir")); - } - else - { - System.setProperty("catalina.base", m_catalinaBase); + private void setCatalinaBase() { + if( m_catalinaBase.equals( "default" ) ) { + System.setProperty( "catalina.base", getCatalinaHome() ); + } else if( m_catalinaBase.equals( "user.dir" ) ) { + System.setProperty( "catalina.base", System.getProperty( "user.dir" ) ); + } else { + System.setProperty( "catalina.base", m_catalinaBase ); } } - /** - * Get the Base for Catalina. - * @return Catalina's base. - */ - private String getCatalinaBase() - { - if (System.getProperty("catalina.base") == null) - { + private String getCatalinaBase() { + if( System.getProperty( "catalina.base" ) == null ) { setCatalinaBase(); } - return System.getProperty("catalina.base"); + return System.getProperty( "catalina.base" ); } - /** - * Set the home for catalina - * This a bit dirty for Phoenix but necessary - */ - private void setCatalinaHome() - { - if (m_catalinaHome.equals("default")) - { - System.setProperty("catalina.home", System.getProperty("phoenix.home") - + File.separator + "catalina"); - } - else - { - System.setProperty("catalina.home", m_catalinaHome); + private void setCatalinaHome() { + if( m_catalinaHome.equals( "default" ) ) { + System.setProperty( "catalina.home", System.getProperty( "phoenix.home" ) + File.separator + "catalina" ); + } else { + System.setProperty( "catalina.home", m_catalinaHome ); } } - /** - * Get the Home for Catalina. - * @return Catalina's home. - */ - private String getCatalinaHome() - { - if (System.getProperty("catalina.home") == null) - { + private String getCatalinaHome() { + if( System.getProperty( "catalina.home" ) == null ) { setCatalinaHome(); } - return System.getProperty("catalina.home"); + return System.getProperty( "catalina.home" ); } - /** - * Get the directory that this was started in - * @return The directory that jar file for this block was started in. - */ - private String getStartupDir() - { + private String getStartupDir() { String startup = this.getClass().getClassLoader() - .getResource("org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevak.class") + .getResource( "org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevak.class" ) .toExternalForm(); - startup = startup.substring("jar:file:/".length(), startup.indexOf("!")); - getLogger().debug("Start up JAR " + startup); - return new File(startup).getParent(); + startup = startup.substring( "jar:file:/".length(), startup.indexOf( "!" ) ); + getLogger().debug( "Start up JAR " + startup ); + return new File( startup ).getParent(); } } 1.2 +86 -138 jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakClassLoaderFactory.java Index: CatalinaSevakClassLoaderFactory.java =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakClassLoaderFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CatalinaSevakClassLoaderFactory.java 29 Sep 2002 11:38:42 -0000 1.1 +++ CatalinaSevakClassLoaderFactory.java 30 Sep 2002 22:03:12 -0000 1.2 @@ -9,12 +9,9 @@ import java.lang.reflect.Method; - -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.CascadingRuntimeException; +import org.apache.avalon.framework.logger.Logger; import java.io.File; -import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; @@ -31,190 +28,141 @@ * @see Tomcat Project Page * * @author Daniel Krieg - * @version $Revision$ $Date$ + * @version 1.0 */ -public final class CatalinaSevakClassLoaderFactory extends AbstractLogEnabled -{ +public final class CatalinaSevakClassLoaderFactory { + private static Logger m_logger; - /** - * Create a ClassLoader for Catalina - * @param unpacked unpacked files - * @param packed packed files - * @param parent the parent classloader - * @return The classloader - * @throws IOException if a problem - * @throws ClassNotFoundException if a problem - */ - public ClassLoader createClassLoader(File unpacked[], File packed[], ClassLoader parent) - throws IOException, ClassNotFoundException - { - getLogger().debug("Creating new class loader"); + public static ClassLoader createClassLoader( File unpacked[], File packed[], ClassLoader parent ) + throws Exception { + getLogger().debug( "Creating new class loader" ); // Construct the "class path" for this class loader ArrayList stringList = new ArrayList(); ArrayList urlList = new ArrayList(); // Add unpacked directories - if (unpacked != null) - { - for (int i = 0; i < unpacked.length; i++) - { - File file = unpacked[i]; - if (!file.isDirectory() || !file.exists() || !file.canRead()) - { + if( unpacked != null ) { + for( int i = 0; i < unpacked.length; i++ ) { + File file = unpacked[ i ]; + if( !file.isDirectory() || !file.exists() || !file.canRead() ) continue; - } - getLogger().debug(" Including directory " + file.getAbsolutePath()); - URL url = new URL("file", null, - file.getCanonicalPath() + File.separator); - stringList.add(url.toString()); - urlList.add(url); + getLogger().debug( " Including directory " + file.getAbsolutePath() ); + URL url = new URL( "file", null, + file.getCanonicalPath() + File.separator ); + stringList.add( url.toString() ); + urlList.add( url ); } } // Add packed directory JAR files - if (packed != null) - { - for (int i = 0; i < packed.length; i++) - { - File directory = packed[i]; - if (!directory.isDirectory() - || !directory.exists() - || !directory.canRead()) - { + if( packed != null ) { + for( int i = 0; i < packed.length; i++ ) { + File directory = packed[ i ]; + if( !directory.isDirectory() || !directory.exists() || + !directory.canRead() ) continue; - } String filenames[] = directory.list(); - for (int j = 0; j < filenames.length; j++) - { - String filename = filenames[j].toLowerCase(); - if (!filename.endsWith(".jar")) - { + for( int j = 0; j < filenames.length; j++ ) { + String filename = filenames[ j ].toLowerCase(); + if( !filename.endsWith( ".jar" ) ) continue; - } - File file = new File(directory, filenames[j]); - getLogger().debug((" Including jar file " + file.getAbsolutePath())); - URL url = new URL("file", null, - file.getCanonicalPath()); - stringList.add(url.toString()); - urlList.add(url); + File file = new File( directory, filenames[ j ] ); + getLogger().debug( ( " Including jar file " + file.getAbsolutePath() ) ); + URL url = new URL( "file", null, + file.getCanonicalPath() ); + stringList.add( url.toString() ); + urlList.add( url ); } } } // Construct the class loader itself - String[] stringArray = (String[]) stringList.toArray(new String[stringList.size()]); - URL[] urlArray = (URL[]) urlList.toArray(new URL[urlList.size()]); - Class loaderClass = (parent == null) - ? URLClassLoader.newInstance(urlArray) - .loadClass("org.apache.catalina.loader.StandardClassLoader") - : URLClassLoader.newInstance(urlArray, parent) - .loadClass("org.apache.catalina.loader.StandardClassLoader"); + String[] stringArray = (String[]) stringList.toArray( new String[ stringList.size() ] ); + URL[] urlArray = (URL[]) urlList.toArray( new URL[ urlList.size() ] ); + Class loaderClass = ( parent == null ) ? URLClassLoader.newInstance( urlArray ).loadClass( "org.apache.catalina.loader.StandardClassLoader" ) + : URLClassLoader.newInstance( urlArray, parent ).loadClass( "org.apache.catalina.loader.StandardClassLoader" ); - getLogger().debug(loaderClass.getName() + " successfully loaded."); + getLogger().debug( loaderClass.getName() + " successfully loaded." ); Object loader = null; - if (parent == null) - { - try - { - loader = loaderClass.getConstructor(new Class[]{stringArray.getClass()}) - .newInstance(new Object[]{stringArray}); - } - catch (Exception e) - { - throw new CascadingRuntimeException("Some problem constructing using reflection",e); - } - } - else - { - try - { - loader = loaderClass.getConstructor(new Class[]{stringArray.getClass(), - ClassLoader.class}).newInstance(new Object[]{stringArray, parent}); - } - catch (Exception e) - { - throw new CascadingRuntimeException("Some problem constructing using reflection",e); - } + if( parent == null ) { + loader = loaderClass.getConstructor( new Class[]{stringArray.getClass()} ) + .newInstance( new Object[]{stringArray} ); + } else { + loader = loaderClass.getConstructor( new Class[]{stringArray.getClass(), ClassLoader.class} ) + .newInstance( new Object[]{stringArray, parent} ); } - getLogger().debug("Setting loader to delegate=true"); - try - { - Method delegating = loader.getClass().getMethod("setDelegate", - new Class[]{Boolean.TYPE}); - delegating.invoke(loader, new Object[]{Boolean.TRUE}); - } - catch (Exception e) - { - throw new CascadingRuntimeException("Some problem invoking methods using reflection",e); - } - getLogger().debug("Class Loader Intance: " + loader); + getLogger().debug( "Setting loader to delegate=true" ); + Method delegating = loader.getClass().getMethod( "setDelegate", new Class[]{Boolean.TYPE} ); + delegating.invoke( loader, new Object[]{Boolean.TRUE} ); + getLogger().debug( "Class Loader Intance: " + loader ); - getLogger().debug("ClassLoader creation completed..."); + getLogger().debug( "ClassLoader creation completed..." ); return (ClassLoader) loader; } - /** - * Load some securty stuff for Catalina. - * @param loader the loader - * @throws Exception if a problem - */ - public void securityClassLoad(ClassLoader loader) throws Exception - { + public static void securityClassLoad( ClassLoader loader ) throws Exception { - if (System.getSecurityManager() == null) - { + if( System.getSecurityManager() == null ) return; - } String basePackage = "org.apache.catalina."; loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedGetRequestDispatcher"); + ( basePackage + + "core.ApplicationContext$PrivilegedGetRequestDispatcher" ); loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedGetResource"); + ( basePackage + + "core.ApplicationContext$PrivilegedGetResource" ); loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedGetResourcePaths"); + ( basePackage + + "core.ApplicationContext$PrivilegedGetResourcePaths" ); loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedLogMessage"); + ( basePackage + + "core.ApplicationContext$PrivilegedLogMessage" ); loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedLogException"); + ( basePackage + + "core.ApplicationContext$PrivilegedLogException" ); loader.loadClass - (basePackage - + "core.ApplicationContext$PrivilegedLogThrowable"); + ( basePackage + + "core.ApplicationContext$PrivilegedLogThrowable" ); loader.loadClass - (basePackage - + "core.ApplicationDispatcher$PrivilegedForward"); + ( basePackage + + "core.ApplicationDispatcher$PrivilegedForward" ); loader.loadClass - (basePackage - + "core.ApplicationDispatcher$PrivilegedInclude"); + ( basePackage + + "core.ApplicationDispatcher$PrivilegedInclude" ); loader.loadClass - (basePackage - + "core.ContainerBase$PrivilegedAddChild"); + ( basePackage + + "core.ContainerBase$PrivilegedAddChild" ); loader.loadClass - (basePackage - + "connector.HttpRequestBase$PrivilegedGetSession"); + ( basePackage + + "connector.HttpRequestBase$PrivilegedGetSession" ); loader.loadClass - (basePackage - + "connector.HttpResponseBase$PrivilegedFlushBuffer"); + ( basePackage + + "connector.HttpResponseBase$PrivilegedFlushBuffer" ); loader.loadClass - (basePackage - + "loader.WebappClassLoader$PrivilegedFindResource"); + ( basePackage + + "loader.WebappClassLoader$PrivilegedFindResource" ); loader.loadClass - (basePackage + "session.StandardSession"); + ( basePackage + "session.StandardSession" ); loader.loadClass - (basePackage + "util.CookieTools"); + ( basePackage + "util.CookieTools" ); loader.loadClass - (basePackage + "util.URL"); - loader.loadClass(basePackage + "util.Enumerator"); - loader.loadClass("javax.servlet.http.Cookie"); + ( basePackage + "util.URL" ); + loader.loadClass( basePackage + "util.Enumerator" ); + loader.loadClass( "javax.servlet.http.Cookie" ); + + } + + + public static void setLogger( Logger logger ) { + m_logger = logger; + } + private static Logger getLogger() { + return m_logger; } } 1.2 +63 -334 jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakServer.java Index: CatalinaSevakServer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CatalinaSevakServer.java 29 Sep 2002 11:38:42 -0000 1.1 +++ CatalinaSevakServer.java 30 Sep 2002 22:03:12 -0000 1.2 @@ -1,371 +1,100 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE file. - */ package org.apache.avalon.apps.sevak.blocks.catalina; -import org.apache.catalina.Deployer; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; import org.apache.catalina.Server; import org.apache.catalina.Service; import org.apache.catalina.deploy.NamingResources; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.core.StandardServer; -/** - * Catalina Sevak Server - * - * @author Daniel Krieg - * @version $Revision$ $Date$ - */ -public class CatalinaSevakServer implements Server, Lifecycle, Runnable -{ - private static final String C_INFO = CatalinaSevakServer.class.getName(); - private LifecycleSupport m_lifecycleSupport = new LifecycleSupport(this); - private String m_shutdown = "SHUTDOWN"; - private Service[] m_services = new Service[0]; - private int m_port = 8005; - private boolean m_initialized = false; - private boolean m_started = false; - private NamingResources m_globalNamingResources; - private boolean m_serving = false; - - /** - * As per runnable - */ - public void run() - { - while (m_serving) - { - try - { - Thread.sleep(3 * 1000); // Three seconds - } - catch (InterruptedException e) - { - System.out.println("CatalinaSevakServer.run: " + e); - } - } + +public class CatalinaSevakServer implements Server, Lifecycle, Runnable { + private final StandardServer m_standardServer = new StandardServer(); + private boolean m_serving; + + public String getInfo() { + return m_standardServer.getInfo(); } - /** - * Await - */ - public void await() - { - Thread t = new Thread(this); - t.start(); + public NamingResources getGlobalNamingResources() { + return m_standardServer.getGlobalNamingResources(); } - /** - * Start - * @throws LifecycleException if a problem - */ - public void start() throws LifecycleException - { - if (m_started) - { - throw new LifecycleException("This server has already been started"); - } + public void setGlobalNamingResources( NamingResources globalNamingResources ) { + m_standardServer.setGlobalNamingResources(globalNamingResources); + } - m_lifecycleSupport.fireLifecycleEvent(BEFORE_START_EVENT, null); - m_lifecycleSupport.fireLifecycleEvent(START_EVENT, null); - m_started = true; - - synchronized (m_services) - { - for (int i = 0; i < m_services.length; i++) - { - if (m_services[i] instanceof Lifecycle) - { - ((Lifecycle) m_services[i]).start(); - } - } - } + public int getPort() { + return m_standardServer.getPort(); + } - m_lifecycleSupport.fireLifecycleEvent(AFTER_START_EVENT, null); + public void setPort( int port ) { + m_standardServer.setPort(port); } - /** - * Stop - * @throws LifecycleException if a problem - */ - public void stop() throws LifecycleException - { - if (!m_started) - { - throw new LifecycleException("This server has not yet been started"); - } + public String getShutdown() { + return m_standardServer.getShutdown(); + } - m_lifecycleSupport.fireLifecycleEvent(BEFORE_STOP_EVENT, null); - m_lifecycleSupport.fireLifecycleEvent(STOP_EVENT, null); - m_started = false; - - for (int i = 0; i < m_services.length; i++) - { - if (m_services[i] instanceof Lifecycle) - { - ((Lifecycle) m_services[i]).stop(); - } - } + public void setShutdown( String shutdown ) { + m_standardServer.setShutdown(shutdown); + } - m_lifecycleSupport.fireLifecycleEvent(AFTER_STOP_EVENT, null); + public void addService( Service service ) { + m_standardServer.addService(service); } - /** - * Initialize - * @throws LifecycleException if a problem - */ - public void initialize() throws LifecycleException - { - if (m_initialized) - { - throw new LifecycleException("This server has already been initialized"); - } - m_initialized = true; + public void await() { + Thread t = new Thread(this); + t.start(); + } - for (int i = 0; i < m_services.length; i++) - { - m_services[i].initialize(); - } + public Service findService( String name ) { + return m_standardServer.findService(name); } - /** - * Get the GlobalNamingReources - * @return the naming resources - */ - public NamingResources getGlobalNamingResources() - { - return m_globalNamingResources; - } - - /** - * Set the global naming resources - * @param globalNamingResources the global naming resources. - */ - public void setGlobalNamingResources(NamingResources globalNamingResources) - { - m_globalNamingResources = globalNamingResources; - m_globalNamingResources.setContainer(this); - } - - /** - * Add the service - * @param service the service - */ - public void addService(final Service service) - { - service.setServer(this); - - synchronized (m_services) - { - Service[] services = new Service[m_services.length + 1]; - System.arraycopy(m_services, 0, services, 0, m_services.length); - services[m_services.length] = service; - m_services = services; - - if (m_initialized) - { - try - { - service.initialize(); - } - catch (LifecycleException e) - { - e.printStackTrace(System.err); - } - } + public Service[] findServices() { + return m_standardServer.findServices(); + } - if (m_started && (service instanceof Lifecycle)) - { - try - { - ((Lifecycle) service).start(); - } - catch (LifecycleException e) - { - // nothing? - } - } - } + public void removeService( Service service ) { + m_standardServer.removeService(service); } - /** - * Find a service - * @param name the service name - * @return the service - */ - public Service findService(String name) - { - - if (name == null) - { - return (null); - } - synchronized (m_services) - { - for (int i = 0; i < m_services.length; i++) - { - if (name.equals(m_services[i].getName())) - { - return (m_services[i]); - } - } - } - return (null); + public void initialize() throws LifecycleException { + m_standardServer.initialize(); + } + public void addLifecycleListener( LifecycleListener listener ) { + m_standardServer.addLifecycleListener(listener); } - /** - * Find all services - * @return the services - */ - public Service[] findServices() - { - - return (m_services); + public LifecycleListener[] findLifecycleListeners() { + return m_standardServer.findLifecycleListeners(); + } + public void removeLifecycleListener( LifecycleListener listener ) { + m_standardServer.removeLifecycleListener(listener); } - /** - * Remove a service - * @param service the service - */ - public void removeService(Service service) - { - synchronized (m_services) - { - int j = -1; - for (int i = 0; i < m_services.length; i++) - { - if (service == m_services[i]) - { - j = i; - break; - } - } - if (j < 0) - { - return; - } - if (m_services[j] instanceof Lifecycle) - { - try - { - ((Lifecycle) m_services[j]).stop(); - } - catch (LifecycleException e) - { - // nothing? - } - } - int k = 0; - Service results[] = new Service[m_services.length - 1]; - for (int i = 0; i < m_services.length; i++) - { - if (i != j) - { - results[k++] = m_services[i]; - } - } - m_services = results; - } + public void start() throws LifecycleException { + m_serving = true; + m_standardServer.start(); + } + + public void stop() throws LifecycleException { + m_standardServer.stop(); + m_serving = false; } - /** - * Get the port - * @return the port - */ - public int getPort() - { - return m_port; - } - - /** - * Set the port - * @param port the port - */ - public void setPort(int port) - { - m_port = port; - } - - /** - * Get info - * @return info - */ - public String getInfo() - { - return C_INFO; - } - - /** - * Get shutdown property - * @return the shutdown property - */ - public String getShutdown() - { - return m_shutdown; - } - - /** - * Set the shutdown property - * @param shutdown the shutdown property - */ - public void setShutdown(String shutdown) - { - m_shutdown = shutdown; - } - - /** - * Add a lifecycle listener - * @param listener the listener - */ - public void addLifecycleListener(LifecycleListener listener) - { - m_lifecycleSupport.addLifecycleListener(listener); - } - - /** - * Find lifecycle listeners. - * @return the LifeCycle listeners - */ - public LifecycleListener[] findLifecycleListeners() - { - return m_lifecycleSupport.findLifecycleListeners(); - } - - /** - * Remove lifecycle listeners. - * @param listener the listener - */ - public void removeLifecycleListener(LifecycleListener listener) - { - m_lifecycleSupport.removeLifecycleListener(listener); - } - - /** - * A string rep of this instance - * @return the string - */ - public String toString() - { - StringBuffer sb = new StringBuffer("CatalinaSevakServer["); - sb.append(getPort()); - sb.append("]"); - return (sb.toString()); - } - - /** - * Get the deployer - * @return the deployer - */ - public Deployer getDeployer() - { - return null; + public void run() { + while(m_serving) { + try { + Thread.sleep(3 * 1000); + } catch( InterruptedException e ) { + // ignored + } + } } } 1.1 jakarta-avalon-apps/sevak/src/demo/webapps/sevak-test/WEB-INF/classes/num/NumberGuessBean.class <> 1.1 jakarta-avalon-apps/sevak/src/demo/webapps/sevak-test/WEB-INF/classes/num/NumberGuessBean.java Index: NumberGuessBean.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 * . * */ /* * Originally written by Jason Hunter, http://www.servlets.com. */ package num; import java.util.*; public class NumberGuessBean { int answer; boolean success; String hint; int numGuesses; public NumberGuessBean() { reset(); } public void setGuess(String guess) { numGuesses++; int g; try { g = Integer.parseInt(guess); } catch (NumberFormatException e) { g = -1; } if (g == answer) { success = true; } else if (g == -1) { hint = "a number next time"; } else if (g < answer) { hint = "higher"; } else if (g > answer) { hint = "lower"; } } public boolean getSuccess() { return success; } public String getHint() { return "" + hint; } public int getNumGuesses() { return numGuesses; } public void reset() { answer = Math.abs(new Random().nextInt() % 100) + 1; success = false; numGuesses = 0; } } 1.1 jakarta-avalon-apps/sevak/src/demo/webapps/sevak-test/WEB-INF/web.xml Index: web.xml =================================================================== 1.1 jakarta-avalon-apps/sevak/src/demo/webapps/sevak-test/index.jsp Index: index.jsp =================================================================== <%@ page import = "num.NumberGuessBean" %> Number Guess

Hello Mulithost Sevak


<% if (numguess.getSuccess()) { %> Congratulations! You got it. And after just <%= numguess.getNumGuesses() %> tries.

<% numguess.reset(); %> Care to try again? <% } else if (numguess.getNumGuesses() == 0) { %> Welcome to the Number Guess game.

I'm thinking of a number between 1 and 100.

What's your guess?
<% } else { %> Good guess, but nope. Try <%= numguess.getHint() %>. You have made <%= numguess.getNumGuesses() %> guesses.

I'm thinking of a number between 1 and 100.

What's your guess?
<% } %>
-- To unsubscribe, e-mail: For additional commands, e-mail: