www-apache-bugdb mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladislav Malyshkin <malys...@cs.wmich.edu>
Subject Re: mod_jserv/4580: Can not post may long form parameters with the same name.
Date Mon, 14 Jun 1999 14:50:03 GMT
The following reply was made to PR mod_jserv/4580; it has been noted by GNATS.

From: Vladislav Malyshkin <malyshki@cs.wmich.edu>
To: apbugs@hyperreal.org, jserv-bugdb@apache.org
Cc:  Subject: Re: mod_jserv/4580: Can not post may long form parameters with the same 
 name.
Date: Sun, 13 Jun 1999 22:50:51 -0400

 apbugs@hyperreal.org wrote:
 
 > Thank you very much for your problem report.
 > It has the internal identification `mod_jserv/4580'.
 > The individual assigned to look at your
 > report is: jserv.
 >
 > >Category:       mod_jserv
 > >Responsible:    jserv
 > >Synopsis:       Can not post may long form parameters with the same name.
 > >Arrival-Date:   Sun Jun 13 19:40:00 PDT 1999
 
 The two patches below fix this problem.
 They do the following:
 1. re-implement SUNs  javax.servlet.http.HttpUtils in org.apache.jserv.JServUtils
     and change JServConnection to use these methods.
 2.  Now we use JServUtils.URLDecode instead of  javax.servlet.http.HttpUtils.parseName
    This somehow cases garbage collector to collect unused objects.
 
 With these patches applied I am able to post big forms.
 Without them I get OutOfMemory Exception when I try to post big forms.
 
 I can send an example of such form, if necessary.
 
 Vladislav
 
 --- /tmp/d/ORIGTINAL/src/java/org/apache/jserv/JServUtils.java  Sun Apr 25 20:33:59 1999
 +++ ApacheJServ-1.0fc1/src/java/org/apache/jserv/JServUtils.java        Sun Jun 13 22:33:36
1999
 @@ -150,6 +150,100 @@
          return dec.toString();
      }
 
 +
 + /** This method parses a urlencoded string
 +   *  to a Hastable of parameters.
 +   *  @param encodedString the url-encoded string
 +   *  @return the hashtable of values
 +   */
 +  static public java.util.Hashtable parseQueryString(String encodedString)
 +    throws java.lang.IllegalArgumentException {
 +      if (encodedString == null)
 +       throw new java.lang.IllegalArgumentException();
 +
 +      final java.util.Hashtable t=new java.util.Hashtable();
 +      final int val_len=encodedString.length(),val_len_1=val_len-1;
 +      int prevPosWord=0,possepar=-1;
 +      for(int n=0;n<val_len;n++)
 +       {
 +         final char c=encodedString.charAt(n);
 +         if(c=='&' || n>=val_len_1)
 +           {
 +             final String name,value;
 +             final int last_pos= c=='&' ? n : n+1;
 +                // there is somethingt strange how garbage collector
 +                // works with encoding. If we use the same buffer
 +                // for URLDecode it some times does not release memory
 +             if(possepar<0)
 +               {
 +                 name=URLDecode(encodedString.substring(prevPosWord,last_pos));
 +                 value="";
 +               }
 +             else
 +               {
 +                 name=URLDecode(encodedString.substring(prevPosWord,possepar));
 +                 value= possepar>=val_len_1 ? "" : URLDecode(encodedString.substring(possepar+1,last_pos));
 +               }
 +             java.util.Vector v=(java.util.Vector) t.get(name);
 +             if(null==v)
 +               { // new parameter
 +                 v=new java.util.Vector();
 +                 t.put(name,v);
 +               }
 +             v.addElement(value);
 +             prevPosWord=n+1;
 +             possepar=-1;
 +           }
 +         else if(c=='=')
 +           {
 +             possepar=n;
 +           }
 +       }
 +      final int sz=t.size();
 +      if(sz<=0) return null;
 +
 +      final java.util.Enumeration e=t.keys();
 +      final java.util.Hashtable t1=new java.util.Hashtable(sz,1.0f);
 +      for(;e.hasMoreElements();)
 +       {
 +         final Object nm=e.nextElement();
 +         final java.util.Vector v=(java.util.Vector)t.get(nm);
 +         final String [] varr=new String [v.size()];
 +         final java.util.Enumeration e2=v.elements();
 +         for(int i=0;i<varr.length;i++)
 +           {
 +             varr[i]=(String)e2.nextElement();
 +           }
 +         t1.put(nm,varr);
 +       }
 +      return t1;
 + }
 +
 +
 +  /**
 +   * This method parses FORM data of
 +   * application/x-www-form-urlencoded mime type.
 +   * @param len the length of the data
 +   * @param in the input stream
 +   * @return a hashtable of the parsed key, values.
 +   */
 +  static public java.util.Hashtable parsePostData(int len,javax.servlet.ServletInputStream
in)
 +    throws java.io.IOException,java.lang.IllegalArgumentException {
 +    if (len <=0) return null;
 +
 +    final byte [] arr_bytes = new byte [len];
 +    int off=0;
 +    do {
 +      final int read_len=in.read(arr_bytes,off,len -off);
 +      if (read_len <= 0)
 +       throw new java.io.IOException ("short read");
 +      off += read_len;
 +    } while ((len - off) > 0);
 +    return parseQueryString(new String (arr_bytes, 0, 0, len));
 +  }
 +
 +
 +
      /**
       * Parse a cookie header into an array of cookies as per
       * RFC2109 - HTTP Cookies
 @@ -257,4 +351,4 @@
              return encoding;
          }
      }
 -}
 \ No newline at end of file
 +}
 
 
 And this is one more patch:
 
 
 --- /tmp/d/ORIGTINAL/src/java/org/apache/jserv/JServConnection.java     Tue Jun  8 14:52:55
1999
 +++ ApacheJServ-1.0fc1/src/java/org/apache/jserv/JServConnection.java   Sun Jun 13 22:33:35
1999
 @@ -755,7 +755,7 @@
          // Parse any query string parameters from the request
          Hashtable queryParameters = null;
          try {
 -            queryParameters = HttpUtils.parseQueryString(getQueryString());
 +            queryParameters = JServUtils.parseQueryString(getQueryString());
          } catch (IllegalArgumentException e) {
              queryParameters = null;
          }
 @@ -767,7 +767,7 @@
              try {
                  ServletInputStream is = getInputStream();
                  postParameters =
 -                    HttpUtils.parsePostData(getContentLength(), is);
 +                    JServUtils.parsePostData(getContentLength(), is);
              } catch (IllegalArgumentException e) {
                  postParameters = null;
              } catch (IOException e) {
 
 

Mime
View raw message