Index: java/org/apache/commons/httpclient/HostConfiguration.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v
retrieving revision 1.19
diff -u -r1.19 HostConfiguration.java
--- java/org/apache/commons/httpclient/HostConfiguration.java 17 Jul 2004 18:58:33 -0000 1.19
+++ java/org/apache/commons/httpclient/HostConfiguration.java 29 Sep 2004 18:24:33 -0000
@@ -33,6 +33,7 @@
import org.apache.commons.httpclient.protocol.Protocol;
import java.net.InetAddress;
+import java.util.Iterator;
/**
* Holds all of the variables needed to describe an HTTP connection to a host. This includes
@@ -446,6 +447,15 @@
}
/**
+ * Tests if the local address has been set.
+ *
+ * @return true if a local address has been set.
+ */
+ public synchronized boolean isLocalAddressSet() {
+ return this.localAddress != null;
+ }
+
+ /**
* Set the local address to be used when creating connections.
* If this is unset, the default address will be used.
* This is useful for specifying the interface to use on multi-homed or clustered systems.
@@ -555,6 +565,44 @@
}
+ public synchronized void copyDefaults(final HostConfiguration hostdefaults) {
+ if (hostdefaults == null) {
+ return;
+ }
+ synchronized(hostdefaults) {
+ if (!isHostSet() && hostdefaults.isHostSet()) {
+ setHost(
+ hostdefaults.getHost(),
+ hostdefaults.getVirtualHost(),
+ hostdefaults.getPort(),
+ hostdefaults.getProtocol()
+ );
+ }
+ if (!isLocalAddressSet() && hostdefaults.isLocalAddressSet()) {
+ setLocalAddress(
+ hostdefaults.getLocalAddress()
+ );
+ }
+ if (!isProxySet() && hostdefaults.isProxySet()) {
+ setProxy(
+ hostdefaults.getProxyHost(),
+ hostdefaults.getProxyPort()
+ );
+ }
+ if (!hostdefaults.getParams().isEmpty()) {
+ Iterator i = hostdefaults.getParams().iterator();
+ while (i.hasNext()) {
+ String paramname = (String)i.next();
+ if (!this.params.isParameterSetLocally(paramname)) {
+ this.params.setParameter(paramname,
+ hostdefaults.getParams().getParameter(paramname));
+ }
+ }
+ }
+ }
+ }
+
+
/**
* @see java.lang.Object#hashCode()
*/
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.96
diff -u -r1.96 HttpClient.java
--- java/org/apache/commons/httpclient/HttpClient.java 14 Jun 2004 21:25:38 -0000 1.96
+++ java/org/apache/commons/httpclient/HttpClient.java 29 Sep 2004 18:24:35 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v 1.96 2004/06/14 21:25:38 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v 1.96 2004/06/14 21:25:38 olegk Exp $
* $Revision: 1.96 $
* $Date: 2004/06/14 21:25:38 $
*
@@ -321,14 +321,7 @@
LOG.trace("enter HttpClient.executeMethod(HttpMethod)");
// execute this method and use its host configuration, if it has one
- return executeMethod(
- method.getHostConfiguration() != null
- ? method.getHostConfiguration()
- : getHostConfiguration(),
- method,
- null
- );
-
+ return executeMethod(null, method,null);
}
/**
@@ -360,7 +353,9 @@
* {@link HostConfiguration host configuration} with the given custom
* {@link HttpState HTTP state}.
*
- * @param hostConfiguration The {@link HostConfiguration host configuration} to use.
+ * @param hostdefaults The default {@link HostConfiguration host configuration} to use.
+ * This host configuration will be used to draw the default values
+ * when they are not explicitly defined by the HTTP method
* @param method the {@link HttpMethod HTTP method} to execute.
* @param state the {@link HttpState HTTP state} to use when executing the method.
* If null, the state returned by {@link #getState} will be used instead.
@@ -373,8 +368,9 @@
* cannot be recovered from.
* @since 2.0
*/
- public int executeMethod(HostConfiguration hostConfiguration,
- HttpMethod method, HttpState state)
+ public int executeMethod(
+ HostConfiguration hostdefaults,
+ final HttpMethod method, final HttpState state)
throws IOException, HttpException {
LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)");
@@ -382,58 +378,16 @@
if (method == null) {
throw new IllegalArgumentException("HttpMethod parameter may not be null");
}
-
- if (hostConfiguration == null) {
- hostConfiguration = (
- method.getHostConfiguration() != null
- ? method.getHostConfiguration()
- : getHostConfiguration()
- );
- }
-
- HostConfiguration defaultHostConfiguration = null;
- synchronized (this) {
- defaultHostConfiguration = getHostConfiguration();
- }
- HostConfiguration methodConfiguration = new HostConfiguration(hostConfiguration);
- if (hostConfiguration != defaultHostConfiguration) {
- // we may need to apply some defaults
- if (!methodConfiguration.isHostSet()) {
- methodConfiguration.setHost(
- defaultHostConfiguration.getHost(),
- defaultHostConfiguration.getVirtualHost(),
- defaultHostConfiguration.getPort(),
- defaultHostConfiguration.getProtocol()
- );
- }
- if (!methodConfiguration.isProxySet()
- && defaultHostConfiguration.isProxySet()) {
-
- methodConfiguration.setProxy(
- defaultHostConfiguration.getProxyHost(),
- defaultHostConfiguration.getProxyPort()
- );
- }
- if (methodConfiguration.getLocalAddress() == null
- && defaultHostConfiguration.getLocalAddress() != null) {
-
- methodConfiguration.setLocalAddress(defaultHostConfiguration.getLocalAddress());
- }
+ // make sure the host configuration has reasonable defaults
+ if (hostdefaults == null) {
+ hostdefaults = getHostConfiguration();
}
+ method.getHostConfiguration().copyDefaults(hostdefaults);
- /* access all synchronized data in a single block, this will keeps us
- * from accessing data asynchronously as well having to regain the lock
- * for each item.
- */
- HttpMethodDirector methodDirector = null;
- synchronized (this) {
- methodDirector = new HttpMethodDirector(
+ HttpMethodDirector methodDirector = new HttpMethodDirector(
this.httpConnectionManager,
- methodConfiguration,
this.params,
- (state == null ? getState() : state));
- defaultHostConfiguration = getHostConfiguration();
- }
+ (state == null ? this.state : state));
methodDirector.executeMethod(method);
return method.getStatusCode();
}
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.215
diff -u -r1.215 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java 17 Sep 2004 08:00:51 -0000 1.215
+++ java/org/apache/commons/httpclient/HttpMethodBase.java 29 Sep 2004 18:24:41 -0000
@@ -153,8 +153,8 @@
* a recoverable exception. */
private int recoverableExceptionCount = 0;
- /** the host configuration for this HTTP method, can be null */
- private HostConfiguration hostConfiguration;
+ /** the host configuration for this HTTP method */
+ private HostConfiguration hostconfig = new HostConfiguration();
/**
* Handles method retries
@@ -191,6 +191,8 @@
* No-arg constructor.
*/
public HttpMethodBase() {
+ super();
+ this.params.setDefaults(this.hostconfig.getParams());
}
/**
@@ -206,7 +208,7 @@
*/
public HttpMethodBase(String uri)
throws IllegalArgumentException, IllegalStateException {
-
+ this();
try {
// create a URI and allow for null/empty uri values
@@ -242,7 +244,7 @@
*/
public URI getURI() throws URIException {
- if (hostConfiguration == null) {
+ if (!hostconfig.isHostSet()) {
// just use a relative URI, the host hasn't been set
URI tmpUri = new URI(null, null, path, null, null);
tmpUri.setEscapedQuery(queryString);
@@ -250,15 +252,15 @@
} else {
// we only want to include the port if it's not the default
- int port = hostConfiguration.getPort();
- if (port == hostConfiguration.getProtocol().getDefaultPort()) {
+ int port = hostconfig.getPort();
+ if (port == hostconfig.getProtocol().getDefaultPort()) {
port = -1;
}
URI tmpUri = new URI(
- hostConfiguration.getProtocol().getScheme(),
+ hostconfig.getProtocol().getScheme(),
null,
- hostConfiguration.getHost(),
+ hostconfig.getHost(),
port,
path,
null // to set an escaped form
@@ -282,10 +284,7 @@
public void setURI(URI uri) throws URIException {
// only set the host if specified by the URI
if (uri.isAbsoluteURI()) {
- if (this.hostConfiguration == null) {
- this.hostConfiguration = new HostConfiguration();
- }
- this.hostConfiguration.setHost(
+ this.hostconfig.setHost(
uri.getHost(),
uri.getPort(),
uri.getScheme()
@@ -1056,6 +1055,9 @@
releaseConnection();
+ hostconfig = new HostConfiguration();
+ params = new HttpMethodParams();
+ params.setDefaults(this.hostconfig.getParams());
path = null;
followRedirects = false;
doAuthentication = true;
@@ -1067,7 +1069,6 @@
effectiveVersion = null;
aborted = false;
used = false;
- params = new HttpMethodParams();
responseBody = null;
recoverableExceptionCount = 0;
connectionCloseForced = false;
@@ -2295,16 +2296,19 @@
* @return the host configuration
*/
public HostConfiguration getHostConfiguration() {
- return hostConfiguration;
+ return this.hostconfig;
}
/**
* Sets the {@link HostConfiguration host configuration}.
*
- * @param hostConfiguration The hostConfiguration to set
+ * @param hostconfig The hostConfiguration to set
*/
- public void setHostConfiguration(HostConfiguration hostConfiguration) {
- this.hostConfiguration = hostConfiguration;
+ public void setHostConfiguration(final HostConfiguration hostconfig) {
+ if (hostconfig == null) {
+ throw new IllegalArgumentException("Host configuration may not be null");
+ }
+ this.hostconfig = hostconfig;
}
/**
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.30
diff -u -r1.30 HttpMethodDirector.java
--- java/org/apache/commons/httpclient/HttpMethodDirector.java 15 Sep 2004 20:42:17 -0000 1.30
+++ java/org/apache/commons/httpclient/HttpMethodDirector.java 29 Sep 2004 18:24:44 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v 1.30 2004/09/15 20:42:17 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v 1.30 2004/09/15 20:42:17 olegk Exp $
* $Revision: 1.30 $
* $Date: 2004/09/15 20:42:17 $
*
@@ -79,8 +79,6 @@
private HttpState state;
- private HostConfiguration hostConfiguration;
-
private HttpConnectionManager connectionManager;
private HttpClientParams params;
@@ -106,13 +104,11 @@
public HttpMethodDirector(
final HttpConnectionManager connectionManager,
- final HostConfiguration hostConfiguration,
final HttpClientParams params,
final HttpState state
) {
super();
this.connectionManager = connectionManager;
- this.hostConfiguration = hostConfiguration;
this.params = params;
this.state = state;
this.authProcessor = new AuthChallengeProcessor(this.params);
@@ -131,11 +127,12 @@
}
// Link all parameter collections to form the hierarchy:
// Global -> HttpClient -> HostConfiguration -> HttpMethod
- this.hostConfiguration.getParams().setDefaults(this.params);
- method.getParams().setDefaults(this.hostConfiguration.getParams());
+ HostConfiguration hostconfig = method.getHostConfiguration();
+ hostconfig.getParams().setDefaults(this.params);
+ method.getParams().setDefaults(hostconfig.getParams());
// Generate default request headers
- Collection defaults = (Collection)this.hostConfiguration.getParams().
+ Collection defaults = (Collection)hostconfig.getParams().
getParameter(HostParams.DEFAULT_HEADERS);
if (defaults != null) {
Iterator i = defaults.iterator();
@@ -150,7 +147,7 @@
for (int redirectCount = 0;;) {
// make sure the connection we have is appropriate
- if (this.conn != null && !hostConfiguration.hostEquals(this.conn)) {
+ if (this.conn != null && !hostconfig.hostEquals(this.conn)) {
this.conn.setLocked(false);
this.conn.releaseConnection();
this.conn = null;
@@ -159,7 +156,7 @@
// get a connection, if we need one
if (this.conn == null) {
this.conn = connectionManager.getConnectionWithTimeout(
- hostConfiguration,
+ hostconfig,
this.params.getConnectionManagerTimeout()
);
this.conn.setLocked(true);
@@ -592,7 +589,6 @@
}
}
method.setURI(redirectUri);
- hostConfiguration.setHost(redirectUri);
} catch (URIException e) {
LOG.warn("Redirected location '" + location + "' is malformed");
return false;
@@ -870,13 +866,6 @@
}
}
return creds;
- }
-
- /**
- * @return
- */
- public HostConfiguration getHostConfiguration() {
- return hostConfiguration;
}
/**
Index: java/org/apache/commons/httpclient/ProxyClient.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ProxyClient.java,v
retrieving revision 1.4
diff -u -r1.4 ProxyClient.java
--- java/org/apache/commons/httpclient/ProxyClient.java 4 May 2004 21:24:51 -0000 1.4
+++ java/org/apache/commons/httpclient/ProxyClient.java 29 Sep 2004 18:24:45 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ProxyClient.java,v 1.4 2004/05/04 21:24:51 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ProxyClient.java,v 1.4 2004/05/04 21:24:51 olegk Exp $
* $Revision: 1.4 $
* $Date: 2004/05/04 21:24:51 $
*
@@ -187,6 +187,7 @@
}
ConnectMethod method = new ConnectMethod();
+ method.setHostConfiguration(getHostConfiguration());
method.getParams().setDefaults(getParams());
DummyConnectionManager connectionManager = new DummyConnectionManager();
@@ -194,7 +195,6 @@
HttpMethodDirector director = new HttpMethodDirector(
connectionManager,
- getHostConfiguration(),
getParams(),
getState()
);
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.8
diff -u -r1.8 DefaultHttpParams.java
--- java/org/apache/commons/httpclient/params/DefaultHttpParams.java 13 May 2004 04:01:22 -0000 1.8
+++ java/org/apache/commons/httpclient/params/DefaultHttpParams.java 29 Sep 2004 18:24:46 -0000
@@ -31,6 +31,7 @@
import java.io.Serializable;
import java.util.HashMap;
+import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -232,6 +233,18 @@
*/
public void clear() {
this.parameters = null;
+ }
+
+ public boolean isEmpty() {
+ return this.parameters == null || this.parameters.isEmpty();
+ }
+
+ public Iterator iterator() {
+ if (this.parameters != null) {
+ return this.parameters.keySet().iterator();
+ } else {
+ return new HashMap().keySet().iterator();
+ }
}
/**
Index: java/org/apache/commons/httpclient/params/HttpParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpParams.java,v
retrieving revision 1.6
diff -u -r1.6 HttpParams.java
--- java/org/apache/commons/httpclient/params/HttpParams.java 13 May 2004 04:01:22 -0000 1.6
+++ java/org/apache/commons/httpclient/params/HttpParams.java 29 Sep 2004 18:24:46 -0000
@@ -29,6 +29,8 @@
package org.apache.commons.httpclient.params;
+import java.util.Iterator;
+
/**
* This interface represents a collection of HTTP protocol parameters. Protocol parameters
* may be linked together to form a hierarchy. If a particular parameter value has not been
@@ -53,7 +55,7 @@
*
* @see #setDefaults(HttpParams)
*/
- public HttpParams getDefaults();
+ HttpParams getDefaults();
/**
* Assigns the parent collection that this collection will defer to
@@ -65,7 +67,7 @@
*
* @see #getDefaults()
*/
- public void setDefaults(final HttpParams params);
+ public void setDefaults(HttpParams params);
/**
* Returns a parameter value with the given name. If the parameter is
@@ -80,7 +82,7 @@
*
* @see #setParameter(String, Object)
*/
- public Object getParameter(final String name);
+ Object getParameter(String name);
/**
* Assigns the value to the parameter with the given name
@@ -88,7 +90,7 @@
* @param name parameter name
* @param value parameter value
*/
- public void setParameter(final String name, final Object value);
+ void setParameter(String name, Object value);
/**
* Returns a {@link Long} parameter value with the given name.
@@ -104,7 +106,7 @@
*
* @see #setLongParameter(String, long)
*/
- public long getLongParameter(final String name, long defaultValue);
+ long getLongParameter(String name, long defaultValue);
/**
* Assigns a {@link Long} to the parameter with the given name
@@ -112,7 +114,7 @@
* @param name parameter name
* @param value parameter value
*/
- public void setLongParameter(final String name, long value);
+ void setLongParameter(String name, long value);
/**
* Returns an {@link Integer} parameter value with the given name.
@@ -128,7 +130,7 @@
*
* @see #setIntParameter(String, int)
*/
- public int getIntParameter(final String name, int defaultValue);
+ int getIntParameter(String name, int defaultValue);
/**
* Assigns an {@link Integer} to the parameter with the given name
@@ -136,7 +138,7 @@
* @param name parameter name
* @param value parameter value
*/
- public void setIntParameter(final String name, int value);
+ void setIntParameter(String name, int value);
/**
* Returns a {@link Double} parameter value with the given name.
@@ -152,7 +154,7 @@
*
* @see #setDoubleParameter(String, double)
*/
- public double getDoubleParameter(final String name, double defaultValue);
+ double getDoubleParameter(String name, double defaultValue);
/**
* Assigns a {@link Double} to the parameter with the given name
@@ -160,7 +162,7 @@
* @param name parameter name
* @param value parameter value
*/
- public void setDoubleParameter(final String name, double value);
+ void setDoubleParameter(String name, double value);
/**
* Returns a {@link Boolean} parameter value with the given name.
@@ -176,7 +178,7 @@
*
* @see #setBooleanParameter(String, boolean)
*/
- public boolean getBooleanParameter(final String name, boolean defaultValue);
+ boolean getBooleanParameter(String name, boolean defaultValue);
/**
* Assigns a {@link Boolean} to the parameter with the given name
@@ -184,7 +186,7 @@
* @param name parameter name
* @param value parameter value
*/
- public void setBooleanParameter(final String name, boolean value);
+ void setBooleanParameter(String name, boolean value);
/**
* Returns true if the parameter is set at any level, false otherwise.
@@ -194,7 +196,7 @@
* @return true if the parameter is set at any level, false
* otherwise.
*/
- public boolean isParameterSet(final String name);
+ boolean isParameterSet(String name);
/**
* Returns true if the parameter is set locally, false otherwise.
@@ -204,7 +206,7 @@
* @return true if the parameter is set locally, false
* otherwise.
*/
- public boolean isParameterSetLocally(final String name);
+ boolean isParameterSetLocally(String name);
/**
* Returns true if the parameter is set and is true, false
@@ -215,7 +217,7 @@
* @return true if the parameter is set and is true, false
* otherwise.
*/
- public boolean isParameterTrue(final String name);
+ boolean isParameterTrue(String name);
/**
* Returns true if the parameter is either not set or is false,
@@ -226,6 +228,22 @@
* @return true if the parameter is either not set or is false,
* false otherwise.
*/
- public boolean isParameterFalse(final String name);
+ boolean isParameterFalse(String name);
+
+ /**
+ * Returns true if the parameter collection contains no parameters,
+ * false otherwise.
+ *
+ * @return true if the parameter collection contains no parameters,
+ * false otherwise.
+ */
+ boolean isEmpty();
+
+ /**
+ * Returns an iterator over parameter names in this parameter collection.
+ *
+ * @return an iterator over parameter names in this parameter collection.
+ */
+ Iterator iterator();
}
Index: test/org/apache/commons/httpclient/TestRedirects.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v
retrieving revision 1.3
diff -u -r1.3 TestRedirects.java
--- test/org/apache/commons/httpclient/TestRedirects.java 28 Sep 2004 21:08:48 -0000 1.3
+++ test/org/apache/commons/httpclient/TestRedirects.java 29 Sep 2004 18:24:48 -0000
@@ -234,7 +234,8 @@
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
- assertEquals(new URI("/oldlocation/", false), httpget.getURI());
+ assertEquals(new URI("http://" + host + ":" + port + "/oldlocation/", false),
+ httpget.getURI());
} finally {
httpget.releaseConnection();
}
@@ -250,7 +251,8 @@
this.client.executeMethod(httppost);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httppost.getStatusCode());
assertEquals("/oldlocation/", httppost.getPath());
- assertEquals(new URI("/oldlocation/", false), httppost.getURI());
+ assertEquals(new URI("http://" + host + ":" + port + "/oldlocation/", false),
+ httppost.getURI());
} finally {
httppost.releaseConnection();
}
@@ -288,7 +290,8 @@
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
- assertEquals(new URI("/oldlocation/", false), httpget.getURI());
+ assertEquals(new URI("http://" + host + ":" + port + "/oldlocation/", false),
+ httpget.getURI());
} finally {
httpget.releaseConnection();
}
Index: test/org/apache/commons/httpclient/params/TestHttpParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v
retrieving revision 1.2
diff -u -r1.2 TestHttpParams.java
--- test/org/apache/commons/httpclient/params/TestHttpParams.java 15 Sep 2004 20:45:48 -0000 1.2
+++ test/org/apache/commons/httpclient/params/TestHttpParams.java 29 Sep 2004 18:24:49 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v 1.2 2004/09/15 20:45:48 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v 1.2 2004/09/15 20:45:48 olegk Exp $
* $Revision: 1.2 $
* $Date: 2004/09/15 20:45:48 $
* ====================================================================
@@ -129,5 +129,38 @@
Header[] thatheader = httpget.getRequestHeaders("that-header");
assertEquals(2, thatheader.length);
assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
+ }
+
+ public void testDefaults() throws IOException {
+ this.server.setHttpService(new SimpleService());
+
+ this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");
+ HostConfiguration hostconfig = new HostConfiguration();
+ hostconfig.setHost(
+ this.server.getLocalAddress(),
+ this.server.getLocalPort(),
+ Protocol.getProtocol("http"));
+ hostconfig.getParams().setParameter("testparam1", "stuff");
+ hostconfig.getParams().setParameter("testparam2", "stuff");
+
+ GetMethod httpget = new GetMethod("/miss/");
+ httpget.getHostConfiguration().getParams().setParameter("testparam1", "no stuff");
+ try {
+ this.client.executeMethod(hostconfig, httpget);
+ } finally {
+ httpget.releaseConnection();
+ }
+ assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
+ assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
+ assertEquals("test", httpget.getParams().
+ getParameter(HttpMethodParams.USER_AGENT));
+ assertEquals("test", httpget.getHostConfiguration().getParams().
+ getParameter(HttpMethodParams.USER_AGENT));
+ assertFalse("test".equals(hostconfig.getParams().
+ getParameter(HttpMethodParams.USER_AGENT)));
+
+ assertEquals("no stuff", httpget.getHostConfiguration().getParams().getParameter("testparam1"));
+ assertEquals("stuff", httpget.getHostConfiguration().getParams().getParameter("testparam2"));
+
}
}