commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods EntityEnclosingMethod.java MultipartPostMethod.java
Date Tue, 15 Jul 2003 12:40:57 GMT
mbecke      2003/07/15 05:40:57

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java ContentLengthInputStream.java
               httpclient/src/java/org/apache/commons/httpclient/methods
                        EntityEnclosingMethod.java MultipartPostMethod.java
  Log:
  Adds support for large(long) content.
  
  PR: 21323
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.167     +9 -9      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.166
  retrieving revision 1.167
  diff -u -r1.166 -r1.167
  --- HttpMethodBase.java	15 Jul 2003 02:19:58 -0000	1.166
  +++ HttpMethodBase.java	15 Jul 2003 12:40:56 -0000	1.167
  @@ -668,7 +668,7 @@
        *          If <tt>Content-Length</tt> header is not present, the method

        *          returns  <tt>-1</tt>.
        */
  -    protected int getResponseContentLength() {
  +    protected long getResponseContentLength() {
           Header[] headers = getResponseHeaderGroup().getHeaders("Content-Length");
           if (headers.length == 0) {
               return -1;
  @@ -679,7 +679,7 @@
           for (int i = headers.length - 1; i >= 0; i++) {
               Header header = headers[i];
               try {
  -                return Integer.parseInt(header.getValue());
  +                return Long.parseLong(header.getValue());
               } catch (NumberFormatException e) {
                   if (LOG.isWarnEnabled()) {
                       LOG.warn("Invalid content-length value: " + e.getMessage());
  @@ -1362,7 +1362,7 @@
        *
        * @return <tt>0</tt>, indicating that the request has no body.
        */
  -    protected int getRequestContentLength() {
  +    protected long getRequestContentLength() {
           return 0;
       }
   
  @@ -1424,7 +1424,7 @@
                     + "HttpState, HttpConnection)");
   
           // add content length or chunking
  -        int len = getRequestContentLength();
  +        long len = getRequestContentLength();
           if (getRequestHeader("content-length") == null) {
               if (0 < len) {
                   setRequestHeader("Content-Length", String.valueOf(len));
  @@ -2081,7 +2081,7 @@
                   result = is;  
               }
           } else {
  -            int expectedLength = getResponseContentLength();
  +            long expectedLength = getResponseContentLength();
               if (expectedLength == -1) {
                   if (canResponseHaveBody(statusLine.getStatusCode())) {
                       setConnectionCloseForced(true);
  
  
  
  1.7       +21 -7     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java
  
  Index: ContentLengthInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContentLengthInputStream.java	28 Jan 2003 04:40:20 -0000	1.6
  +++ ContentLengthInputStream.java	15 Jul 2003 12:40:56 -0000	1.7
  @@ -70,7 +70,7 @@
   /**
    * Cuts the wrapped InputStream off after a specified number of bytes.
    *
  - * @author Ortwin Glück
  + * @author Ortwin Gl�ck
    * @author Eric Johnson
    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
    * @since 2.0
  @@ -82,15 +82,17 @@
        * The maximum number of bytes that can be read from the stream. Subsequent
        * read operations will return -1.
        */
  -    private int contentLength;
  +    private long contentLength;
   
       /** The current position */
  -    private int pos = 0;
  +    private long pos = 0;
   
       /** True if the stream is closed. */
       private boolean closed = false;
   
       /**
  +     * @deprecated use {@link #ContentLengthInputStream(InputStream, long)}
  +     * 
        * Creates a new length limited stream
        *
        * @param in The stream to wrap
  @@ -103,6 +105,18 @@
       }
   
       /**
  +     * Creates a new length limited stream
  +     *
  +     * @param in The stream to wrap
  +     * @param contentLength The maximum number of bytes that can be read from
  +     * the stream. Subsequent read operations will return -1.
  +     */
  +    public ContentLengthInputStream(InputStream in, long contentLength) {
  +        super(in);
  +        this.contentLength = contentLength;
  +    }
  +
  +    /**
        * <p>Reads until the end of the known length of content.</p>
        *
        * <p>Does not close the underlying socket input, but instead leaves it
  @@ -162,7 +176,7 @@
           }
   
           if (pos + len > contentLength) {
  -            len = contentLength - pos;
  +            len = (int) (contentLength - pos);
           }
           int count = super.read(b, off, len);
           pos += count;
  
  
  
  1.22      +35 -8     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
  
  Index: EntityEnclosingMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- EntityEnclosingMethod.java	15 Jul 2003 02:19:58 -0000	1.21
  +++ EntityEnclosingMethod.java	15 Jul 2003 12:40:57 -0000	1.22
  @@ -128,7 +128,7 @@
       /** The content length of the <code>requestBodyStream</code> or one of
        *  <code>CONTENT_LENGTH_AUTO</code> and <code>CONTENT_LENGTH_CHUNKED</code>.
        */
  -    private int requestContentLength = CONTENT_LENGTH_AUTO;
  +    private long requestContentLength = CONTENT_LENGTH_AUTO;
   
       // ----------------------------------------------------------- Constructors
   
  @@ -244,6 +244,8 @@
       }
   
       /**
  +     * @deprecated use {@link #setRequestContentLength(long)} instead
  +     * 
        * Sets length information about the request body.
        *
        * <p>
  @@ -269,12 +271,37 @@
       }
   
       /**
  +     * Sets length information about the request body.
  +     *
  +     * <p>
  +     * Note: If you specify a content length the request is unbuffered. This
  +     * prevents redirection and automatic retry if a request fails the first
  +     * time. This means that the HttpClient can not perform authorization
  +     * automatically but will throw an Exception. You will have to set the
  +     * necessary 'Authorization' or 'Proxy-Authorization' headers manually.
  +     * </p>
  +     *
  +     * @param length size in bytes or any of CONTENT_LENGTH_AUTO,
  +     *        CONTENT_LENGTH_CHUNKED. If number of bytes or CONTENT_LENGTH_CHUNKED
  +     *        is specified the content will not be buffered internally and the
  +     *        Content-Length header of the request will be used. In this case
  +     *        the user is responsible to supply the correct content length.
  +     *        If CONTENT_LENGTH_AUTO is specified the request will be buffered
  +     *        before it is sent over the network.
  +     *
  +     */
  +    public void setRequestContentLength(long length) {
  +        LOG.trace("enter EntityEnclosingMethod.setRequestContentLength(int)");
  +        this.requestContentLength = length;
  +    }
  +
  +    /**
        * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
        * to return the length of the request body.
        *
        * @return number of bytes in the request body
        */
  -    protected int getRequestContentLength() {
  +    protected long getRequestContentLength() {
           LOG.trace("enter EntityEnclosingMethod.getRequestContentLength()");
   
           if (!hasRequestContent()) {
  @@ -309,7 +336,7 @@
   
           if ((getRequestHeader("content-length") == null) 
               && (getRequestHeader("Transfer-Encoding") == null)) {
  -            int len = getRequestContentLength();
  +            long len = getRequestContentLength();
               if (len >= 0) {
                   addRequestHeader("Content-Length", String.valueOf(len));
               } else if ((len == CONTENT_LENGTH_CHUNKED) && (isHttp11())) {
  @@ -404,7 +431,7 @@
               return true;
           }
   
  -        int contentLength = getRequestContentLength();
  +        long contentLength = getRequestContentLength();
   
           if ((contentLength == CONTENT_LENGTH_CHUNKED) && !isHttp11()) {
               throw new ProtocolException(
  
  
  
  1.19      +5 -11     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java
  
  Index: MultipartPostMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- MultipartPostMethod.java	5 Jul 2003 18:43:04 -0000	1.18
  +++ MultipartPostMethod.java	15 Jul 2003 12:40:57 -0000	1.19
  @@ -250,16 +250,10 @@
        * 
        * @return The request content length.
        */
  -    protected int getRequestContentLength() {
  +    protected long getRequestContentLength() {
           LOG.trace("enter MultipartPostMethod.getRequestContentLength()");
           try {
  -            long len = Part.getLengthOfParts(getParts());
  -            // Chop the length to the max int value.
  -            if (len <= Integer.MAX_VALUE) {
  -                return (int) len;
  -            } else {
  -                return (Integer.MAX_VALUE);
  -            }
  +            return Part.getLengthOfParts(getParts());
           } catch (IOException e) {
               // Can't throw an IOException and still override
               throw new RuntimeException(e.toString());
  
  
  

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


Mime
View raw message