Index: java/org/apache/commons/httpclient/HttpClient.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.86
diff -u -r1.86 HttpClient.java
--- java/org/apache/commons/httpclient/HttpClient.java 11 Oct 2003 19:46:51 -0000 1.86
+++ java/org/apache/commons/httpclient/HttpClient.java 17 Oct 2003 16:13:34 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v 1.86 2003/10/11 19:46:51 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v 1.86 2003/10/11 19:46:51 olegk Exp $
* $Revision: 1.86 $
* $Date: 2003/10/11 19:46:51 $
*
@@ -82,7 +82,7 @@
* @author Rodney Waldhoff
* @author Sean C. Sullivan
* @author dIon Gillard
- * @author Ortwin Glück
+ * @author Ortwin Gl�ck
* @author Michael Becke
* @author Mike Bowler
* @author Sam Maloney
@@ -161,6 +161,9 @@
if (this.httpConnectionManager == null) {
this.httpConnectionManager = new SimpleHttpConnectionManager();
}
+ if (this.httpConnectionManager != null) {
+ this.httpConnectionManager.getParams().setDefaults(this.params);
+ }
}
/**
@@ -184,6 +187,9 @@
}
this.params = params;
this.httpConnectionManager = httpConnectionManager;
+ if (this.httpConnectionManager != null) {
+ this.httpConnectionManager.getParams().setDefaults(this.params);
+ }
}
/**
@@ -534,6 +540,9 @@
HttpConnectionManager httpConnectionManager
) {
this.httpConnectionManager = httpConnectionManager;
+ if (this.httpConnectionManager != null) {
+ this.httpConnectionManager.getParams().setDefaults(this.params);
+ }
}
/**
@@ -555,6 +564,9 @@
* @see HttpClientParams
*/
public void setParams(final HttpClientParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
this.params = params;
}
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.75
diff -u -r1.75 HttpConnection.java
--- java/org/apache/commons/httpclient/HttpConnection.java 10 Sep 2003 21:37:48 -0000 1.75
+++ java/org/apache/commons/httpclient/HttpConnection.java 17 Oct 2003 16:13:35 -0000
@@ -74,6 +74,7 @@
import java.net.Socket;
import java.net.SocketException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
@@ -393,7 +394,7 @@
* @return true if I am connected
*/
public boolean isOpen() {
- if (used && isStaleCheckingEnabled() && isStale()) {
+ if (used && this.params.isStaleCheckingEnabled() && isStale()) {
LOG.debug("Connection is stale, closing...");
close();
}
@@ -406,9 +407,12 @@
* @return true if enabled
*
* @see #isStale()
+ *
+ * @deprecated Use {@link HttpConnectionParams#isStaleCheckingEnabled()},
+ * {@link HttpConnection#getParams()}.
*/
public boolean isStaleCheckingEnabled() {
- return staleCheckingEnabled;
+ return this.params.isStaleCheckingEnabled();
}
/**
@@ -418,9 +422,12 @@
*
* @see #isStale()
* @see #isOpen()
+ *
+ * @deprecated Use {@link HttpConnectionParams#setStaleCheckingEnabled(boolean)},
+ * {@link HttpConnection#getParams()}.
*/
public void setStaleCheckingEnabled(boolean staleCheckEnabled) {
- this.staleCheckingEnabled = staleCheckEnabled;
+ this.params.setStaleCheckingEnabled(staleCheckEnabled);
}
/**
@@ -462,7 +469,7 @@
inputStream.unread(byteRead);
}
} finally {
- socket.setSoTimeout(soTimeout);
+ socket.setSoTimeout(this.params.getSoTimeout());
}
}
} catch (InterruptedIOException e) {
@@ -525,6 +532,31 @@
// --------------------------------------------------- Other Public Methods
/**
+ * Returns {@link HttpConnectionParams HTTP protocol parameters} associated with this method.
+ *
+ * @return HTTP parameters.
+ *
+ * @since 2.1
+ */
+ public HttpConnectionParams getParams() {
+ return this.params;
+ }
+
+ /**
+ * Assigns {@link HttpConnectionParams HTTP protocol parameters} for this method.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionParams
+ */
+ public void setParams(final HttpConnectionParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ this.params = params;
+ }
+
+ /**
* Set my {@link Socket}'s timeout, via {@link Socket#setSoTimeout}. If the
* connection is already open, the SO_TIMEOUT is changed. If no connection
* is open, then subsequent connections will use the timeout value.
@@ -535,13 +567,30 @@
* @throws SocketException - if there is an error in the underlying
* protocol, such as a TCP error.
* @throws IllegalStateException if I am not connected
+ *
+ * @deprecated Use {@link HttpConnectionParams#setSoTimeout(int)},
+ * {@link HttpConnection#getParams()}.
*/
public void setSoTimeout(int timeout)
throws SocketException, IllegalStateException {
- LOG.debug("HttpConnection.setSoTimeout(" + timeout + ")");
- soTimeout = timeout;
- if (socket != null) {
- socket.setSoTimeout(timeout);
+ this.params.setSoTimeout(timeout);
+ }
+
+ /**
+ * Sets SO_TIMEOUT value directly on the underlying {@link Socket socket}.
+ * This method does not change the default read timeout value set via
+ * {@link HttpConnectionParams}.
+ *
+ * @param timeout the timeout value
+ * @throws SocketException - if there is an error in the underlying
+ * protocol, such as a TCP error.
+ * @throws IllegalStateException if I am not connected
+ */
+ public void setSocketTimeout(int timeout)
+ throws SocketException, IllegalStateException {
+ assertOpen();
+ if (this.socket != null) {
+ this.socket.setSoTimeout(timeout);
}
}
@@ -553,14 +602,12 @@
* Note: This is not a connection timeout but a timeout on network traffic!
*
* @return the timeout value
+ *
+ * @deprecated Use {@link HttpConnectionParams#getSoTimeout()},
+ * {@link HttpConnection#getParams()}.
*/
public int getSoTimeout() throws SocketException {
- LOG.debug("HttpConnection.getSoTimeout()");
- if (this.socket != null) {
- return this.socket.getSoTimeout();
- } else {
- return this.soTimeout;
- }
+ return this.params.getSoTimeout();
}
/**
@@ -568,9 +615,12 @@
* until a connection is established. The connection will fail after this
* amount of time.
* @param timeout The timeout in milliseconds. 0 means timeout is not used.
+ *
+ * @deprecated Use {@link HttpConnectionParams#setConnectionTimeout(int)},
+ * {@link HttpConnection#getParams()}.
*/
public void setConnectionTimeout(int timeout) {
- this.connectTimeout = timeout;
+ this.params.setConnectionTimeout(timeout);
}
/**
@@ -599,7 +649,7 @@
? new DefaultProtocolSocketFactory()
: protocolInUse.getSocketFactory());
- if (connectTimeout == 0) {
+ if (this.params.getConnectionTimeout() == 0) {
if (localAddress != null) {
socket = socketFactory.createSocket(host, port, localAddress, 0);
} else {
@@ -615,7 +665,7 @@
}
}
};
- TimeoutController.execute(task, connectTimeout);
+ TimeoutController.execute(task, this.params.getConnectionTimeout());
socket = task.getSocket();
if (task.exception != null) {
throw task.exception;
@@ -632,11 +682,16 @@
situations. In such cases, nagling may be turned off through
use of the TCP_NODELAY sockets option." */
- socket.setTcpNoDelay(soNodelay);
- socket.setSoTimeout(soTimeout);
- if (sendBufferSize != -1) {
- socket.setSendBufferSize(sendBufferSize);
- }
+ socket.setTcpNoDelay(this.params.getTcpNoDelay());
+ socket.setSoTimeout(this.params.getSoTimeout());
+ int sndBufSize = this.params.getSendBufferSize();
+ if (sndBufSize >= 0) {
+ socket.setSendBufferSize(sndBufSize);
+ }
+ int rcvBufSize = this.params.getReceiveBufferSize();
+ if (rcvBufSize >= 0) {
+ socket.setReceiveBufferSize(rcvBufSize);
+ }
inputStream = new PushbackInputStream(socket.getInputStream());
outputStream = new BufferedOutputStream(
new WrappedOutputStream(socket.getOutputStream()),
@@ -651,10 +706,19 @@
throw e;
} catch (TimeoutController.TimeoutException e) {
if (LOG.isWarnEnabled()) {
- LOG.warn("The host " + hostName + ":" + portNumber
- + " (or proxy " + proxyHostName + ":" + proxyPortNumber
- + ") did not accept the connection within timeout of "
- + connectTimeout + " milliseconds");
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("The host ");
+ buffer.append(hostName);
+ buffer.append(":");
+ buffer.append(portNumber);
+ buffer.append(" (or proxy ");
+ buffer.append(proxyHostName);
+ buffer.append(":");
+ buffer.append(proxyPortNumber);
+ buffer.append(") did not accept the connection within timeout of ");
+ buffer.append(this.params.getConnectionTimeout());
+ buffer.append(" milliseconds");
+ LOG.warn(buffer.toString());
}
throw new ConnectionTimeoutException();
}
@@ -687,8 +751,13 @@
(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
socket = socketFactory.createSocket(socket, hostName, portNumber, true);
- if (sendBufferSize != -1) {
- socket.setSendBufferSize(sendBufferSize);
+ int sndBufSize = this.params.getSendBufferSize();
+ if (sndBufSize >= 0) {
+ socket.setSendBufferSize(sndBufSize);
+ }
+ int rcvBufSize = this.params.getReceiveBufferSize();
+ if (rcvBufSize >= 0) {
+ socket.setReceiveBufferSize(rcvBufSize);
}
inputStream = new PushbackInputStream(socket.getInputStream());
outputStream = new BufferedOutputStream(
@@ -805,7 +874,7 @@
}
} finally {
try {
- socket.setSoTimeout(soTimeout);
+ socket.setSoTimeout(this.params.getSoTimeout());
} catch (IOException ioe) {
LOG.debug("An error ocurred while resetting soTimeout, we will assume that"
+ " no response is available.",
@@ -1146,12 +1215,12 @@
* @throws SocketException if an error occurs while setting the socket value
*
* @see Socket#setSendBufferSize(int)
+ *
+ * @deprecated Use {@link HttpConnectionParams#setSendBuffer(int)},
+ * {@link HttpConnection#getParams()}.
*/
public void setSendBufferSize(int sendBufferSize) throws SocketException {
- this.sendBufferSize = sendBufferSize;
- if (socket != null) {
- socket.setSendBufferSize(sendBufferSize);
- }
+ this.params.setSendBufferSize(sendBufferSize);
}
// -- Timeout Exception
@@ -1323,9 +1392,6 @@
/** 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;
@@ -1335,11 +1401,8 @@
/** the protocol being used */
private Protocol protocolInUse;
- /** SO_TIMEOUT socket value */
- private int soTimeout = 0;
-
- /** TCP_NODELAY socket value */
- private boolean soNodelay = true;
+ /** Collection of HTTP parameters associated with this HTTP connection*/
+ private HttpConnectionParams params = new HttpConnectionParams();
/** flag to indicate if this connection can be released, if locked the connection cannot be
* released */
@@ -1350,12 +1413,6 @@
/** Whether I am tunneling a proxy or not */
private boolean tunnelEstablished = false;
-
- /** Whether or not isStale() is used by isOpen() */
- private boolean staleCheckingEnabled = true;
-
- /** Timeout until connection established (Socket created). 0 means no timeout. */
- private int connectTimeout = 0;
/** the connection manager that created this connection or null */
private HttpConnectionManager httpConnectionManager;
Index: java/org/apache/commons/httpclient/HttpConnectionManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v
retrieving revision 1.16
diff -u -r1.16 HttpConnectionManager.java
--- java/org/apache/commons/httpclient/HttpConnectionManager.java 16 Jul 2003 20:48:27 -0000 1.16
+++ java/org/apache/commons/httpclient/HttpConnectionManager.java 17 Oct 2003 16:13:35 -0000
@@ -63,6 +63,8 @@
package org.apache.commons.httpclient;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+
/**
* An interface for classes that manage HttpConnections.
*
@@ -147,4 +149,24 @@
* @param conn - The HttpConnection to make available.
*/
void releaseConnection(HttpConnection conn);
+
+ /**
+ * Returns {@link HttpConnectionManagerParams parameters} associated
+ * with this connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public HttpConnectionManagerParams getParams();
+
+ /**
+ * Assigns {@link HttpConnectionManagerParams parameters} for this
+ * connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public void setParams(final HttpConnectionManagerParams params);
}
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.182
diff -u -r1.182 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java 13 Oct 2003 12:22:24 -0000 1.182
+++ java/org/apache/commons/httpclient/HttpMethodBase.java 17 Oct 2003 16:13:37 -0000
@@ -1708,7 +1708,7 @@
int len = encodings.length;
if ((len > 0) && ("chunked".equalsIgnoreCase(encodings[len - 1].getName()))) {
// if response body is empty
- if (conn.isResponseAvailable(conn.getSoTimeout())) {
+ if (conn.isResponseAvailable(conn.getParams().getSoTimeout())) {
result = new ChunkedInputStream(is, this);
} else {
if (getParams().isParameterTrue(HttpMethodParams.STRICT_TRANSFER_ENCODING)) {
@@ -1926,9 +1926,9 @@
if ((expectvalue != null)
&& (expectvalue.compareToIgnoreCase("100-continue") == 0)) {
if (ver.greaterEquals(HttpVersion.HTTP_1_1)) {
- int readTimeout = conn.getSoTimeout();
+ int readTimeout = conn.getParams().getSoTimeout();
try {
- conn.setSoTimeout(RESPONSE_WAIT_TIME_MS);
+ conn.setSocketTimeout(RESPONSE_WAIT_TIME_MS);
readStatusLine(state, conn);
processStatusLine(state, conn);
readResponseHeaders(state, conn);
@@ -1948,7 +1948,7 @@
removeRequestHeader("Expect");
LOG.info("100 (continue) read timeout. Resume sending the request");
} finally {
- conn.setSoTimeout(readTimeout);
+ conn.setSocketTimeout(readTimeout);
}
} else {
@@ -2095,6 +2095,9 @@
* @see HttpMethodParams
*/
public void setParams(final HttpMethodParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
this.params = params;
}
Index: java/org/apache/commons/httpclient/HttpMethodDirector.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
retrieving revision 1.6
diff -u -r1.6 HttpMethodDirector.java
--- java/org/apache/commons/httpclient/HttpMethodDirector.java 15 Oct 2003 02:12:18 -0000 1.6
+++ java/org/apache/commons/httpclient/HttpMethodDirector.java 17 Oct 2003 16:13:37 -0000
@@ -244,8 +244,6 @@
if (!connection.isOpen()) {
// this connection must be opened before it can be used
- connection.setSoTimeout(this.params.getSoTimeout());
- connection.setConnectionTimeout(this.params.getConnectionTimeout());
connection.open();
if (connection.isProxied() && connection.isSecure()) {
// we need to create a secure tunnel before we can execute the real method
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.25
diff -u -r1.25 MultiThreadedHttpConnectionManager.java
--- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 26 Sep 2003 02:44:18 -0000 1.25
+++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 17 Oct 2003 16:13:38 -0000
@@ -77,6 +77,8 @@
import java.util.LinkedList;
import java.util.Map;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -104,15 +106,17 @@
public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
// ----------------------------------------------------- Instance Variables
+ /**
+ * Collection of parameters associated with this connection manager.
+ */
+ private HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+
/** Maximum number of connections allowed per host */
private int maxHostConnections = DEFAULT_MAX_HOST_CONNECTIONS;
/** Maximum number of connections allowed overall */
private int maxTotalConnections = DEFAULT_MAX_TOTAL_CONNECTIONS;
- /** The value to set when calling setStaleCheckingEnabled() on each connection */
- private boolean connectionStaleCheckingEnabled = true;
-
/** Connection Pool */
private ConnectionPool connectionPool;
@@ -144,9 +148,12 @@
* @return true if stale checking will be enabled on HttpConections
*
* @see HttpConnection#isStaleCheckingEnabled()
+ *
+ * @deprecated Use {@link HttpConnectionManagerParams#isStaleCheckingEnabled()},
+ * {@link HttpConnectionManager#getParams()}.
*/
public boolean isConnectionStaleCheckingEnabled() {
- return connectionStaleCheckingEnabled;
+ return this.params.isStaleCheckingEnabled();
}
/**
@@ -156,9 +163,12 @@
* on HttpConections
*
* @see HttpConnection#setStaleCheckingEnabled(boolean)
+ *
+ * @deprecated Use {@link HttpConnectionManagerParams#setStaleCheckingEnabled(boolean)},
+ * {@link HttpConnectionManager#getParams()}.
*/
public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled) {
- this.connectionStaleCheckingEnabled = connectionStaleCheckingEnabled;
+ this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
}
/**
@@ -438,9 +448,35 @@
return connectionConfiguration;
}
-
/**
+ * Returns {@link HttpConnectionManagerParams parameters} associated
+ * with this connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public HttpConnectionManagerParams getParams() {
+ return this.params;
+ }
+
+ /**
+ * Assigns {@link HttpConnectionManagerParams parameters} for this
+ * connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public void setParams(final HttpConnectionManagerParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ this.params = params;
+ }
+
+ /**
* Global Connection Pool, including per-host pools
*/
private class ConnectionPool {
@@ -478,7 +514,7 @@
LOG.debug("Allocating new connection, hostConfig=" + hostConfiguration);
}
connection = new HttpConnection(hostConfiguration);
- connection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
+ connection.getParams().setDefaults(MultiThreadedHttpConnectionManager.this.params);
connection.setHttpConnectionManager(MultiThreadedHttpConnectionManager.this);
numConnections++;
hostPool.numConnections++;
@@ -806,6 +842,9 @@
}
}
+ /**
+ * @deprecated
+ */
public boolean isStaleCheckingEnabled() {
if (hasConnection()) {
return wrappedConnection.isStaleCheckingEnabled();
@@ -821,7 +860,10 @@
throw new IllegalStateException("Connection has been released");
}
}
-
+
+ /**
+ * @deprecated
+ */
public void setStaleCheckingEnabled(boolean staleCheckEnabled) {
if (hasConnection()) {
wrappedConnection.setStaleCheckingEnabled(staleCheckEnabled);
@@ -1005,6 +1047,9 @@
}
}
+ /**
+ * @deprecated
+ */
public void setConnectionTimeout(int timeout) {
if (hasConnection()) {
wrappedConnection.setConnectionTimeout(timeout);
@@ -1069,6 +1114,9 @@
}
}
+ /**
+ * @deprecated
+ */
public void setSoTimeout(int timeout)
throws SocketException, IllegalStateException {
if (hasConnection()) {
@@ -1138,6 +1186,9 @@
}
}
+ /**
+ * @deprecated
+ */
public int getSoTimeout() throws SocketException {
if (hasConnection()) {
return wrappedConnection.getSoTimeout();
@@ -1170,9 +1221,28 @@
}
}
+ /**
+ * @deprecated
+ */
public void setSendBufferSize(int sendBufferSize) throws SocketException {
if (hasConnection()) {
wrappedConnection.setSendBufferSize(sendBufferSize);
+ } else {
+ throw new IllegalStateException("Connection has been released");
+ }
+ }
+
+ public HttpConnectionParams getParams() {
+ if (hasConnection()) {
+ return wrappedConnection.getParams();
+ } else {
+ throw new IllegalStateException("Connection has been released");
+ }
+ }
+
+ public void setParams(final HttpConnectionParams params) {
+ if (hasConnection()) {
+ wrappedConnection.setParams(params);
} else {
throw new IllegalStateException("Connection has been released");
}
Index: java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java,v
retrieving revision 1.15
diff -u -r1.15 SimpleHttpConnectionManager.java
--- java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 12 Aug 2003 02:35:17 -0000 1.15
+++ java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 17 Oct 2003 16:13:38 -0000
@@ -66,6 +66,8 @@
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+
/**
* A connection manager that provides access to a single HttpConnection. This
* manager makes no attempt to provide exclusive access to the contained
@@ -84,15 +86,10 @@
/** The http connection */
private HttpConnection httpConnection;
- /** The value to set when calling setStaleCheckingEnabled() on connections */
- private boolean connectionStaleCheckingEnabled = true;
-
/**
- * Constructor for SimpleHttpConnectionManager.
+ * Collection of parameters associated with this connection manager.
*/
- public SimpleHttpConnectionManager() {
- super();
- }
+ private HttpConnectionManagerParams params = new HttpConnectionManagerParams();
/**
* @see HttpConnectionManager#getConnection(HostConfiguration)
@@ -107,9 +104,12 @@
* @return true if stale checking will be enabled on HttpConections
*
* @see HttpConnection#isStaleCheckingEnabled()
+ *
+ * @deprecated Use {@link HttpConnectionManagerParams#isStaleCheckingEnabled()},
+ * {@link HttpConnectionManager#getParams()}.
*/
public boolean isConnectionStaleCheckingEnabled() {
- return connectionStaleCheckingEnabled;
+ return this.params.isStaleCheckingEnabled();
}
/**
@@ -119,9 +119,12 @@
* on HttpConections
*
* @see HttpConnection#setStaleCheckingEnabled(boolean)
+ *
+ * @deprecated Use {@link HttpConnectionManagerParams#setStaleCheckingEnabled(boolean)},
+ * {@link HttpConnectionManager#getParams()}.
*/
public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled) {
- this.connectionStaleCheckingEnabled = connectionStaleCheckingEnabled;
+ this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
}
/**
@@ -133,7 +136,7 @@
if (httpConnection == null) {
httpConnection = new HttpConnection(hostConfiguration);
httpConnection.setHttpConnectionManager(this);
- httpConnection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
+ httpConnection.getParams().setDefaults(this.params);
} else {
// make sure the host and proxy are correct for this connection
@@ -145,8 +148,6 @@
httpConnection.close();
}
- httpConnection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
-
httpConnection.setHost(hostConfiguration.getHost());
httpConnection.setVirtualHost(hostConfiguration.getVirtualHost());
httpConnection.setPort(hostConfiguration.getPort());
@@ -201,5 +202,32 @@
conn.close();
}
}
+ }
+
+ /**
+ * Returns {@link HttpConnectionManagerParams parameters} associated
+ * with this connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public HttpConnectionManagerParams getParams() {
+ return this.params;
+ }
+
+ /**
+ * Assigns {@link HttpConnectionManagerParams parameters} for this
+ * connection manager.
+ *
+ * @since 2.1
+ *
+ * @see HttpConnectionManagerParams
+ */
+ public void setParams(final HttpConnectionManagerParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ this.params = params;
}
}
Index: java/org/apache/commons/httpclient/methods/multipart/PartBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartBase.java,v
retrieving revision 1.2
diff -u -r1.2 PartBase.java
--- java/org/apache/commons/httpclient/methods/multipart/PartBase.java 10 Oct 2003 04:18:35 -0000 1.2
+++ java/org/apache/commons/httpclient/methods/multipart/PartBase.java 17 Oct 2003 16:13:39 -0000
@@ -88,7 +88,7 @@
*
* @param name The name of the part
* @param contentType The content type, or null
- * @param charset The character encoding, or null
+ * @param charSet The character encoding, or null
* @param transferEncoding The transfer encoding, or null
*/
public PartBase(String name, String contentType, String charSet, String transferEncoding) {
Index: java/org/apache/commons/httpclient/params/DefaultHttpParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParams.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultHttpParams.java
--- java/org/apache/commons/httpclient/params/DefaultHttpParams.java 3 Oct 2003 20:57:36 -0000 1.4
+++ java/org/apache/commons/httpclient/params/DefaultHttpParams.java 17 Oct 2003 16:13:39 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParams.java,v 1.4 2003/10/03 20:57:36 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParams.java,v 1.4 2003/10/03 20:57:36 olegk Exp $
* $Revision: 1.4 $
* $Date: 2003/10/03 20:57:36 $
*
Index: java/org/apache/commons/httpclient/params/HttpClientParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java,v
retrieving revision 1.2
diff -u -r1.2 HttpClientParams.java
--- java/org/apache/commons/httpclient/params/HttpClientParams.java 23 Sep 2003 19:51:49 -0000 1.2
+++ java/org/apache/commons/httpclient/params/HttpClientParams.java 17 Oct 2003 16:13:39 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java,v 1.2 2003/09/23 19:51:49 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java,v 1.2 2003/09/23 19:51:49 olegk Exp $
* $Revision: 1.2 $
* $Date: 2003/09/23 19:51:49 $
*
Index: java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java
===================================================================
RCS file: java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java
diff -N java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java 17 Oct 2003 16:13:39 -0000
@@ -0,0 +1,78 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * This parameter expects a value of type {@link Integer}. + *
+ * @see SocketOptions#SO_TIMEOUT + */ + public static final String SO_TIMEOUT = "http.socket.timeout"; + + /** + * Determines whether Nagle's algorithm is to be used. The Nagle's algorithm + * tries to conserve bandwidth by minimizing the number of segments that are + * sent. When applications wish to decrease network latency and increase + * performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). + * Data will be sent earlier, at the cost of an increase in bandwidth consumption. + *+ * This parameter expects a value of type {@link Boolean}. + *
+ * @see SocketOptions#TCP_NODELAY + */ + public static final String TCP_NODELAY = "http.tcp.nodelay"; + + /** + * Determines a hint the size of the underlying buffers used by the platform + * for outgoing network I/O. This value is a suggestion to the kernel from + * the application about the size of buffers to use for the data to be sent + * over the socket. + *+ * This parameter expects a value of type {@link Integer}. + *
+ * @see SocketOptions#SO_SNDBUF + */ + public static final String SO_SNDBUF = "http.socket.sendbuffer"; + + /** + * Determines a hint the size of the underlying buffers used by the platform + * for incoming network I/O. This value is a suggestion to the kernel from + * the application about the size of buffers to use for the data to be received + * over the socket. + *+ * This parameter expects a value of type {@link Integer}. + *
+ * @see SocketOptions#SO_RCVBUF + */ + public static final String SO_RCVBUF = "http.socket.receivebuffer"; + + /** + * Determines the timeout until a connection is etablished. A value of zero + * means the timeout is not used. The default value is zero. + *+ * This parameter expects a value of type {@link Integer}. + *
+ */ + public static final String CONNECTION_TIMEOUT = "http.connection.timeout"; + + /** + * Determines whether stale connection check is to be used. Disabling + * stale connection check may result in slight performance improvement + * at the risk of getting an I/O error when executing a request over a + * connection that has been closed at the server side. + *+ * This parameter expects a value of type {@link Boolean}. + *
+ */ + public static final String STALE_CONNECTION_CHECK = "http.connection.stalecheck"; + + /** + * Creates a new collection of parameters with the collection returned + * by {@link #getDefaultParams()} as a parent. The collection will defer + * to its parent for a default value if a particular parameter is not + * explicitly set in the collection itself. + * + * @see #getDefaultParams() + */ + public HttpConnectionParams() { + super(); + } + + /** + * Returns the socket timeout (SO_TIMEOUT) in milliseconds which is the + * timeout for waiting for data. A timeout value of zero is interpreted as an + * infinite timeout. + * + * @return timeout in milliseconds + */ + public int getSoTimeout() { + return getIntParameter(SO_TIMEOUT, 0); + } + + /** + * Sets the socket timeout (SO_TIMEOUT) in milliseconds which is the + * timeout for waiting for data. A timeout value of zero is interpreted as an + * infinite timeout. + * + * @param timeout Timeout in milliseconds + */ + public void setSoTimeout(int timeout) { + setIntParameter(SO_TIMEOUT, timeout); + } + + /** + * Determines whether Nagle's algorithm is to be used. The Nagle's algorithm + * tries to conserve bandwidth by minimizing the number of segments that are + * sent. When applications wish to decrease network latency and increase + * performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). + * Data will be sent earlier, at the cost of an increase in bandwidth consumption. + * + * @param value true if the Nagle's algorithm is to NOT be used + * (that is enable TCP_NODELAY), false otherwise. + */ + public void setTcpNoDelay(boolean value) { + setBooleanParameter(TCP_NODELAY, value); + } + + /** + * Tests if Nagle's algorithm is to be used. + * + * @return true if the Nagle's algorithm is to NOT be used + * (that is enable TCP_NODELAY), false otherwise. + */ + public boolean getTcpNoDelay() { + return getBooleanParameter(TCP_NODELAY, true); + } + + /** + * Returns a hint the size of the underlying buffers used by the platform for + * outgoing network I/O. This value is a suggestion to the kernel from the + * application about the size of buffers to use for the data to be sent over + * the socket. + * + * @return the hint size of the send buffer + */ + public int getSendBufferSize() { + return getIntParameter(SO_SNDBUF, -1); + } + + /** + * Sets a hint the size of the underlying buffers used by the platform for + * outgoing network I/O. This value is a suggestion to the kernel from the + * application about the size of buffers to use for the data to be sent over + * the socket. + * + * @param size the hint size of the send buffer + */ + public void setSendBufferSize(int size) { + setIntParameter(SO_SNDBUF, size); + } + + /** + * Returns a hint the size of the underlying buffers used by the platform + * for incoming network I/O. This value is a suggestion to the kernel from + * the application about the size of buffers to use for the data to be received + * over the socket. + * + * @return the hint size of the send buffer + */ + public int getReceiveBufferSize() { + return getIntParameter(SO_RCVBUF, -1); + } + + /** + * Sets a hint the size of the underlying buffers used by the platform + * for incoming network I/O. This value is a suggestion to the kernel from + * the application about the size of buffers to use for the data to be received + * over the socket. + * + * @param size the hint size of the send buffer + */ + public void setReceiveBufferSize(int size) { + setIntParameter(SO_RCVBUF, size); + } + + /** + * Returns the timeout until a connection is etablished. A value of zero + * means the timeout is not used. The default value is zero. + * + * @return timeout in milliseconds. + */ + public int getConnectionTimeout() { + return getIntParameter(CONNECTION_TIMEOUT, 0); + } + + /** + * Sets the timeout until a connection is etablished. A value of zero + * means the timeout is not used. The default value is zero. + * + * @param timeout Timeout in milliseconds. + */ + public void setConnectionTimeout(int timeout) { + setIntParameter(CONNECTION_TIMEOUT, timeout); + } + + /** + * Tests whether stale connection check is to be used. Disabling + * stale connection check may result in slight performance improvement + * at the risk of getting an I/O error when executing a request over a + * connection that has been closed at the server side. + * + * @return true if stale connection check is to be used, + * false otherwise. + */ + public boolean isStaleCheckingEnabled() { + return getBooleanParameter(STALE_CONNECTION_CHECK, true); + } + + /** + * Defines whether stale connection check is to be used. Disabling + * stale connection check may result in slight performance improvement + * at the risk of getting an I/O error when executing a request over a + * connection that has been closed at the server side. + * + * @param value true if stale connection check is to be used, + * false otherwise. + */ + public void setStaleCheckingEnabled(boolean value) { + setBooleanParameter(STALE_CONNECTION_CHECK, value); + } +} Index: java/org/apache/commons/httpclient/params/HttpMethodParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v retrieving revision 1.3 diff -u -r1.3 HttpMethodParams.java --- java/org/apache/commons/httpclient/params/HttpMethodParams.java 3 Oct 2003 20:57:36 -0000 1.3 +++ java/org/apache/commons/httpclient/params/HttpMethodParams.java 17 Oct 2003 16:13:40 -0000 @@ -172,7 +172,7 @@ * @see #getDefaultParams() */ public HttpMethodParams() { - super(); + super(null); } /** Index: test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v retrieving revision 1.3 diff -u -r1.3 NoHostHttpConnectionManager.java --- test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 17 Sep 2003 03:53:25 -0000 1.3 +++ test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 17 Oct 2003 16:13:40 -0000 @@ -9,6 +9,8 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; + /** */ public class NoHostHttpConnectionManager implements HttpConnectionManager { @@ -16,6 +18,8 @@ private HttpConnection connection; private boolean connectionReleased = false; + + private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); public NoHostHttpConnectionManager() { setConnection(new SimpleHttpConnection()); @@ -34,6 +38,7 @@ public void setConnection(HttpConnection connection) { this.connection = connection; connection.setHttpConnectionManager(this); + connection.getParams().setDefaults(this.params); } public HttpConnection getConnection(HostConfiguration hostConfiguration) { @@ -63,6 +68,9 @@ return connection; } + /** + * @deprecated + */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { return getConnection(hostConfiguration); @@ -103,5 +111,15 @@ } } + public HttpConnectionManagerParams getParams() { + return this.params; + } + + public void setParams(final HttpConnectionManagerParams params) { + if (params == null) { + throw new IllegalArgumentException("Parameters may not be null"); + } + this.params = params; + } } Index: test/org/apache/commons/httpclient/TestHttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnection.java,v retrieving revision 1.11 diff -u -r1.11 TestHttpConnection.java --- test/org/apache/commons/httpclient/TestHttpConnection.java 3 Oct 2003 20:57:36 -0000 1.11 +++ test/org/apache/commons/httpclient/TestHttpConnection.java 17 Oct 2003 16:13:41 -0000 @@ -157,7 +157,7 @@ HttpConnection conn = new HttpConnection(getHost(), getPort(), testProtocol); // 1 ms is short enough to make this fail - conn.setConnectionTimeout(1); + conn.getParams().setConnectionTimeout(1); try { conn.open(); fail("Should have timed out");