You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/01/27 02:24:51 UTC
cvs commit: jakarta-tomcat/src/shell tomcat.bat tomcat.sh
costin 00/01/26 17:24:51
Modified: . build.xml
src/share/org/apache/tomcat/core ContextManager.java
src/share/org/apache/tomcat/service
TcpEndpointConnector.java
src/share/org/apache/tomcat/shell/deployment server.xml
src/share/org/apache/tomcat/startup Tomcat.java
src/shell tomcat.bat tomcat.sh
Added: src/etc server.xml tomcat.xml
Removed: src/share/org/apache/tomcat/startup tomcat.xml
Log:
Another big change - use the new Tomcat starter ( still using server.xml )
This change is required in order to allow adding of new "modules"
( interceptors, adapters, etc) at config time, and uses ant-like
"patterns" to configure independent components. It is not final,
but it's better to do the move now in order to "burn" it and to
allow development of adapters. ( and also get feedback on the
"hierarchy" patterns - which is an extension to ant )
Note that stoping tomcat is done using one of the existing adapters
( Ajp12), which has a "stop" command inside (used by Apache to
restart jserv). We will add RMI later,
after more admin methods will be added ( that also mean you need
to start ajp12 instead of RMI !). It no longer use a log file,
but you need to specify the same server.xml when you start and
stop.
Again - it probably brake something, but that's good because we'll
get a chance to fix it, and we can discover more things to do!
Revision Changes Path
1.23 +5 -2 jakarta-tomcat/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/build.xml,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- build.xml 2000/01/26 22:59:58 1.22
+++ build.xml 2000/01/27 01:24:49 1.23
@@ -96,7 +96,6 @@
<mkdir dir="${tomcat.home}/webapps"/>
<mkdir dir="${tomcat.home}/webapps/ROOT"/>
- <copydir src="${tomcat.build}/webapps/ROOT" dest="${tomcat.home}/webapps/ROOT"/>
<copydir src="${tomcat.build}/bin" dest="${tomcat.home}/bin" />
<copydir src="${tomcat.build}/conf" dest="${tomcat.home}/conf"/>
<copydir src="${tomcat.build}/doc" dest="${tomcat.home}/doc"/>
@@ -104,11 +103,15 @@
<copydir src="${tomcat.build}/lib" dest="${tomcat.home}/lib"/>
<copyfile src="${tomcat.build}/LICENSE" dest="${tomcat.home}/LICENSE"/>
- <!-- Copy only war format for examples and test -->
+ <copydir src="${tomcat.build}/webapps/ROOT" dest="${tomcat.home}/webapps/ROOT"/>
+ <copydir src="${tomcat.build}/webapps/examples" dest="${tomcat.home}/webapps/examples"/>
+ <copydir src="${tomcat.build}/webapps/test" dest="${tomcat.home}/webapps/test"/>
+ <!-- Copy only war format for examples and test -->
<copyfile src="${tomcat.build}/webapps/examples.war"
dest="${tomcat.home}/webapps/examples.war"/>
<copyfile src="${tomcat.build}/webapps/test.war"
dest="${tomcat.home}/webapps/test.war"/>
+
<!-- create tomcat jar files -->
<jar jarfile="${tomcat.home}/lib/webserver.jar"
1.1 jakarta-tomcat/src/etc/server.xml
Index: server.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<Server adminPort="-1" workDir="work">
<ContextManager port="8080" hostName="" inet="">
<!--
Defaults:
defaultSessionTimeOut="30"
isWARExpanded="true"
isWARValidated="false"
isInvokerEnabled="true"
isWorkDirPersistent="false"
-->
<Context path="/" docBase="webapps/ROOT" />
<Context path="/examples" docBase="webapps/examples" />
<Context path="/test" docBase="webapps/test" />
<Connector className="org.apache.tomcat.service.http.HttpAdapter">
</Connector>
<!-- AJP12 - current JServ module -->
<Connector className="org.apache.tomcat.service.TcpEndpointConnector">
<Parameter name="handler" value="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"/>
<Parameter name="port" value="8007"/>
</Connector>
</ContextManager>
</Server>
1.1 jakarta-tomcat/src/etc/tomcat.xml
Index: tomcat.xml
===================================================================
<!-- New tomcat configuration file -->
<!-- Right now all "tags" must be associated with java classes
in Tomcat.java
Soon a <module tag="" type="" javaClass="" /> will be added,
that will allow you to add new modules without recompilation
( like taskdef in ant )
-->
<!-- Note that XmlHelper will create a java object based on
tag name + (optional) "type" attribute if present.
That should make the config file easier to read ( IMHO )
-->
<contextManager debug="1" >
<!-- ==================== ContextManager tuning ==================== -->
<requestInterceptor type="contextMapper" />
<requestInterceptor type="session" />
<requestInterceptor type="simpleMapper" debug="0" />
<!-- ==================== adapter modules ==================== -->
<adapter className="org.apache.tomcat.service.TcpEndpointConnector" port="8080"
handler="org.apache.tomcat.service.http.HttpConnectionHandler "/>
<adapter className="org.apache.tomcat.service.TcpEndpointConnector" port="8007"
handler="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"/>
<!-- ==================== Contexts ==================== -->
<context path="/" docBase="webapps/ROOT" />
<context path="/examples" docBase="webapps/examples" />
<context path="/test" docBase="webapps/test" />
</contextManager>
1.26 +4 -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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- ContextManager.java 2000/01/26 02:50:36 1.25
+++ ContextManager.java 2000/01/27 01:24:49 1.26
@@ -262,6 +262,10 @@
connectors.addElement( con );
}
+ public Enumeration getConnectors() {
+ return connectors.elements();
+ }
+
public void addRequestInterceptor( RequestInterceptor ri ) {
if(debug>0) log(" adding request intereptor " + ri.getClass().getName());
requestInterceptors.addElement( ri );
1.2 +24 -5 jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpointConnector.java
Index: TcpEndpointConnector.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpointConnector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TcpEndpointConnector.java 1999/10/09 00:20:48 1.1
+++ TcpEndpointConnector.java 2000/01/27 01:24:50 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpointConnector.java,v 1.1 1999/10/09 00:20:48 duncan Exp $
- * $Revision: 1.1 $
- * $Date: 1999/10/09 00:20:48 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpointConnector.java,v 1.2 2000/01/27 01:24:50 costin Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/01/27 01:24:50 $
*
* ====================================================================
*
@@ -130,11 +130,30 @@
public void setContextManager( ContextManager ctx ) {
this.cm=ctx;
}
+
+ public void setTcpConnectionHandler( TcpConnectionHandler handler) {
+ this.con=handler;
+ }
+
+ public TcpConnectionHandler getTcpConnectionHandler() {
+ return con;
+ }
+
+ public void setPort( int port ) {
+ this.port=port;
+ }
+
+ public void setPort( String portS ) {
+ this.port=string2Int( portS );
+ }
+
+ public int getPort() {
+ return port;
+ }
public void setProperty( String prop, String value) {
if("port".equals(prop) ) {
- // System.out.println("XXX");
- port=string2Int(value);
+ setPort( value );
}
if("handler".equals(prop)) {
try {
1.7 +0 -6 jakarta-tomcat/src/share/org/apache/tomcat/shell/deployment/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/shell/deployment/server.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- server.xml 1999/12/31 01:18:37 1.6
+++ server.xml 2000/01/27 01:24:50 1.7
@@ -1,9 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-
-<!DOCTYPE Server
- PUBLIC "-//Sun Microsystems, Inc.//DTD Servlet Server 1.0//EN"
- "file:./etc/server.dtd">
-
<!--
This is the configuration file for the JSWDK server.
@@ -12,7 +7,6 @@
file for complete configuration information:
etc/server.dtd
-
-->
<Server adminPort="-1" workDir="work">
1.5 +64 -49 jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
Index: Tomcat.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Tomcat.java 2000/01/15 23:30:27 1.4
+++ Tomcat.java 2000/01/27 01:24:50 1.5
@@ -10,6 +10,9 @@
import org.apache.tomcat.util.*;
import org.apache.tomcat.core.*;
+// Used to stop tomcat
+import org.apache.tomcat.service.TcpEndpointConnector;
+import org.apache.tomcat.service.connector.Ajp12ConnectionHandler;
/**
* Starter for Tomcat using XML.
@@ -19,6 +22,17 @@
*/
public class Tomcat {
+ static {
+ // XXX temp fix for wars
+ // Register our protocols XXX
+ String warPackage = "org.apache.tomcat.protocol";
+ String protocolKey = "java.protocol.handler.pkgs";
+ String protocolHandlers = System.getProperties().getProperty(protocolKey);
+ System.getProperties().put(protocolKey,
+ (protocolHandlers == null) ?
+ warPackage : protocolHandlers + "|" + warPackage);
+ };
+
Tomcat() {
}
@@ -35,18 +49,6 @@
xmlHelper.addMap( "requestInterceptor", "simpleMapper", "org.apache.tomcat.request.SimpleMapper");
}
- void startTomcat() throws Exception {
- File f=new File(configFile);
-
- XmlHelper xmlHelper=new XmlHelper();
- setHelper( xmlHelper );
-
- ContextManager cm=(ContextManager)xmlHelper.readXml(f);
-
- cm.start();
- System.out.println("Done with " + cm);
- }
-
// Set the mappings
void setHelperOld( XmlHelper xmlHelper ) {
xmlHelper.addMap( "Server", "org.apache.tomcat.server.HttpServer");
@@ -65,56 +67,71 @@
"contextManager");
}
- void startTomcatOld() throws Exception {
+ public void execute(String args[] ) throws Exception {
+ if( ! processArgs( args ) ) {
+ System.out.println("Wrong arguments");
+ printUsage();
+ return;
+ }
+
File f=new File(configFile);
XmlHelper xmlHelper=new XmlHelper();
xmlHelper.setDebug( 0 );
- setHelperOld( xmlHelper );
-
- org.apache.tomcat.server.HttpServer cm=(org.apache.tomcat.server.HttpServer)xmlHelper.readXml(f);
+ ContextManager cm=null;
+ if( configFile.indexOf("server.xml") <0 ) {
+ // new config format
+ setHelper( xmlHelper );
+ cm=(ContextManager)xmlHelper.readXml(f);
+ } else {
+ // old config format
+ setHelperOld( xmlHelper );
+ org.apache.tomcat.server.HttpServer server=(org.apache.tomcat.server.HttpServer)xmlHelper.readXml(f);
+ // XXX use invocation to do start!
+ cm=server.getContextManager();
+ }
- // XXX use invocation to do start!
+ if( doStop ) {
+ stopTomcat(cm);
+ return;
+ }
+
cm.start();
- System.out.println("Done with " + cm);
}
-
public static void main(String args[] ) {
try {
Tomcat tomcat=new Tomcat();
-
- if( ! tomcat.processArgs( args ) ) {
- System.out.println("Wrong arguments");
- printUsage();
- return;
- }
-
- if( tomcat.stopPort != null ) {
- tomcat.stopTomcat();
- return;
- }
-
- if( ! "server.xml".equals(tomcat.configFile) )
- tomcat.startTomcat();
- else
- tomcat.startTomcatOld();
-
-
-
+ tomcat.execute( args );
} catch(Exception ex ) {
ex.printStackTrace();
}
}
- void stopTomcat( ) {
- // use Ajp12 to stop the server...
+ /** 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( ContextManager cm ) {
+ // Find Ajp12 connector
int portInt=8007;
- try {
- portInt = Integer.valueOf(stopPort).intValue();
- } catch (NumberFormatException nfe) {
+ Enumeration enum=cm.getConnectors();
+ while( enum.hasMoreElements() ) {
+ Object con=enum.nextElement();
+ if( con instanceof TcpEndpointConnector ) {
+ TcpEndpointConnector tcpCon=(TcpEndpointConnector) con;
+ if( tcpCon.getTcpConnectionHandler() instanceof Ajp12ConnectionHandler ) {
+ portInt=tcpCon.getPort();
+ }
+ }
}
+
+ // use Ajp12 to stop the server...
try {
Socket socket = new Socket("localhost", portInt);
OutputStream os=socket.getOutputStream();
@@ -129,8 +146,8 @@
}
// -------------------- Command-line args processing --------------------
- String configFile="server.xml";
- String stopPort=null;
+ String configFile="conf/server.xml";
+ boolean doStop=false;
public static void printUsage() {
System.out.println("usage: ");
@@ -147,10 +164,8 @@
return false;
} else if (arg.equals("-stop")) {
- i++;
- if( i < args.length )
- stopPort = args[i];
- } else if (arg.equals("-f")) {
+ doStop=true;
+ } else if (arg.equals("-f") || arg.equals("-config")) {
i++;
if( i < args.length )
configFile = args[i];
1.9 +7 -4 jakarta-tomcat/src/shell/tomcat.bat
Index: tomcat.bat
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/shell/tomcat.bat,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- tomcat.bat 2000/01/26 20:12:31 1.8
+++ tomcat.bat 2000/01/27 01:24:51 1.9
@@ -1,5 +1,5 @@
@echo off
-rem $Id: tomcat.bat,v 1.8 2000/01/26 20:12:31 costin Exp $
+rem $Id: tomcat.bat,v 1.9 2000/01/27 01:24:51 costin Exp $
rem A batch file to start/stop tomcat server.
rem This batch file written and tested under Windows NT
@@ -39,19 +39,22 @@
:startServer
echo Starting tomcat in new window
echo Using classpath: %CLASSPATH%
-start java org.apache.tomcat.shell.Startup %2 %3 %4 %5 %6 %7 %8 %9
+rem start java org.apache.tomcat.shell.Startup %2 %3 %4 %5 %6 %7 %8 %9
+start java org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup
:runServer
rem Start the Tomcat Server
echo Using classpath: %CLASSPATH%
-java org.apache.tomcat.shell.Startup %2 %3 %4 %5 %6 %7 %8 %9
+rem java org.apache.tomcat.shell.Startup %2 %3 %4 %5 %6 %7 %8 %9
+java org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup
:stopServer
rem Stop the Tomcat Server
echo Using classpath: %CLASSPATH%
-java org.apache.tomcat.shell.Shutdown %2 %3 %4 %5 %6 %7 %8 %9
+rem java org.apache.tomcat.shell.Shutdown %2 %3 %4 %5 %6 %7 %8 %9
+java org.apache.tomcat.startup.Tomcat -stop %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup
goto cleanup
1.9 +7 -4 jakarta-tomcat/src/shell/tomcat.sh
Index: tomcat.sh
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/shell/tomcat.sh,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- tomcat.sh 2000/01/26 22:59:59 1.8
+++ tomcat.sh 2000/01/27 01:24:51 1.9
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $Id: tomcat.sh,v 1.8 2000/01/26 22:59:59 costin Exp $
+# $Id: tomcat.sh,v 1.9 2000/01/27 01:24:51 costin Exp $
# Shell script to start and stop the server
@@ -99,17 +99,20 @@
if [ "$1" = "start" ] ; then
shift
echo Using classpath: ${CLASSPATH}
- $JAVACMD org.apache.tomcat.shell.Startup "$@" &
+ $JAVACMD org.apache.tomcat.startup.Tomcat "$@" &
+# $JAVACMD org.apache.tomcat.shell.Startup "$@" &
elif [ "$1" = "stop" ] ; then
shift
echo Using classpath: ${CLASSPATH}
- $JAVACMD org.apache.tomcat.shell.Shutdown "$@"
+ $JAVACMD org.apache.tomcat.startup.Tomcat -stop "$@"
+# $JAVACMD org.apache.tomcat.shell.Shutdown "$@"
elif [ "$1" = "run" ] ; then
shift
echo Using classpath: ${CLASSPATH}
- $JAVACMD org.apache.tomcat.shell.Startup "$@"
+ $JAVACMD org.apache.tomcat.startup.Tomcat "$@"
+# $JAVACMD org.apache.tomcat.shell.Startup "$@"
# no &
## Call it with source tomcat.sh to set the env for tomcat