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/test/org/apache/commons/httpclient SimpleHttpConnection.java
Date Sun, 27 Apr 2003 19:43:42 GMT
mbecke      2003/04/27 12:43:42

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java HttpConnection.java
                        MultiThreadedHttpConnectionManager.java
               httpclient/src/test/org/apache/commons/httpclient
                        SimpleHttpConnection.java
  Log:
  Adds HttpConnection output stream buffering.
  
  PR: 19208
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.139     +8 -4      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.138
  retrieving revision 1.139
  diff -u -r1.138 -r1.139
  --- HttpMethodBase.java	26 Apr 2003 10:26:05 -0000	1.138
  +++ HttpMethodBase.java	27 Apr 2003 19:43:41 -0000	1.139
  @@ -2117,6 +2117,8 @@
           writeRequestLine(state, conn);
           writeRequestHeaders(state, conn);
           conn.writeLine(); // close head
  +        // make sure the status line and headers have been sent
  +        conn.flushRequestOutputStream();
           if (Wire.enabled()) {
               Wire.output("\r\n");
           }
  @@ -2162,6 +2164,8 @@
           }
   
           writeRequestBody(state, conn);
  +        // make sure the entire request body has been sent
  +        conn.flushRequestOutputStream();
       }
   
       /**
  
  
  
  1.60      +69 -6     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- HttpConnection.java	25 Apr 2003 18:03:28 -0000	1.59
  +++ HttpConnection.java	27 Apr 2003 19:43:41 -0000	1.60
  @@ -63,6 +63,7 @@
   
   package org.apache.commons.httpclient;
   
  +import java.io.BufferedOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InterruptedIOException;
  @@ -661,8 +662,14 @@
   
               socket.setTcpNoDelay(soNodelay);
               socket.setSoTimeout(soTimeout);
  +            if (sendBufferSize != -1) {
  +                socket.setSendBufferSize(sendBufferSize);
  +            }
               inputStream = new PushbackInputStream(socket.getInputStream());
  -            outputStream = new WrappedOutputStream(socket.getOutputStream());
  +            outputStream = new BufferedOutputStream(
  +                new WrappedOutputStream(socket.getOutputStream()),
  +                socket.getSendBufferSize()
  +            );
               isOpen = true;
               used = false;
           } catch (IOException e) {
  @@ -708,8 +715,14 @@
               (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
   
           socket = socketFactory.createSocket(socket, hostName, portNumber, true);
  +        if (sendBufferSize != -1) {
  +            socket.setSendBufferSize(sendBufferSize);
  +        }        
           inputStream = new PushbackInputStream(socket.getInputStream());
  -        outputStream = socket.getOutputStream();
  +        outputStream = new BufferedOutputStream(
  +            new WrappedOutputStream(socket.getOutputStream()),
  +            socket.getSendBufferSize()
  +        );
           usingSecureSocket = true;
           tunnelEstablished = true;
           LOG.debug("Secure tunnel created");
  @@ -726,6 +739,18 @@
       }
   
       /**
  +     * Flushes the output request stream.  This method should be called to 
  +     * ensure that data written to the request OutputStream is sent to the server.
  +     * 
  +     * @throws IOException if an I/O problem occurs
  +     */
  +    public void flushRequestOutputStream() throws IOException {
  +        LOG.trace("enter HttpConnection.flushRequestOutputStream()");
  +        assertOpen();
  +        outputStream.flush();
  +    }
  +
  +    /**
        * Return a {@link OutputStream} suitable for writing (possibly
        * chunked) bytes to my {@link OutputStream}.
        *
  @@ -1099,6 +1124,40 @@
           }
       }
   
  +    /**
  +     * Gets the socket's sendBufferSize.
  +     * 
  +     * @return the size of the buffer for the socket OutputStream, -1 if the value
  +     * has not been set and the socket has not been opened
  +     * 
  +     * @throws SocketException if an error occurs while getting the socket value
  +     * 
  +     * @see Socket#getSendBufferSize()
  +     */
  +    public int getSendBufferSize() throws SocketException {
  +        if (socket == null) {
  +            return -1;
  +        } else {
  +            return socket.getSendBufferSize();
  +        }
  +    }
  +
  +    /**
  +     * Sets the socket's sendBufferSize.
  +     * 
  +     * @param sendBufferSize the size to set for the socket OutputStream
  +     * 
  +     * @throws SocketException if an error occurs while setting the socket value
  +     * 
  +     * @see Socket#setSendBufferSize(int)
  +     */
  +    public void setSendBufferSize(int sendBufferSize) throws SocketException {
  +        this.sendBufferSize = sendBufferSize;
  +        if (socket != null) {
  +            socket.setSendBufferSize(sendBufferSize);
  +        }
  +    }
  +
       // -- Timeout Exception
       /**
        * Signals that a timeout occured while opening the socket.
  @@ -1264,6 +1323,9 @@
       /** My OutputStream. */
       private OutputStream outputStream = null;
       
  +    /** the size of the buffer to use for the socket OutputStream */
  +    private int sendBufferSize = -1;
  +    
       /** An {@link InputStream} for the response to an individual request. */
       private InputStream lastResponseInputStream = null;
       
  @@ -1290,4 +1352,5 @@
       
       /** the connection manager that created this connection or null */
       private HttpConnectionManager httpConnectionManager;
  +
   }
  
  
  
  1.15      +51 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MultiThreadedHttpConnectionManager.java	13 Apr 2003 03:51:39 -0000	1.14
  +++ MultiThreadedHttpConnectionManager.java	27 Apr 2003 19:43:41 -0000	1.15
  @@ -1033,6 +1033,54 @@
               }
           }
   
  +        public void flushRequestOutputStream() throws IOException {
  +            if (hasConnection()) {
  +                wrappedConnection.flushRequestOutputStream();
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public int getSoTimeout() throws SocketException {
  +            if (hasConnection()) {
  +                return wrappedConnection.getSoTimeout();
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public String getVirtualHost() {
  +            if (hasConnection()) {
  +                return wrappedConnection.getVirtualHost();
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public void setVirtualHost(String host) throws IllegalStateException {
  +            if (hasConnection()) {
  +                wrappedConnection.setVirtualHost(host);
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public int getSendBufferSize() throws SocketException {
  +            if (hasConnection()) {
  +                return wrappedConnection.getSendBufferSize();
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public void setSendBufferSize(int sendBufferSize) throws SocketException {
  +            if (hasConnection()) {
  +                wrappedConnection.setSendBufferSize(sendBufferSize);
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
       }
   
   }
  
  
  
  1.14      +7 -3      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java
  
  Index: SimpleHttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SimpleHttpConnection.java	20 Apr 2003 21:34:41 -0000	1.13
  +++ SimpleHttpConnection.java	27 Apr 2003 19:43:42 -0000	1.14
  @@ -213,5 +213,9 @@
           return bodyOutputStream;
       }
   
  +    public void flushRequestOutputStream() throws IOException {
  +        assertOpen();
  +    }
  +
   }
   
  
  
  

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