tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util RequestUtil.java CookieUtil.java
Date Sat, 15 Apr 2000 23:36:17 GMT
craigmcc    00/04/15 16:36:17

  Modified:    proposals/catalina/src/share/org/apache/tomcat/connector
                        HttpRequestBase.java RequestBase.java
                        RequestStream.java
               proposals/catalina/src/share/org/apache/tomcat/connector/http
                        HttpProcessor.java HttpRequestImpl.java
  Added:       proposals/catalina/src/share/org/apache/tomcat/connector
                        Constants.java LocalStrings.properties
               proposals/catalina/src/share/org/apache/tomcat/util
                        RequestUtil.java
  Removed:     proposals/catalina/src/share/org/apache/tomcat/util
                        CookieUtil.java
  Log:
  Finish factoring of request processing components.  The implementation
  class is not yet complete, but those changes will be localized.  The base
  classes (RequestBase and HttpRequestBase) because some APIs really do need
  to be specific to an implementation -- for example, there is no generic
  implementation for the ServletRequest.getParameter() family of methods on
  non-HTTP requests.
  
  Make RequestStream (which implements ServletInputStream) respect the
  content length if it is specified.
  
  Revision  Changes    Path
  1.2       +6 -46     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java
  
  Index: HttpRequestBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpRequestBase.java	2000/04/14 18:55:27	1.1
  +++ HttpRequestBase.java	2000/04/15 23:36:15	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v
1.1 2000/04/14 18:55:27 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/04/14 18:55:27 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v
1.2 2000/04/15 23:36:15 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/04/15 23:36:15 $
    *
    * ====================================================================
    *
  @@ -79,13 +79,13 @@
    * Convenience base implementation of the <b>HttpRequest</b> interface, which
    * can be used for the Request implementation required by most Connectors that
    * implement the HTTP protocol.  Only the connector-specific methods need to
  - * be implemented.
  + * be implemented, which are marked abstract in this class.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/04/14 18:55:27 $
  + * @version $Revision: 1.2 $ $Date: 2000/04/15 23:36:15 $
    */
   
  -public class HttpRequestBase
  +public abstract class HttpRequestBase
       extends RequestBase
       implements HttpRequest, HttpServletRequest {
   
  @@ -244,46 +244,6 @@
       public void setUserPrincipal(Principal principal) {
   
   	this.userPrincipal = principal;
  -
  -    }
  -
  -
  -    // ------------------------------------------------- ServletRequest Methods
  -
  -
  -    /**
  -     * Return the value of the specified request parameter, if any; otherwise,
  -     * return <code>null</code>.  If there is more than one value defined,
  -     * return only the first one.
  -     *
  -     * @param name Name of the desired request parameter
  -     */
  -    public String getParameter(String name) {
  -
  -	return (null);	// FIXME: getParameter()
  -
  -    }
  -
  -
  -    /**
  -     * Return the names of all defined request parameters for this request.
  -     */
  -    public Enumeration getParameterNames() {
  -
  -	return (null);	// FIXME: getParameterNames()
  -
  -    }
  -
  -
  -    /**
  -     * Return the defined values for the specified request parameter, if any;
  -     * otherwise, return <code>null</code>.
  -     *
  -     * @param name Name of the desired request parameter
  -     */
  -    public String[] getParameterValues(String name) {
  -
  -	return (null);	// FIXME: getParameterValues()
   
       }
   
  
  
  
  1.4       +105 -47   jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java
  
  Index: RequestBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RequestBase.java	2000/04/14 18:55:27	1.3
  +++ RequestBase.java	2000/04/15 23:36:15	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v
1.3 2000/04/14 18:55:27 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/04/14 18:55:27 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v
1.4 2000/04/15 23:36:15 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/04/15 23:36:15 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   
   import java.io.BufferedReader;
   import java.io.InputStream;
  +import java.io.InputStreamReader;
   import java.io.IOException;
   import java.security.Principal;
   import java.util.Enumeration;
  @@ -74,6 +75,7 @@
   import java.util.Locale;
   import java.util.Vector;
   import javax.servlet.RequestDispatcher;
  +import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.ServletInputStream;
   import javax.servlet.ServletRequest;
  @@ -81,18 +83,21 @@
   import org.apache.tomcat.Context;
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
  +import org.apache.tomcat.util.RequestUtil;
  +import org.apache.tomcat.util.StringManager;
   
   
   /**
    * Convenience base implementation of the <b>Request</b> interface, which can
    * be used for the Request implementation required by most Connectors.  Only
  - * the connector-specific methods need to be implemented.
  + * the connector-specific methods need to be implemented, which are marked
  + * abstract in this class.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/04/14 18:55:27 $
  + * @version $Revision: 1.4 $ $Date: 2000/04/15 23:36:15 $
    */
   
  -public class RequestBase
  +public abstract class RequestBase
       implements ServletRequest, Request {
   
   
  @@ -137,6 +142,12 @@
   
   
       /**
  +     * The input stream associated with this Request.
  +     */
  +    protected InputStream input = null;
  +
  +
  +    /**
        * The preferred Locales assocaited with this Request.
        */
       protected Vector locales = new Vector();
  @@ -149,12 +160,24 @@
   
   
       /**
  +     * The reader that has been returned by <code>getReader</code>, if any.
  +     */
  +    protected BufferedReader reader = null;
  +
  +
  +    /**
        * The remote address associated with this request.
        */
       protected String remoteAddr = null;
   
   
       /**
  +     * The fully qualified name of the remote host.
  +     */
  +    protected String remoteHost = null;
  +
  +
  +    /**
        * The response with which this request is associated.
        */
       protected Response response = null;
  @@ -185,9 +208,17 @@
   
   
       /**
  -     * The input stream associated with this Request.
  +     * The string manager for this package.
  +     */
  +    protected static StringManager sm =
  +	StringManager.getManager(Constants.Package);
  +
  +
  +    /**
  +     * The ServletInputStream that has been returned by
  +     * <code>getInputStream()</code>, if any.
        */
  -    protected InputStream stream = null;
  +    protected ServletInputStream stream = null;
   
   
       // ------------------------------------------------------------- Properties
  @@ -290,7 +321,7 @@
        */
       public InputStream getStream() {
   
  -	return (this.stream);
  +	return (this.input);
   
       }
   
  @@ -298,11 +329,11 @@
       /**
        * Set the input stream associated with this Request.
        *
  -     * @param stream The new input stream
  +     * @param input The new input stream
        */
  -    public void setStream(InputStream stream) {
  +    public void setStream(InputStream input) {
   
  -	this.stream = stream;
  +	this.input = input;
   
       }
   
  @@ -325,7 +356,9 @@
   
       /**
        * Create and return a ServletInputStream to read the content
  -     * associated with this Request.
  +     * associated with this Request.  The default implementation creates an
  +     * instance of RequestStream associated with this request, but this can
  +     * be overridden if necessary.
        *
        * @exception IOException if an input/output error occurs
        */
  @@ -347,10 +380,15 @@
   	contentLength = -1;
   	contentType = null;
   	context = null;
  +	input = null;
   	locales.removeAllElements();
   	protocol = null;
  +	reader = null;
  +	remoteAddr = null;
  +	remoteHost = null;
   	response = null;
   	scheme = null;
  +	secure = false;
   	serverName = null;
   	serverPort = -1;
   	stream = null;
  @@ -397,20 +435,31 @@
   
   
       /**
  -     * Set the remote IP address associated with this Request.  NOTE:  This
  -     * value will be used to resolve the value for <code>getRemoteHost()</code>
  -     * if that method is called.
  +     * Set the IP address of the remote client associated with this Request.
        *
  -     * @param remote The remote IP address
  +     * @param remoteAddr The remote IP address
        */
  -    public void setRemoteAddr(String remote) {
  +    public void setRemoteAddr(String remoteAddr) {
   
  -	this.remoteAddr = remote;
  +	this.remoteAddr = remoteAddr;
   
       }
   
   
       /**
  +     * Set the fully qualified name of the remote client associated with this
  +     * Request.
  +     *
  +     * @param remoteHost The remote host name
  +     */
  +    public void setRemoteHost(String remoteHost) {
  +
  +	this.remoteHost = remoteHost;
  +
  +    }
  +
  +
  +    /**
        * Set the name of the scheme associated with this request.  Typical values
        * are <code>http</code>, <code>https</code>, and <code>ftp</code>.
        *
  @@ -492,7 +541,7 @@
        */
       public String getCharacterEncoding() {
   
  -	return (null);	// FIXME: getCharacterEncoding()
  +	return (RequestUtil.parseCharacterEncoding(getContentType()));
   
       }
   
  @@ -518,7 +567,9 @@
   
   
       /**
  -     * Return the servlet input stream for this Request.
  +     * Return the servlet input stream for this Request.  The default
  +     * implementation returns a servlet input stream created by
  +     * <code>createInputStream()</code>.
        *
        * @exception IllegalStateException if <code>getReader()</code> has
        *  already been called for this request
  @@ -526,7 +577,13 @@
        */
       public ServletInputStream getInputStream() throws IOException {
   
  -	return (null);	// FIXME: getInputStream()
  +	if (reader != null)
  +	    throw new IllegalStateException
  +		(sm.getString("requestBase.getInputStream.ise"));
  +
  +	if (stream == null)
  +	    stream = createInputStream();
  +	return (stream);
   
       }
   
  @@ -571,34 +628,22 @@
        *
        * @param name Name of the desired request parameter
        */
  -    public String getParameter(String name) {
  -
  -	return (null);	// FIXME: getParameter()
  +    public abstract String getParameter(String name);
   
  -    }
   
  -
       /**
        * Return the names of all defined request parameters for this request.
        */
  -    public Enumeration getParameterNames() {
  +    public abstract Enumeration getParameterNames();
   
  -	return (null);	// FIXME: getParameterNames()
   
  -    }
  -
  -
       /**
        * Return the defined values for the specified request parameter, if any;
        * otherwise, return <code>null</code>.
        *
        * @param name Name of the desired request parameter
        */
  -    public String[] getParameterValues(String name) {
  -
  -	return (null);	// FIXME: getParameterValues()
  -
  -    }
  +    public abstract String[] getParameterValues(String name);
   
   
       /**
  @@ -612,15 +657,26 @@
   
   
       /**
  -     * Read the Reader wrapping the input stream for this Request.
  +     * Read the Reader wrapping the input stream for this Request.  The
  +     * default implementation wraps a <code>BufferedReader</code> around the
  +     * servlet input stream returned by <code>createInputStream()</code>.
        *
        * @exception IllegalStateException if <code>getInputStream()</code>
        *  has already been called for this request
        * @exception IOException if an input/output error occurs
        */
  -    public BufferedReader getReader() {
  +    public BufferedReader getReader() throws IOException {
   
  -	return (null);	// FIXME: getReader()
  +	if (stream != null)
  +	    throw new IllegalStateException
  +		(sm.getString("requestBase.getReader.ise"));
  +
  +	if (reader == null) {
  +	    InputStreamReader isr =	// FIXME: encoding choice?
  +		new InputStreamReader(createInputStream());
  +	    reader = new BufferedReader(isr);
  +	}
  +	return (reader);
   
       }
   
  @@ -635,7 +691,13 @@
        */
       public String getRealPath(String path) {
   
  -	return (null);	// FIXME: getRealPath()
  +	if (context == null)
  +	    return (null);
  +	ServletContext servletContext = context.getServletContext();
  +	if (servletContext == null)
  +	    return (null);
  +	else
  +	    return (servletContext.getRealPath(path));
   
       }
   
  @@ -655,7 +717,7 @@
        */
       public String getRemoteHost() {
   
  -	return (null);	// FIXME: getRemoteHost()
  +	return (this.remoteHost);
   
       }
   
  @@ -666,11 +728,7 @@
        *
        * @param path Path of the resource to be wrapped
        */
  -    public RequestDispatcher getRequestDispatcher(String path) {
  -
  -	return (null);	// FIXME: getRequestDispatcher()
  -
  -    }
  +    public abstract RequestDispatcher getRequestDispatcher(String path);
   
   
       /**
  
  
  
  1.2       +74 -13    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestStream.java
  
  Index: RequestStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestStream.java	2000/02/20 02:55:06	1.1
  +++ RequestStream.java	2000/04/15 23:36:15	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestStream.java,v
1.1 2000/02/20 02:55:06 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/02/20 02:55:06 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestStream.java,v
1.2 2000/04/15 23:36:15 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/04/15 23:36:15 $
    *
    * ====================================================================
    *
  @@ -69,19 +69,20 @@
   import java.io.IOException;
   import javax.servlet.ServletInputStream;
   import org.apache.tomcat.Request;
  +import org.apache.tomcat.util.StringManager;
   
   
   /**
    * Convenience implementation of <b>ServletInputStream</b> that works with
  - * the standard RequestBase implementation of <b>Request</b>.
  + * the standard implementations of <b>Request</b>.  If the content length has
  + * been set on our associated Request, this implementation will enforce
  + * not reading more than that many bytes on the underlying stream.
    *
  - * <b>FIXME</b>:  Enforce reading up to content length if specified
  - *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/02/20 02:55:06 $
  + * @version $Revision: 1.2 $ $Date: 2000/04/15 23:36:15 $
    */
   
  -final class RequestStream
  +public final class RequestStream
       extends ServletInputStream {
   
   
  @@ -96,8 +97,10 @@
       public RequestStream(Request request) {
   
   	super();
  -	this.request = request;
  -	this.stream = request.getStream();
  +	closed = false;
  +	count = 0;
  +	length = request.getRequest().getContentLength();
  +	stream = request.getStream();
   
       }
   
  @@ -105,13 +108,33 @@
       // ----------------------------------------------------- Instance Variables
   
   
  +    /**
  +     * Has this stream been closed?
  +     */
  +    private boolean closed = false;
  +
  +
  +    /**
  +     * The number of bytes which have already been returned by this stream.
  +     */
  +    private int count = 0;
  +
  +
       /**
  -     * The Request with which this input stream is associated.
  +     * The content length past which we will not read, or -1 if there is
  +     * no defined content length.
        */
  -    private Request request = null;
  +    private int length = -1;
   
   
       /**
  +     * The localized strings for this package.
  +     */
  +    private static StringManager sm =
  +	StringManager.getManager(Constants.Package);
  +
  +
  +    /**
        * The underlying input stream from which we should read data.
        */
       private InputStream stream = null;
  @@ -120,14 +143,52 @@
       // --------------------------------------------------------- Public Methods
   
   
  +    /**
  +     * Close this input stream.  No physical level I-O is performed, but
  +     * any further attempt to read from this stream will throw an IOException.
  +     * If a content length has been set but not all of the bytes have yet been
  +     * consumed, the remaining bytes will be swallowed.
  +     */
  +    public void close() throws IOException {
  +
  +	if (closed)
  +	    throw new IOException(sm.getString("requestStream.close.closed"));
  +
  +	if (length > 0) {
  +	    while (count < length) {
  +		int b = read();
  +		if (b < 0)
  +		    break;
  +	    }
  +	}
  +
  +	closed = true;
  +
  +    }
  +
  +
  +
       /**
  -     * Read and return a single byte from this input stream.
  +     * Read and return a single byte from this input stream, or -1 if end of
  +     * file has been encountered.
        *
        * @exception IOException if an input/output error occurs
        */
       public int read() throws IOException {
   
  -	return (stream.read());
  +	// Has this stream been closed?
  +	if (closed)
  +	    throw new IOException(sm.getString("requestStream.read.closed"));
  +
  +	// Have we read the specified content length already?
  +	if ((length >= 0) && (count >= length))
  +	    return (-1);	// End of file indicator
  +
  +	// Read and count the next byte, then return it
  +	int b = stream.read();
  +	if (b >= 0)
  +	    count++;
  +	return (b);
   
       }
   
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/Constants.java
  
  Index: Constants.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/Constants.java,v
1.1 2000/04/15 23:36:15 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/04/15 23:36:15 $
   *
   * ====================================================================
   *
   * 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
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.connector;
  
  
  /**
   * Static constants for this package.
   */
  
  public final class Constants {
  
      public static final String Package = "org.apache.tomcat.connector";
  
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  requestBase.getInputStream.ise=getReader() has already been called for this request
  requestBase.getReader.ise=getInputStream() has already been called for this request
  requestStream.close.closed=Cannot close the same input stream twice
  requestStream.read.closed=This input stream has been closed
  
  
  
  1.4       +6 -6      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java
  
  Index: HttpProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpProcessor.java	2000/04/15 05:39:15	1.3
  +++ HttpProcessor.java	2000/04/15 23:36:16	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v
1.3 2000/04/15 05:39:15 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/04/15 05:39:15 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v
1.4 2000/04/15 23:36:16 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/04/15 23:36:16 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
   import org.apache.tomcat.LifecycleException;
   import org.apache.tomcat.LifecycleListener;
   import org.apache.tomcat.Logger;
  -import org.apache.tomcat.util.CookieUtil;
  +import org.apache.tomcat.util.RequestUtil;
   import org.apache.tomcat.util.LifecycleSupport;
   import org.apache.tomcat.util.StringManager;
   
  @@ -97,7 +97,7 @@
    * the request.  When the processor is completed, it will recycle itself.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/04/15 05:39:15 $
  + * @version $Revision: 1.4 $ $Date: 2000/04/15 23:36:16 $
    */
   
   final class HttpProcessor
  @@ -307,7 +307,7 @@
   	    if (match.equals("authorization")) {
   		;	// FIXME -- do not want to include with regular headers
   	    } else if (match.equals("cookie")) {
  -		Cookie cookies[] = CookieUtil.parseCookieHeader(value);
  +		Cookie cookies[] = RequestUtil.parseCookieHeader(value);
   		for (int i = 0; i < cookies.length; i++)
   		    request.addCookie(cookies[i]);
   	    } else if (match.equals("content-length")) {
  
  
  
  1.3       +100 -10   jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java
  
  Index: HttpRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpRequestImpl.java	2000/04/15 05:39:16	1.2
  +++ HttpRequestImpl.java	2000/04/15 23:36:16	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java,v
1.2 2000/04/15 05:39:16 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/04/15 05:39:16 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java,v
1.3 2000/04/15 23:36:16 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/04/15 23:36:16 $
    *
    * ====================================================================
    *
  @@ -65,15 +65,21 @@
   package org.apache.tomcat.connector.http;
   
   
  +import java.io.BufferedReader;
  +import java.io.IOException;
   import java.net.InetAddress;
  +import java.util.Enumeration;
  +import javax.servlet.RequestDispatcher;
  +import javax.servlet.ServletInputStream;
   import org.apache.tomcat.connector.HttpRequestBase;
  +import org.apache.tomcat.connector.RequestStream;
   
   
   /**
    * Implementation of <b>HttpRequest</b> specific to the HTTP connector.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/04/15 05:39:16 $
  + * @version $Revision: 1.3 $ $Date: 2000/04/15 23:36:16 $
    */
   
   final class HttpRequestImpl
  @@ -139,6 +145,87 @@
   
   
       /**
  +     * Release all object references, and initialize instance variables, in
  +     * preparation for reuse of this object.
  +     */
  +    public void recycle() {
  +
  +	super.recycle();
  +	inet = null;
  +	((HttpConnector) connector).recycle(this);
  +
  +    }
  +
  +
  +    // ------------------------------------------------- ServletRequest Methods
  +
  +
  +    /**
  +     * Return the servlet input stream for this Request.
  +     *
  +     * @exception IllegalStateException if <code>getReader()</code> has
  +     *  already been called for this request
  +     * @exception IOException if an input/output error occurs
  +     */
  +    public ServletInputStream getInputStream() throws IOException {
  +
  +	return (null);	// FIXME: getInputStream()
  +
  +    }
  +
  +
  +    /**
  +     * Return the value of the specified request parameter, if any; otherwise,
  +     * return <code>null</code>.  If there is more than one value defined,
  +     * return only the first one.
  +     *
  +     * @param name Name of the desired request parameter
  +     */
  +    public String getParameter(String name) {
  +
  +	return (null);	// FIXME: getParameter()
  +
  +    }
  +
  +
  +    /**
  +     * Return the names of all defined request parameters for this request.
  +     */
  +    public Enumeration getParameterNames() {
  +
  +	return (null);	// FIXME: getParameterNames()
  +
  +    }
  +
  +
  +    /**
  +     * Return the defined values for the specified request parameter, if any;
  +     * otherwise, return <code>null</code>.
  +     *
  +     * @param name Name of the desired request parameter
  +     */
  +    public String[] getParameterValues(String name) {
  +
  +	return (null);	// FIXME: getParameterValues()
  +
  +    }
  +
  +
  +    /**
  +     * Read the Reader wrapping the input stream for this Request.
  +     *
  +     * @exception IllegalStateException if <code>getInputStream()</code>
  +     *  has already been called for this request
  +     * @exception IOException if an input/output error occurs
  +     */
  +    public BufferedReader getReader() {
  +
  +	return (null);	// FIXME: getReader()
  +
  +    }
  +
  +
  +    /**
        * Return the Internet Protocol (IP) address of the client that sent
        * this request.
        */
  @@ -161,16 +248,19 @@
   
   
       /**
  -     * Release all object references, and initialize instance variables, in
  -     * preparation for reuse of this object.
  +     * Return a RequestDispatcher that wraps the resource at the specified
  +     * path, which may be interpreted as relative to the current request path.
  +     *
  +     * @param path Path of the resource to be wrapped
        */
  -    public void recycle() {
  +    public RequestDispatcher getRequestDispatcher(String path) {
   
  -	super.recycle();
  -	inet = null;
  -	((HttpConnector) connector).recycle(this);
  +	return (null);	// FIXME: getRequestDispatcher()
   
       }
  +
  +
  +    // --------------------------------------------- HttpServletRequest Methods
   
   
   }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/RequestUtil.java,v
1.1 2000/04/15 23:36:17 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/04/15 23:36:17 $
   *
   * ====================================================================
   *
   * 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
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.util;
  
  
  import java.util.StringTokenizer;
  import java.util.Vector;
  import javax.servlet.http.Cookie;
  
  
  /**
   * General purpose request parsing and encoding utility methods.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/04/15 23:36:17 $
   */
  
  public final class RequestUtil {
  
  
      /**
       * Parse the character encoding from the specified content type header.
       * If the content type is null, or there is no explicit character encoding,
       * ISO-8859-1 is returned.
       *
       * @param contentType a content type header
       */
      public static String parseCharacterEncoding(String contentType) {
  
  	if (contentType == null)
  	    return ("ISO-8859-1");
  	int start = contentType.indexOf("charset=");
  	if (start < 0)
  	    return ("ISO-8859-1");
  	String encoding = contentType.substring(start + 8);
  	int end = encoding.indexOf(";");
  	if (end >= 0)
  	    encoding = encoding.substring(0, end);
  	return (encoding.trim());
  
      }
  
  
      /**
       * Parse a cookie header into an array of cookies according to RFC 2109.
       *
       * @param header Value of an HTTP "Cookie" header
       */
      public static Cookie[] parseCookieHeader(String header) {
  
  	if ((header == null) || (header.length() < 1))
  	    return (new Cookie[0]);
  
  	Vector cookieJar = new Vector();
  	StringTokenizer tokens = new StringTokenizer(header, ";");
  	while (tokens.hasMoreTokens()) {
  	    try {
  		String token = tokens.nextToken();
  		int equals = token.indexOf("=");
  		if (equals > 0) {
  		    String name = URLDecode(token.substring(0, equals).trim());
  		    String value = URLDecode(token.substring(equals+1).trim());
  		    cookieJar.addElement(new Cookie(name, value));
  		}
  	    } catch (Throwable e) {
  		;
  	    }
  	}
  
  	Cookie[] cookies = new Cookie[cookieJar.size()];
  	cookieJar.copyInto(cookies);
  	return (cookies);
  
      }
  
  
      /**
       * Decode and return the specified URL-encoded String.
       *
       * @param str The url-encoded string
       *
       * @exception IllegalArgumentException if a '%' character is not followed
       * by a valid 2-digit hexadecimal number
       */
      public static String URLDecode(String str)
  	throws IllegalArgumentException {
  
  	if (str == null)
  	    return (null);
  
  	StringBuffer dec = new StringBuffer();
  	int pos = 0;
  	int len = str.length();
  	dec.ensureCapacity(str.length());
  
  	while (pos < len) {
  	    int lookahead;	// Look-ahead position
  
  	    // Look ahead to the next URLencoded metacharacter, if any
  	    for (lookahead = pos; lookahead < len; lookahead++) {
  		char ch = str.charAt(lookahead);
  		if ((ch == '+') || (ch == '%'))
  		    break;
  	    }
  
  	    // If there were non-metacharacters, copy them as a block
  	    if (lookahead > pos) {
  		dec.append(str.substring(pos, lookahead));
  		pos = lookahead;
  	    }
  
  	    // Shortcut out if we are at the end of the string
  	    if (pos >= len)
  		break;
  
  	    // Process the next metacharacter
  	    char meta = str.charAt(pos);
  	    if (meta == '+') {
  		dec.append(' ');
  		pos++;
  	    } else if (meta == '%') {
  		try {
  		    dec.append((char) Integer.parseInt
  			       (str.substring(pos+1, pos+3), 16));
  		} catch (NumberFormatException e) {
  		    throw new IllegalArgumentException
  			("Invalid hexadecimal '" + str.substring(pos+1, pos+3)
  			 + " in URLencoded string");
  		} catch (StringIndexOutOfBoundsException e) {
  		    throw new IllegalArgumentException
  			("Invalid unescaped '%' in URLcoded string");
  		}
  		pos += 3;
  	    }
  	}
  	return (dec.toString());
  
      }
  
  }
  
  
  

Mime
View raw message