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/08/27 22:37:33 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/task StartTomcat.java

costin      00/08/27 13:37:32

  Modified:    src/share/org/apache/tomcat/core Context.java
                        FacadeManager.java Handler.java Request.java
                        Response.java
               src/share/org/apache/tomcat/helper RequestUtil.java
               src/share/org/apache/tomcat/service/connector
                        JNIConnectionHandler.java
               src/share/org/apache/tomcat/service/http
                        HttpResponseAdapter.java
               src/share/org/apache/tomcat/startup EmbededTomcat.java
                        Tomcat.java
               src/share/org/apache/tomcat/task StartTomcat.java
  Log:
  - fixed the build ( facade22 is in a separate module )
  
  Cosmetics:
  
  - removed dead code and old commented out code
  
  - remove Response.body - it wasn't used and broken ( charset problems )
  
  - Transformed Response.notIncluded to Response.included, and
  turned ! notIncluded in included.
  
  -  moved static methods from Response to helper ( helper need a review and
  maybe a rewrite )
  
  - removed hardcoded /home/costin from EmbededTomcat
  
  - removed duplicated code from Tomcat.java ( it is duplicated in helper,
  where it can be used by other code that needs to parse server.xml )
  
  - small changes in StartTomcat to allow Tomcat to reuse the code.
  
  Revision  Changes    Path
  1.113     +0 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- Context.java	2000/08/23 06:53:07	1.112
  +++ Context.java	2000/08/27 20:37:29	1.113
  @@ -61,7 +61,6 @@
   package org.apache.tomcat.core;
   
   import org.apache.tomcat.context.*;
  -import org.apache.tomcat.facade.*;
   import org.apache.tomcat.util.depend.*;
   import org.apache.tomcat.util.*;
   import java.security.*;
  
  
  
  1.7       +0 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java
  
  Index: FacadeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FacadeManager.java	2000/08/23 06:53:07	1.6
  +++ FacadeManager.java	2000/08/27 20:37:29	1.7
  @@ -61,7 +61,6 @@
   package org.apache.tomcat.core;
   
   import org.apache.tomcat.util.*;
  -import org.apache.tomcat.facade.*;
   import java.io.*;
   import java.net.*;
   import java.security.*;
  
  
  
  1.12      +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Handler.java	2000/08/23 06:53:07	1.11
  +++ Handler.java	2000/08/27 20:37:29	1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.11 2000/08/23 06:53:07 costin Exp $
  - * $Revision: 1.11 $
  - * $Date: 2000/08/23 06:53:07 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.12 2000/08/27 20:37:29 costin Exp $
  + * $Revision: 1.12 $
  + * $Date: 2000/08/27 20:37:29 $
    *
    * ====================================================================
    *
  @@ -62,7 +62,7 @@
    */ 
   package org.apache.tomcat.core;
   
  -import org.apache.tomcat.facade.*;
  +//import org.apache.tomcat.facade.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import java.io.*;
  
  
  
  1.56      +0 -1      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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Request.java	2000/08/22 06:56:40	1.55
  +++ Request.java	2000/08/27 20:37:29	1.56
  @@ -60,7 +60,6 @@
   
   package org.apache.tomcat.core;
   
  -import org.apache.tomcat.facade.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import org.apache.tomcat.helper.*;
  
  
  
  1.31      +49 -235   jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Response.java	2000/08/25 22:35:57	1.30
  +++ Response.java	2000/08/27 20:37:29	1.31
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.30 2000/08/25 22:35:57 alex Exp $
  - * $Revision: 1.30 $
  - * $Date: 2000/08/25 22:35:57 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.31 2000/08/27 20:37:29 costin Exp $
  + * $Revision: 1.31 $
  + * $Date: 2000/08/27 20:37:29 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,7 @@
   import javax.servlet.http.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.helper.*;
  -import org.apache.tomcat.facade.*;
  +//import org.apache.tomcat.facade.*;
   import org.apache.tomcat.logging.*;
   
   /**
  @@ -86,10 +86,10 @@
       public static final String DEFAULT_CONTENT_TYPE = "text/plain";
       public static final String DEFAULT_CHAR_ENCODING = "8859_1";
       public static final String LOCALE_DEFAULT="en";
  +    public static final Locale DEFAULT_LOCALE=new Locale(LOCALE_DEFAULT, "");
       
       protected static StringManager sm =
           StringManager.getManager("org.apache.tomcat.resources");
  -    static final Locale DEFAULT_LOCALE=new Locale(LOCALE_DEFAULT, "");
   
       protected Request request;
       protected HttpServletResponse responseFacade;
  @@ -123,10 +123,7 @@
       protected boolean usingWriter = false;
       protected boolean started = false;
       
  -    boolean notIncluded=true;
  -
  -    // default implementation will just append everything here
  -    StringBuffer body=null;
  +    boolean included=false;
       
       public Response() {
       }
  @@ -159,11 +156,11 @@
   
       // Included response behavior
       public boolean isIncluded() {
  -	return ! notIncluded;
  +	return included;
       }
   
       public void setIncluded( boolean incl ) {
  -	notIncluded= ! incl;
  +	included= incl;
   	if( incl ) {
   	    // included behavior, no header output,
   	    // no status change on errors.
  @@ -193,46 +190,28 @@
   	usingStream = false;
   	sessionId=null;
   	writer=null;
  -	//	sos=null;
   	started = false;
   	commited = false;
  -	notIncluded=true;
  -	// adapter
  -	body=null;
  -	// 	if( out != null ) out.recycle();
  -	// 	if( bBuffer != null ) bBuffer.recycle();
  +	included=false;
   	oBuffer.recycle();
   	headers.clear();
       }
   
       public void finish() throws IOException {
  -	// 	if (usingWriter && (writer != null)) {
  -	// 	    writer.flush();
  -	// 	    writer.close();
  -	// 	}
  +	if (usingWriter && (writer != null)) {
  +	    writer.flush();
  +	    //writer.close();
  +	}
   	oBuffer.flushChars();
   	oBuffer.flushBytes();
   
  -	// 	if( bBuffer != null) {
  -	// 	    bBuffer.flush();
  -	// 	    request.getContextManager().doAfterBody(request, this);
  -	// 	    return;
  -	// 	}
  -	
  -	// 	out.flush();
  -	// 	out.reallyFlush();
  -	
   	request.getContextManager().doAfterBody(request, this);
  -	//	out.close();
       }
   
       public boolean containsHeader(String name) {
   	return headers.containsHeader(name);
       }
   
  -    // XXX
  -    // mark whether or not we are being used as a stream our writer
  -
       public boolean isUsingStream() {
   	return usingStream;
       }
  @@ -247,106 +226,20 @@
   
       public void setUsingWriter( boolean writer ) {
   	usingWriter=writer;
  -	//	if( out!=null ) out.setUsingWriter(true);
       }
   
  -//     public void setWriter( PrintWriter w ) {
  -// 	this.writer=w;
  -//     }
  -    
  -//     public PrintWriter getWriter() throws IOException {
  -// 	// usingWriter
  -// 	if( writer != null )
  -// 	    return writer;
  -
  -// 	sos=getFacade().getOutputStream();
  -	    
  -// 	writer=getWriter( sos );
  -
  -// 	return writer;
  -   
  -// 	// 	if( out !=null )
  -// 	// 	    return getWriter( out );
  -	
  -// 	// it will know what to do. This method is here
  -// 	// just to keep old code happy ( internal error handlers)
  -// 	//if( usingStream ) {
  -// 	//    return getWriter( getFacade().getOutputStream());
  -// 	//}
  -// 	//return getFacade().getWriter();
  -//     }
  -
  -//     public PrintWriter getWriter(ServletOutputStream outs) throws IOException {
  -	
  -// 	if(writer!=null) return writer;
  -// 	// it already did all the checkings
  -	
  -// 	started = true;
  -// 	usingWriter = true;
  -	
  -// 	//	writer = new ServletWriterFacade( getConverter(outs), this);
  -// 	writer = new ServletWriterFacade( oBuffer, this);
  -// 	return writer;
  -//     }
  -
  -//     public Writer getConverter( ServletOutputStream outs ) throws IOException {
  -// 	String encoding = getCharacterEncoding();
  -
  -// 	if (encoding == null) {
  -// 	    // use default platform encoding - is this correct ? 
  -// 	    return  new OutputStreamWriter(outs);
  -//         }  else {
  -// 	    try {
  -// 		return  new OutputStreamWriter(outs, encoding);
  -// 	    } catch (java.io.UnsupportedEncodingException ex) {
  -// 		log("Unsuported encoding: " + encoding, Logger.ERROR );
  -
  -// 		return new OutputStreamWriter(outs);
  -// 	    }
  -// 	}
  -//     }
  -
       public OutputBuffer getBuffer() {
   	return oBuffer;
       }
       
  -//     public ByteBuffer getOutputBuffer() {
  -// 	started=true;
  -// 	return bBuffer;
  -//     }
  -
  -//     public void setOutputBuffer(ByteBuffer buf) {
  -// 	bBuffer=buf;
  -// 	if( buf!= null) buf.setParent( this );
  -//     }
  -    
  -    /** Either implement ServletOutputStream or return BufferedServletOutputStream(this)
  -	and implement doWrite();
  -	@deprecated 
  -     */
  -//     public ServletOutputStream getOutputStream() throws IOException {
  -// 	started = true;
  -// // 	if( out!=null)
  -// // 	    return out;
  -// 	// neither writer or output stream used
  -// 	if( sos == null )
  -// 	    sos=getFacade().getOutputStream();
  -
  -// 	return sos;
  -//     }
  -
  -//     public void setServletOutputStream( ServletOutputStream s ) {
  -// 	sos=s;
  -//     }
   
       // -------------------- Headers --------------------
       public MimeHeaders getMimeHeaders() {
   	return headers;
       }
   
  -
       public void setHeader(String name, String value) {
  -	if( ! notIncluded ) return; // we are in included sub-request
  +	if( included ) return; // we are in included sub-request
   	char cc=name.charAt(0);
   	if( cc=='C' || cc=='c' ) {
   	    if( checkSpecialHeader(name, value) )
  @@ -356,7 +249,7 @@
       }
   
       public void addHeader(String name, String value) {
  -	if( ! notIncluded ) return; // we are in included sub-request
  +	if( included ) return; // we are in included sub-request
   	char cc=name.charAt(0);
   	if( cc=='C' || cc=='c' ) {
   	    if( checkSpecialHeader(name, value) )
  @@ -382,8 +275,9 @@
   		setContentLength( cL );
   		return true;
   	    } catch( NumberFormatException ex ) {
  -		// We shouldn't set the header
  -		log("Bogus Content-Length: " + value, Logger.WARNING);
  +		// Do nothing - the spec doesn't have any "throws" 
  +		// and the user might know what he's doing
  +		return false;
   	    }
   	}
   	if( name.equalsIgnoreCase( "Content-Language" ) ) {
  @@ -393,8 +287,6 @@
       }
   
       public int getBufferSize() {
  -	// 	if( out!=null ) return out.getBufferSize();
  -	// 	if( bBuffer != null ) return bBuffer.getBufferSize();
   	return oBuffer.getBufferSize();
       }
   
  @@ -406,18 +298,6 @@
   	    throw new IllegalStateException ( sm.getString("servletOutputStreamImpl.setbuffer.ise"));
   	}
   	oBuffer.setBufferSize( size );
  -	// 	if( bBuffer != null ) {
  -	// 	    if( bBuffer.getBytesWritten() >0  ) {
  -	// 		throw new IllegalStateException ( sm.getString("servletOutputStreamImpl.setbuffer.ise"));
  -	// 	    }
  -	// 	    bBuffer.setBufferSize(size);
  -	// 	    return;
  -	// 	}
  -	
  -	// 	if (out.isContentWritten()  ) {
  -	// 	    throw new IllegalStateException ( sm.getString("servletOutputStreamImpl.setbuffer.ise"));
  -	// 	}
  -	// 	out.setBufferSize(size);
       }
   
       /*
  @@ -443,23 +323,21 @@
   	contentLength = -1;
   	status = 200;
   
  +	// XXX XXX What happens here ? flush() on writer will flush
  +	// to client !!!!!!!!
   	if (usingWriter == true && writer != null)
   	    writer.flush();
   
  -	body=null;
   	// Reset the stream
   	if( commited ) {
   	    String msg = sm.getString("servletOutputStreamImpl.reset.ise"); 
   	    throw new IllegalStateException(msg);
   	}
   	oBuffer.reset();
  -	// 	if (bBuffer!=null ) bBuffer.reset();
  -	// 	if( out!=null ) out.reset();
  -
           // Clear the cookies and such
   
           // Clear the headers
  -        if( notIncluded) headers.clear();
  +        if( ! included) headers.clear();
       }
   
       // Reset the response buffer but not headers and cookies
  @@ -472,21 +350,10 @@
   	    throw new IllegalStateException(msg);
   	}
   	oBuffer.reset();
  -	// 	if (bBuffer!=null ) bBuffer.reset();
  -	// 	if( out!=null ) out.reset();	// May throw IllegalStateException
  -
       }
   
       public void flushBuffer() throws IOException {
  -	//	if( notIncluded) {
  -	// 	if (usingWriter == true && writer != null)
  -	// 	    writer.flush();
  -
         oBuffer.flush();
  -
  -	// 	if( out!=null ) out.reallyFlush();
  -	// 	if(bBuffer!=null) bBuffer.flush();
  -	    //} 
       }
   
   
  @@ -504,13 +371,12 @@
        */
       public void notifyEndHeaders() throws IOException {
   	commited=true;
  -	//	log("End headers " + request.getProtocol());
   	if(request.getProtocol()==null) // HTTP/0.9 
   	    return;
   
   	// let CM notify interceptors and give a chance to fix
   	// the headers
  -	if(request.getContext() != null && notIncluded ) 
  +	if(request.getContext() != null && ! included ) 
   	    request.getContext().getContextManager().doBeforeBody(request, this);
   
   	// No action.. 
  @@ -527,7 +393,7 @@
   	    addHeader( CookieTools.getCookieHeaderName(c0),
   				CookieTools.getCookieHeaderValue(c0));
   	}
  -	if( notIncluded ) userCookies.addElement(cookie);
  +	if( ! included ) userCookies.addElement(cookie);
       }
   
       public Enumeration getCookies() {
  @@ -535,7 +401,7 @@
       }
   
       public void setSessionId( String id ) {
  -	if( notIncluded ) sessionId=id;
  +	if( ! included ) sessionId=id;
       }
   
       public String getSessionId() {
  @@ -546,8 +412,9 @@
           return locale;
       }
   
  +    // XXX XXX Need rewrite
       public void setLocale(Locale locale) {
  -        if (locale == null || ! notIncluded) {
  +        if (locale == null || included) {
               return;  // throw an exception?
           }
   
  @@ -559,38 +426,19 @@
   
           // Set the contentType for header output
           // Use the setContentType() method so encoding is set properly
  -        String newType = constructLocalizedContentType(contentType, locale);
  +        String newType = RequestUtil.constructLocalizedContentType(contentType, locale);
           setContentType(newType);
   
   	// only one header !
   	headers.putHeader("Content-Language", contentLanguage);
       }
   
  -    /** Utility method for parsing the mime type and setting
  -     *  the encoding to locale. Also, convert from java Locale to mime encodings
  -    */
  -    private static String constructLocalizedContentType(String type, Locale loc) {
  -        // Cut off everything after the semicolon
  -        int semi = type.indexOf(";");
  -        if (semi != -1) {
  -            type = type.substring(0, semi);
  -        }
  -
  -        // Append the appropriate charset, based on the locale
  -        String charset = LocaleToCharsetMap.getCharset(loc);
  -        if (charset != null) {
  -            type = type + "; charset=" + charset;
  -        }
  -
  -        return type;
  -    }
  -
       public String getCharacterEncoding() {
   	return characterEncoding;
       }
   
       public void setContentType(String contentType) {
  -        if( ! notIncluded ) return;
  +        if( included ) return;
   	this.contentType = contentType;
   	String encoding = RequestUtil.getCharsetFromContentType(contentType);
           if (encoding != null) {
  @@ -604,9 +452,9 @@
       }
       
       public void setContentLength(int contentLength) {
  -        if( ! notIncluded ) return;
  +        if( included ) return;
   	this.contentLength = contentLength;
  -	headers.putHeader("Content-Length", (new Integer(contentLength)).toString());
  +	headers.putIntHeader("Content-Length", contentLength);
       }
   
       public int getContentLength() {
  @@ -616,12 +464,11 @@
       public int getStatus() {
           return status;
       }
  -
       
       /** Set the response status 
        */ 
       public void setStatus( int status ) {
  -	if( ! notIncluded ) return;
  +	if( included ) return;
   	this.status=status;
       }
   
  @@ -630,56 +477,23 @@
        *  Headers and status will be written before this method is exceuted.
        */
       public void doWrite( byte buffer[], int pos, int count) throws IOException {
  -        // XXX fix if charset is other than default.
  -        if( body==null)
  -	    body=new StringBuffer();
  -	body.append(new String(buffer, pos, count, 
  -			       DEFAULT_CHAR_ENCODING) );
  -    }
  -
  -    public StringBuffer getBody() {
  -	return body;
  -    }
  -
  -    static String st_200=null;
  -    static String st_302=null;
  -    static String st_400=null;
  -    static String st_404=null;
  -    
  -    // utility method - should be in a different class
  -    public static String getMessage( int status ) {
  -	// hotspot, the whole thing must be rewritten.
  -	// Does HTTP requires/allow international messages or
  -	// are pre-defined? The user doesn't see them most of the time
  -	switch( status ) {
  -	case 200:
  -	    if( st_200==null ) st_200=sm.getString( "sc.200");
  -	    return st_200;
  -	case 302:
  -	    if( st_302==null ) st_302=sm.getString( "sc.302");
  -	    return st_302;
  -	case 400:
  -	    if( st_400==null ) st_400=sm.getString( "sc.400");
  -	    return st_400;
  -	case 404:
  -	    if( st_404==null ) st_404=sm.getString( "sc.404");
  -	    return st_404;
  -	}
  -	return sm.getString("sc."+ status);
  -    }
  -
  -    // write log messages to correct log
  -    
  -    Logger.Helper loghelper = new Logger.Helper("tc_log", this);
  -    
  -    protected void log(String s) {
  -	log(s, Logger.INFORMATION);
  -    }
  -    protected void log(String s, int level) {
  -	if (request != null && request.getContext() != null) {
  -	    loghelper.setLogger(request.getContext().getLoggerHelper().getLogger());
  -	}
  -	loghelper.log(s, level);
  -    }		       
  +	// do nothing.
  +	// This method must be overriden ( in the current setup ).
  +
  +	// This should call a hook and follow the same patterns with
  +	// the rest of tomcat ( I'll do that - costin )
  +    }
   
  +
  +    /*
  +      Changes:
  +
  +      - removed StringBuffer body. It was broken ( used DEFAULT_CHAR_ENCODING, the
  +      output is already bytes... ). No known usage, it's easy to create a
  +      response that stores the response.
  +      
  +      - replaced notIncluded with included, remove all ugly ! notIncluded
  +
  +
  +     */
   }
  
  
  
  1.2       +62 -1     jakarta-tomcat/src/share/org/apache/tomcat/helper/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/helper/RequestUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestUtil.java	2000/08/22 06:56:43	1.1
  +++ RequestUtil.java	2000/08/27 20:37:30	1.2
  @@ -60,6 +60,7 @@
   package org.apache.tomcat.helper;
   
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.util.*;
   import org.apache.tomcat.core.Constants;
   import java.io.*;
   import java.net.*;
  @@ -81,7 +82,9 @@
    * @author costin@eng.sun.com
    */
   public class RequestUtil {
  -
  +    protected static StringManager sm =
  +        StringManager.getManager("org.apache.tomcat.resources");
  +    
       public static Hashtable readFormData( Request request ) {
   
           String contentType=request.getContentType();
  @@ -372,6 +375,29 @@
           return encoding;
       }
   
  +    /** Utility method for parsing the mime type and setting
  +     *  the encoding to locale. Also, convert from java Locale to mime
  +     * encodings
  +     */
  +    public static String constructLocalizedContentType(String type,
  +							Locale loc) {
  +        // Cut off everything after the semicolon
  +        int semi = type.indexOf(";");
  +        if (semi != -1) {
  +            type = type.substring(0, semi);
  +        }
  +
  +        // Append the appropriate charset, based on the locale
  +        String charset = LocaleToCharsetMap.getCharset(loc);
  +        if (charset != null) {
  +            type = type + "; charset=" + charset;
  +        }
  +
  +        return type;
  +    }
  +
  +
  +    
       public static Locale getLocale(Request req) {
       	String acceptLanguage = req.getHeader("Accept-Language");
   	    if( acceptLanguage == null ) return Locale.getDefault();
  @@ -481,7 +507,42 @@
           }
       }
   
  +    static String st_200=null;
  +    static String st_302=null;
  +    static String st_400=null;
  +    static String st_404=null;
  +    
  +    /** Get the status string associated with a status code.
  +     *  No I18N - return the messages defined in the HTTP spec.
  +     *  ( the user isn't supposed to see them, this is the last
  +     *  thing to translate)
  +     *
  +     *  Common messages are cached.
  +     *
  +     */
  +    public static String getMessage( int status ) {
  +	// method from Response.
  +	
  +	// Does HTTP requires/allow international messages or
  +	// are pre-defined? The user doesn't see them most of the time
  +	switch( status ) {
  +	case 200:
  +	    if( st_200==null ) st_200=sm.getString( "sc.200");
  +	    return st_200;
  +	case 302:
  +	    if( st_302==null ) st_302=sm.getString( "sc.302");
  +	    return st_302;
  +	case 400:
  +	    if( st_400==null ) st_400=sm.getString( "sc.400");
  +	    return st_400;
  +	case 404:
  +	    if( st_404==null ) st_404=sm.getString( "sc.404");
  +	    return st_404;
  +	}
  +	return sm.getString("sc."+ status);
  +    }
   
  +    
   
       /* -------------------- From HttpDate -------------------- */
       // Parse date - XXX This code is _very_ slow ( 3 parsers, GregorianCalendar,
  
  
  
  1.15      +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java
  
  Index: JNIConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JNIConnectionHandler.java	2000/08/12 04:55:47	1.14
  +++ JNIConnectionHandler.java	2000/08/27 20:37:30	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v 1.14 2000/08/12 04:55:47 costin Exp $
  - * $Revision: 1.14 $
  - * $Date: 2000/08/12 04:55:47 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v 1.15 2000/08/27 20:37:30 costin Exp $
  + * $Revision: 1.15 $
  + * $Date: 2000/08/27 20:37:30 $
    *
    * ====================================================================
    *
  @@ -66,6 +66,7 @@
   import java.io.IOException;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import javax.servlet.ServletInputStream;
   import java.util.Vector;
   import java.io.File;
  @@ -370,7 +371,7 @@
               headerValues[i] = h.getValue();
           }
   
  -        if(h.startReasponse(s, l, status, getMessage(status), headerNames, headerValues, hcnt) <= 0) {
  +        if(h.startReasponse(s, l, status, RequestUtil.getMessage(status), headerNames, headerValues, hcnt) <= 0) {
               throw new IOException("Error: JNI startReasponse implementation error");
           }
       }
  
  
  
  1.17      +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java
  
  Index: HttpResponseAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- HttpResponseAdapter.java	2000/08/14 18:40:33	1.16
  +++ HttpResponseAdapter.java	2000/08/27 20:37:31	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.16 2000/08/14 18:40:33 costin Exp $
  - * $Revision: 1.16 $
  - * $Date: 2000/08/14 18:40:33 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.17 2000/08/27 20:37:31 costin Exp $
  + * $Revision: 1.17 $
  + * $Date: 2000/08/27 20:37:31 $
    *
    * ====================================================================
    *
  @@ -66,6 +66,7 @@
   
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.logging.*;
   import java.io.*;
   import java.net.*;
  @@ -107,7 +108,7 @@
       public void endHeaders()  throws IOException {
   	super.endHeaders();
   	
  -	sendStatus( status, Response.getMessage( status ));
  +	sendStatus( status, RequestUtil.getMessage( status ));
   
   	int count=headers.size();
   	for( int i=0; i<count; i++ ) {
  
  
  
  1.18      +9 -3      jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java
  
  Index: EmbededTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- EmbededTomcat.java	2000/08/12 04:55:48	1.17
  +++ EmbededTomcat.java	2000/08/27 20:37:32	1.18
  @@ -406,15 +406,21 @@
        */
       public static void main( String args[] ) {
   	try {
  +	    File pwdF=new File(".");
  +	    String pwd=pwdF.getCanonicalPath();
  +
   	    EmbededTomcat tc=new EmbededTomcat();
  -	    tc.setWorkDir( "/home/costin/src/jakarta/build/tomcat/work");
  +	    tc.setWorkDir( pwd + "/work"); // relative to pwd
  +
   	    ServletContext sctx;
   	    sctx=tc.addContext("", new URL
  -		( "file:/home/costin/src/jakarta/build/tomcat/webapps/ROOT"));
  +		( "file", null, pwd + "/webapps/ROOT"));
   	    tc.initContext( sctx );
  +
   	    sctx=tc.addContext("/examples", new URL
  -		("file:/home/costin/src/jakarta/build/tomcat/webapps/examples"));
  +		("file", null, pwd + "/webapps/examples"));
   	    tc.initContext( sctx );
  +
   	    tc.addEndpoint( 8080, null, null);
   	    tc.start();
   	} catch (Throwable t ) {
  
  
  
  1.40      +12 -307   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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Tomcat.java	2000/08/13 02:04:22	1.39
  +++ Tomcat.java	2000/08/27 20:37:32	1.40
  @@ -8,6 +8,8 @@
   import java.util.*;
   import java.net.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
  +import org.apache.tomcat.task.*;
   import org.apache.tomcat.util.xml.*;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.logging.*;
  @@ -29,181 +31,20 @@
   	super("tc_log");
       }
   
  -    // Set the mappings
  -    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 );
  -		}
  -	    });
  -    }
  -
  -    void setConnectorHelper( XmlMapper xh ) {
  -// 	xh.addRule( "ContextManager/Connector",
  -// 		    xh.objectCreate(null, "className"));
  -// 	xh.addRule( "ContextManager/Connector",
  -// 		    xh.setParent( "setServer", "java.lang.Object") );
  -// 	xh.addRule( "ContextManager/Connector",
  -// 		    xh.addChild( "addServerConnector",
  -// 				 "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") );
  -
  -	// Connector as ContextInterceptor - experimental
  -	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]
  -     */
  -    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
  -     * <code>-config filename</code> 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
  -     **/
  -    File getConfigFile(ContextManager cm) {
  -	// If configFile is already set, use it
  -	if (configFile != null)
  -	    return (new File(configFile));
  -
  -	// 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
  -	}
  -	// Home will be identical to tomcat home if default config is used.
  -	cm.setInstallDir(tchome);
  -	return (new File(tchome, DEFAULT_CONFIG));
  -
  -    }
  -
       public void execute(String args[] ) throws Exception {
   	if( ! processArgs( args ) ) {
   	    printUsage();
   	    return;
   	}
  -
  +	
   	if( doStop ) {
   	    System.out.println(sm.getString("tomcat.stop"));
   	    try {
  -		stopTomcat(); // stop serving
  +		org.apache.tomcat.task.StopTomcat task=
  +		    new  org.apache.tomcat.task.StopTomcat();
  +		
  +		task.setConfig( configFile );
  +		task.execute();     
   	    }
   	    catch (TomcatException te) {
   		if (te.getRootCause() instanceof java.net.ConnectException)
  @@ -214,124 +55,13 @@
   	    return;
   	}
   
  -	XmlMapper xh=new XmlMapper();
  -	xh.setDebug( 0 );
  -	ContextManager cm=new ContextManager();
  -	setHelper( xh );
  -	setConnectorHelper( xh );
  -	setLogHelper( xh );
  +	StartTomcat st=new StartTomcat();
   
   	// load server.xml
  -	File f = getConfigFile(cm);
  -	loadConfigFile(xh,f,cm);
  -
  -	// load server-*.xml
  -	Vector v = 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 }));
  +	if( configFile!=null)
  +	    st.setConfig( configFile );
   	
  -	cm.init(); // set up contexts
  -	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) {
  -	    log("Starting Tomcat: " + be.getMessage(), Logger.ERROR);
  -	    System.out.println(sm.getString("tomcat.bindexception"));
  -	    try {
  -		cm.stop();
  -	    }
  -	    catch (Exception e) {
  -		log("Stopping ContextManager", e);
  -	    }
  -	}
  -    }
  -
  -    void loadConfigFile(XmlMapper xh, File f, ContextManager cm) throws Exception {
  -	log(sm.getString("tomcat.loading") + " " + f);
  -	try {
  -	    xh.readXml(f,cm);
  -	} catch( Exception ex ) {
  -	    log( sm.getString("tomcat.fatalconfigerror"), ex );
  -	    throw ex;
  -	}
  -	log(sm.getString("tomcat.loaded") + " " + f);
  -    }
  -
  -    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<names.length; ++i) {
  -	    File found = new File(dir, names[i]);
  -	    v.addElement(found);
  -	}
  -	return v;
  -    }
  -
  -    class ConfigFilter implements FilenameFilter {
  -	String start;
  -	String end;
  -	public ConfigFilter(File master) {
  -	    String name = master.getName();
  -	    int dot = name.indexOf(".");
  -	    if (dot==-1) return;
  -	    start = name.substring(0,dot) + "-";
  -	    end = name.substring(dot);
  -	}
  -	public boolean accept(File dir, String name) {
  -	    if (start == null || end == null) return false;
  -	    if (name.startsWith(start) &&
  -		name.endsWith(end))
  -	    {
  -		return true;
  -	    }
  -	    return false;
  -	}
  -    }
  -
  -    
  -    /** 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 );     
  +	st.startTomcat();
       }
       
       public static void main(String args[] ) {
  @@ -346,31 +76,6 @@
   
       }
   
  -    /** 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();
  -	setConnectorHelper( xh );
  -	File f = getConfigFile(cm);
  -	try {
  -	    xh.readXml(f,cm);
  -	} catch( Exception ex ) {
  -	    throw new TomcatException("Fatal exception reading " + f, ex);
  -	}
  -	
  -	org.apache.tomcat.task.StopTomcat stopTc=
  -	    new  org.apache.tomcat.task.StopTomcat();
  -	stopTc.execute( cm );     
  -    }
  -    
       // -------------------- Command-line args processing --------------------
       // null means user didn't set one
       String configFile=null;
  
  
  
  1.2       +9 -5      jakarta-tomcat/src/share/org/apache/tomcat/task/StartTomcat.java
  
  Index: StartTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/StartTomcat.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StartTomcat.java	2000/08/18 03:42:16	1.1
  +++ StartTomcat.java	2000/08/27 20:37:32	1.2
  @@ -102,7 +102,10 @@
   	    task.execute();     
   	    return;
   	}
  -	    
  +	startTomcat();
  +    }
  +
  +    public void startTomcat() throws Exception {
   	XmlMapper xh=new XmlMapper();
   	xh.setDebug( 0 );
   	ContextManager cm=new ContextManager();
  @@ -113,14 +116,15 @@
   	sxml.setConnectorHelper( xh );
   	sxml.setLogHelper( xh );
   
  +	String tchome=sxml.getTomcatInstall();
  +	cm.setInstallDir( tchome);
  +
   	// 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);
  +	else
  +	    f=new File(tchome, DEFAULT_CONFIG);
   
   	loadConfigFile(xh,f,cm);