commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oglu...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestWebappMethods.java
Date Mon, 16 Dec 2002 15:19:37 GMT
oglueck     2002/12/16 07:19:37

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        ChunkedOutputStream.java
               httpclient/src/java/org/apache/commons/httpclient/methods
                        PostMethod.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestWebappMethods.java
  Log:
  Fixed Chunked POST requests test case.
  
  Contributed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.2       +26 -11    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java
  
  Index: ChunkedOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChunkedOutputStream.java	25 Oct 2002 10:15:51 -0000	1.1
  +++ ChunkedOutputStream.java	16 Dec 2002 15:19:37 -0000	1.2
  @@ -73,7 +73,7 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Sean C. Sullivan
    * @author <a href="mailto:dion@apache.org">dIon Gillard</a>
  - * @author Oleg Kalnichevski
  + * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * @version $Revision$ $Date$
    *
    * @see ChunkedInputStream
  @@ -141,11 +141,9 @@
        */
       public void print(String s) throws IOException {
           log.trace("enter ChunckedOutputStream.print(String)");
  -
           if (s == null) {
               s = "null";
           }
  -
           write(s.getBytes());
       }
   
  @@ -177,9 +175,12 @@
        *
        * @param b The byte to be written
        * @throws IOException if an input/output error occurs
  +     * @throws IllegalStateException if stream already closed
        */
       public void write(int b) throws IOException {
  -
  +        if (closed){
  +            throw new IllegalStateException("Output stream already closed"); 
  +        }
           //FIXME: If using chunking, the chunks are ONE byte long!
           stream.write(ONE, 0, ONE.length);
           stream.write(CRLF, 0, CRLF.length);
  @@ -202,6 +203,9 @@
       public void write(byte[] b, int off, int len) throws IOException {
           log.trace("enter ChunckedOutputStream.write(byte[], int, int)");
   
  +        if (closed){
  +            throw new IllegalStateException("Output stream already closed"); 
  +        }
           byte chunkHeader[] = (Integer.toHexString(len) + "\r\n").getBytes();
           stream.write(chunkHeader, 0, chunkHeader.length);
           stream.write(b, off, len);
  @@ -221,8 +225,8 @@
        *
        * @throws IOException if an error occurs closing the stream
        */
  -    public void close() throws IOException {
  -        log.trace("enter ChunkedOutputStream.close()");
  +    public void writeClosingChunk() throws IOException {
  +        log.trace("enter ChunkedOutputStream.writeClosingChunk()");
   
           if (!closed) {
               try {
  @@ -232,18 +236,15 @@
                   stream.write(ENDCHUNK, 0, ENDCHUNK.length);
                   wireLog.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
               } catch (IOException e) {
  -                log.debug("Unexpected exception caught when closing output "
  -                    + " stream", e);
  +                log.debug("Unexpected exception caught when closing output stream", e);
                   throw e;
               } finally {
                   // regardless of what happens, mark the stream as closed.
                   // if there are errors closing it, there's not much we can do
                   // about it
                   closed = true;
  -                super.close();
               }
           }
  -
       }
   
       /**
  @@ -252,5 +253,19 @@
       public void flush() throws java.io.IOException {
           stream.flush();
       }
  +
  +    /**
  +     * Close this output stream, causing any buffered data to be flushed and
  +     * any further output data to throw an IOException. The underlying stream
  +     * is not closed!
  +     *
  +     * @throws IOException if an error occurs closing the stream
  +     */
  +    public void close() throws IOException {
  +        log.trace("enter ChunkedOutputStream.close()");
  +        writeClosingChunk();
  +        super.close();
  +    }
  +
   
   }
  
  
  
  1.30      +7 -4      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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PostMethod.java	11 Dec 2002 13:38:24 -0000	1.29
  +++ PostMethod.java	16 Dec 2002 15:19:37 -0000	1.30
  @@ -735,7 +735,7 @@
   
           if (this.requestContentLength == CONTENT_LENGTH_CHUNKED) {
               outstream = new ChunkedOutputStream(outstream);
  -            }
  +        }
           if (this.requestContentLength >= 0) {
               // don't need a watcher here - we're reading from something local,
               // not server-side.
  @@ -748,6 +748,9 @@
           while ((i = instream.read(tmp)) >= 0) {
               outstream.write(tmp, 0, i);
               total += i;
  +        }
  +        if (outstream instanceof ChunkedOutputStream) {
  +            ((ChunkedOutputStream)outstream).writeClosingChunk();
           }
           if ((this.requestContentLength > 0) && (total < this.requestContentLength))
{
               throw new IOException("Unexpected end of input stream after "
  
  
  
  1.9       +10 -12    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java
  
  Index: TestWebappMethods.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestWebappMethods.java	11 Dec 2002 13:38:25 -0000	1.8
  +++ TestWebappMethods.java	16 Dec 2002 15:19:37 -0000	1.9
  @@ -363,10 +363,8 @@
           assertEquals(200,method.getStatusCode());
       }
   
  -    /*
  -    //enable this when chunked requests are properly implemented
  -    //note: only few servers support this
  -    public void testPostBodyChunked() throws Exception {
  +
  +    public void testPostBodyChunked() {
           HttpClient client = new HttpClient();
           client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
  @@ -381,9 +379,9 @@
               fail("Unable to execute method : " + t.toString());
           }
           assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.</tt>")
>= 0);
  -        assertEquals(200,method.getStatusCode());
  +        assertEquals(200,method.getStatusLine().getStatusCode());
       }
  -    */
  +
   
       public void testPutBody() throws Exception {
           HttpClient client = new HttpClient();
  @@ -419,9 +417,9 @@
           }
           assertEquals(200,method.getStatusLine().getStatusCode());
           String response = method.getResponseBodyAsString();
  -        
  +
           method.recycle();
  -        
  +
           method.setPath("/" + context + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
           method.setRequestBody(new ByteArrayInputStream(body));
  
  
  

--
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