commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeri...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods PostMethod.java
Date Sun, 20 Oct 2002 13:36:43 GMT
jericho     2002/10/20 06:36:43

  Modified:    httpclient/src/java/org/apache/commons/httpclient/methods
                        PostMethod.java
  Log:
  - Use httpclient.util.URIUtil methods instead of httpclient.URIUtil
     Add log error message, when it's happened
  - minor local variable naming change
  
  Revision  Changes    Path
  1.19      +27 -20    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
  
  Index: PostMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PostMethod.java	11 Oct 2002 13:21:07 -0000	1.18
  +++ PostMethod.java	20 Oct 2002 13:36:43 -0000	1.19
  @@ -74,7 +74,8 @@
   import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.HttpState;
   import org.apache.commons.httpclient.NameValuePair;
  -import org.apache.commons.httpclient.URIUtil;
  +import org.apache.commons.httpclient.URIException;
  +import org.apache.commons.httpclient.util.URIUtil;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -745,12 +746,11 @@
       // ------------------------------------------------------------Class Methods
   
       /**
  -     * Encode the list of parameters into a urlencoded string.
  -     * TODO: consider moving this out into URIUtil.
  +     * Encode the list of parameters into a query stream.
        * 
  -     * @param params DOCUMENT ME!
  +     * @param params the list of query name and value
        * 
  -     * @return urlencoded string
  +     * @return the query stream
        * 
        * @since 1.0
        */
  @@ -758,25 +758,32 @@
           log.trace("enter PostMethod.generateRequestBody(List)");
   
           Iterator it = params.iterator();
  -        StringBuffer sb = new StringBuffer();
  +        StringBuffer buff = new StringBuffer();
   
           while (it.hasNext()) {
               NameValuePair parameter = (NameValuePair) it.next();
   
  -
  -            //TODO: make sure these encodings conform to the RFC
  -            sb.append(URIUtil.encode(parameter.getName(), 
  -                                     URIUtil.queryStringValueSafe(), false));
  -            sb.append("=");
  -            sb.append(URIUtil.encode(parameter.getValue(), 
  -                                     URIUtil.queryStringValueSafe(), true));
  -
  +            String queryName = null;
  +            try {
  +                queryName = URIUtil.encodeQuery(parameter.getName());
  +            } catch (URIException urie) {
  +                log.error("URI query name encoding error", urie);
  +                queryName = parameter.getName();
  +            }
  +            buff.append(queryName).append("=");
  +            String queryValue = null;
  +            try {
  +                queryValue = URIUtil.encodeQuery(parameter.getValue());
  +            } catch (URIException urie) {
  +                log.error("URI query value encoding error", urie);
  +                queryValue = parameter.getValue();
  +            }
               if (it.hasNext()) {
  -                sb.append("&");
  +                buff.append("&");
               }
           }
   
  -        return new ByteArrayInputStream(sb.toString().getBytes());
  +        return new ByteArrayInputStream(buff.toString().getBytes());
       }
   
       /**
  @@ -812,4 +819,4 @@
               requestContentLength = 0;
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message