Index: java/org/apache/commons/httpclient/HttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v retrieving revision 1.57 diff -u -r1.57 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 18 Apr 2003 12:45:48 -0000 1.57 +++ java/org/apache/commons/httpclient/HttpConnection.java 22 Apr 2003 02:18:26 -0000 @@ -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}. * @@ -1098,6 +1123,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. @@ -1263,6 +1322,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; @@ -1289,4 +1351,5 @@ /** the connection manager that created this connection or null */ private HttpConnectionManager httpConnectionManager; + } Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.134 diff -u -r1.134 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 20 Apr 2003 23:26:22 -0000 1.134 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 22 Apr 2003 02:18:31 -0000 @@ -2093,6 +2093,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"); } @@ -2138,6 +2140,8 @@ } writeRequestBody(state, conn); + // make sure the entire request body has been sent + conn.flushRequestOutputStream(); } /** Index: java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v retrieving revision 1.14 diff -u -r1.14 MultiThreadedHttpConnectionManager.java --- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 13 Apr 2003 03:51:39 -0000 1.14 +++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 22 Apr 2003 02:18:34 -0000 @@ -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"); + } + } + } } Index: test/org/apache/commons/httpclient/SimpleHttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v retrieving revision 1.13 diff -u -r1.13 SimpleHttpConnection.java --- test/org/apache/commons/httpclient/SimpleHttpConnection.java 20 Apr 2003 21:34:41 -0000 1.13 +++ test/org/apache/commons/httpclient/SimpleHttpConnection.java 22 Apr 2003 02:18:35 -0000 @@ -213,5 +213,9 @@ return bodyOutputStream; } + public void flushRequestOutputStream() throws IOException { + assertOpen(); + } + }