remm        02/03/08 12:52:27

  Modified:    coyote/src/java/org/apache/coyote/tomcat4
                        CoyoteProcessor.java CoyoteRequest.java
  Log:
  - Add parameters handling.
  
  Revision  Changes    Path
  1.8       +6 -5      
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java
  
  Index: CoyoteProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CoyoteProcessor.java      8 Mar 2002 19:26:01 -0000       1.7
  +++ CoyoteProcessor.java      8 Mar 2002 20:52:27 -0000       1.8
  @@ -1,6 +1,6 @@
  -/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.7 2002/03/08 19:26:01 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/03/08 19:26:01 $
  +/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.8 2002/03/08 20:52:27 remm Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/03/08 20:52:27 $
    *
    * ====================================================================
    *
  @@ -111,7 +111,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.7 $ $Date: 2002/03/08 19:26:01 $
  + * @version $Revision: 1.8 $ $Date: 2002/03/08 20:52:27 $
    */
   
   final class CoyoteProcessor
  @@ -137,6 +137,8 @@
           this.proxyPort = connector.getProxyPort();
           this.request = (CoyoteRequest) connector.createRequest();
           this.response = (CoyoteResponse) connector.createResponse();
  +        this.request.setResponse(this.response);
  +        this.response.setRequest(this.request);
           this.serverPort = connector.getPort();
           this.threadName =
               "CoyoteProcessor[" + connector.getPort() + "][" + id + "]";
  @@ -371,7 +373,6 @@
   
           parseHost();
           // parseSession(req);
  -        // parseParameters(req);
   
       }
   
  
  
  
  1.5       +146 -32   
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java
  
  Index: CoyoteRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CoyoteRequest.java        8 Mar 2002 18:50:41 -0000       1.4
  +++ CoyoteRequest.java        8 Mar 2002 20:52:27 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.4 2002/03/08 18:50:41 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/03/08 18:50:41 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.5 2002/03/08 20:52:27 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/08 20:52:27 $
    *
    * ====================================================================
    *
  @@ -91,6 +91,8 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpSession;
   
  +import org.apache.tomcat.util.http.Parameters;
  +
   import org.apache.coyote.Request;
   
   import org.apache.catalina.Connector;
  @@ -115,7 +117,7 @@
    *
    * @author Remy Maucherat
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2002/03/08 18:50:41 $
  + * @version $Revision: 1.5 $ $Date: 2002/03/08 20:52:27 $
    */
   
   public class CoyoteRequest
  @@ -200,21 +202,6 @@
   
   
       /**
  -     * The parsed parameters for this request.  This is populated only if
  -     * parameter information is requested via one of the
  -     * <code>getParameter()</code> family of method calls.  The key is the
  -     * parameter name, while the value is a String array of values for this
  -     * parameter.
  -     * <p>
  -     * <strong>IMPLEMENTATION NOTE</strong> - Once the parameters for a
  -     * particular request are parsed and stored here, they are not modified.
  -     * Therefore, application level access to the parameters need not be
  -     * synchronized.
  -     */
  -    protected ParameterMap parameters = null;
  -
  -
  -    /**
        * Authentication type.
        */
       protected String authType = null;
  @@ -242,6 +229,12 @@
   
   
       /**
  +     * Using writer flag.
  +     */
  +    protected boolean usingReader = false;
  +
  +
  +    /**
        * Context path.
        */
       protected String contextPath = "";
  @@ -284,11 +277,30 @@
   
   
       /**
  +     * Authorization parsed flag.
  +     */
  +    protected boolean authorizationParsed = false;
  +
  +
  +    /**
        * Secure flag.
        */
       protected boolean secure = false;
   
   
  +    /**
  +     * Post data buffer.
  +     */
  +    protected static int CACHED_POST_LEN = 8192;
  +    protected byte[] postData = null;
  +
  +
  +    /**
  +     * Hash map used in the getParametersMap method.
  +     */
  +    protected ParameterMap parameterMap = new ParameterMap();
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -303,6 +315,7 @@
   
           authType = null;
           usingInputStream = false;
  +        usingReader = false;
           contextPath = "";
           pathInfo = null;
           servletPath = null;
  @@ -311,15 +324,15 @@
           userPrincipal = null;
           sessionParsed = false;
           requestParametersParsed = false;
  +        authorizationParsed = false;
           secure = false;
   
           attributes.clear();
           notes.clear();
           cookies.clear();
  -        if (parameters != null) {
  -            parameters.setLocked(false);
  -            parameters.clear();
  -        }
  +
  +        parameterMap.setLocked(false);
  +        parameterMap.clear();
   
       }
   
  @@ -331,18 +344,20 @@
        * The authorization credentials sent with this Request.
        */
       protected String authorization = null;
  -    protected boolean authorizationParsed = false;
   
       /**
        * Return the authorization credentials sent with this request.
        */
       public String getAuthorization() {
  +
           if (!authorizationParsed) {
               setAuthorization(coyoteRequest.getHeader
                                (Constants.AUTHORIZATION_HEADER));
               authorizationParsed = true;
           }
  +
           return (this.authorization);
  +
       }
   
       /**
  @@ -735,7 +750,7 @@
        */
       public ServletInputStream getInputStream() throws IOException {
   
  -        if (reader != null)
  +        if (usingReader)
               throw new IllegalStateException
                   (sm.getString("requestBase.getInputStream.ise"));
   
  @@ -787,7 +802,12 @@
        * @param name Name of the desired request parameter
        */
       public String getParameter(String name) {
  -        return null;
  +
  +        if (!requestParametersParsed)
  +            parseRequestParameters();
  +
  +        return coyoteRequest.getParameters().getParameter(name);
  +
       }
   
   
  @@ -802,7 +822,21 @@
        *  and parameter values as map values.
        */
       public Map getParameterMap() {
  -        return null;
  +
  +        if (parameterMap.isLocked())
  +            return parameterMap;
  +
  +        Enumeration enum = getParameterNames();
  +        while (enum.hasMoreElements()) {
  +            String name = enum.nextElement().toString();
  +            String[] values = getParameterValues(name);
  +            parameterMap.put(name, values);
  +        }
  +
  +        parameterMap.setLocked(true);
  +
  +        return parameterMap;
  +
       }
   
   
  @@ -810,7 +844,12 @@
        * Return the names of all defined request parameters for this request.
        */
       public Enumeration getParameterNames() {
  -        return null;
  +
  +        if (!requestParametersParsed)
  +            parseRequestParameters();
  +
  +        return coyoteRequest.getParameters().getParameterNames();
  +
       }
   
   
  @@ -821,7 +860,12 @@
        * @param name Name of the desired request parameter
        */
       public String[] getParameterValues(String name) {
  -        return null;
  +
  +        if (!requestParametersParsed)
  +            parseRequestParameters();
  +
  +        return coyoteRequest.getParameters().getParameterValues(name);
  +
       }
   
   
  @@ -848,6 +892,7 @@
               throw new IllegalStateException
                   (sm.getString("requestBase.getReader.ise"));
   
  +        usingReader = true;
           if (reader == null) {
               String encoding = getCharacterEncoding();
               InputStreamReader r = new InputStreamReader(inputStream, encoding);
  @@ -1064,7 +1109,7 @@
        * @param values Corresponding values for this request parameter
        */
       public void addParameter(String name, String values[]) {
  -        parameters.put(name, values);
  +        // Not used
       }
   
   
  @@ -1096,7 +1141,7 @@
        * Clear the collection of parameters associated with this Request.
        */
       public void clearParameters() {
  -        parameters.clear();
  +        // Not used
       }
   
   
  @@ -1384,7 +1429,6 @@
       }
   
   
  -
       /**
        * Return the query string associated with this request.
        */
  @@ -1569,6 +1613,76 @@
        */
       public Principal getUserPrincipal() {
           return (userPrincipal);
  +    }
  +
  +
  +    // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Parse request parameters.
  +     */
  +    protected void parseRequestParameters() {
  +
  +        requestParametersParsed = true;
  +
  +        Parameters parameters = coyoteRequest.getParameters();
  +
  +        String enc = coyoteRequest.getCharacterEncoding();
  +        if (enc != null) {
  +            parameters.setEncoding(enc);
  +        } else {
  +            parameters.setEncoding
  +                (org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);
  +        }
  +
  +        parameters.handleQueryParameters();
  +
  +        if (usingInputStream || usingReader)
  +            return;
  +
  +        if (!getMethod().equalsIgnoreCase("POST"))
  +            return;
  +
  +        int len = getContentLength();
  +
  +        if (len > 0) {
  +            try {
  +                byte[] formData = null;
  +                if (len < CACHED_POST_LEN) {
  +                    if (postData == null)
  +                        postData = new byte[CACHED_POST_LEN];
  +                    formData = postData;
  +                } else {
  +                    formData = new byte[len];
  +                }
  +                readPostBody(formData, len);
  +                parameters.processParameters(formData, 0, len);
  +            } catch (Throwable t) {
  +                t.printStackTrace(); // TEMP
  +                ; // Ignore
  +            }
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Read post body in an array.
  +     */
  +    protected int readPostBody(byte body[], int len)
  +        throws IOException {
  +
  +        int offset = 0;
  +        do {
  +            int inputLen = getStream().read(body, offset, len - offset);
  +            if (inputLen <= 0) {
  +                return offset;
  +            }
  +            offset += inputLen;
  +        } while ((len - offset) > 0);
  +        return len;
  +
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to