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.81
diff -u -r1.81 HttpClient.java
--- java/org/apache/commons/httpclient/HttpClient.java 11 Sep 2003 20:08:32 -0000 1.81
+++ java/org/apache/commons/httpclient/HttpClient.java 16 Sep 2003 02:22:01 -0000
@@ -120,12 +120,22 @@
// ----------------------------------------------------------- Constructors
/**
- * Creates an HttpClient using SimpleHttpConnectionManager.
+ * Creates an HttpClient using the default connection manager.
*
- * @see SimpleHttpConnectionManager
+ * @see HttpClientParams#getConnectionManagerClass()
*/
public HttpClient() {
- this(new SimpleHttpConnectionManager());
+
+ super();
+ try {
+ this.httpConnectionManager =
+ (HttpConnectionManager) params.getConnectionManagerClass().newInstance();
+ } catch (Exception e) {
+ LOG.warn("Error instantiating connection manager class, defaulting to"
+ + " SimpleHttpConnectionManager",
+ e);
+ this.httpConnectionManager = new SimpleHttpConnectionManager();
+ }
}
/**
@@ -140,12 +150,7 @@
throw new IllegalArgumentException("httpConnectionManager cannot be null");
}
- this.state = new HttpState();
this.httpConnectionManager = httpConnectionManager;
-
- this.hostConfiguration = new HostConfiguration();
- this.params = new HttpClientParams();
-
}
// ----------------------------------------------------- Instance Variables
@@ -156,12 +161,12 @@
/**
* My {@link HttpState state}.
*/
- private HttpState state;
+ private HttpState state = new HttpState();
- private HttpClientParams params;
+ private HttpClientParams params = new HttpClientParams();
/** The host configuration to use */
- private HostConfiguration hostConfiguration;
+ private HostConfiguration hostConfiguration = new HostConfiguration();
// ------------------------------------------------------------- Properties
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.1
diff -u -r1.1 DefaultHttpParams.java
--- java/org/apache/commons/httpclient/params/DefaultHttpParams.java 11 Sep 2003 20:08:33 -0000 1.1
+++ java/org/apache/commons/httpclient/params/DefaultHttpParams.java 16 Sep 2003 02:22:01 -0000
@@ -87,15 +87,32 @@
private static HttpParamsFactory httpParamsFactory = new DefaultHttpParamsFactory();
+ /**
+ * Gets the default HttpParams to be used.
+ *
+ * @return the value returned from HttpParamsFactory#getDefaultParams()
+ *
+ * @see HttpParamsFactory#getDefaultParams()
+ */
public static HttpParams getDefaultParams() {
return httpParamsFactory.getDefaultParams();
}
+ /**
+ * Sets the factory that will provide the default HttpParams.
+ *
+ * @param httpParamsFactory an instance of HttpParamsFactory
+ *
+ * @see #getDefaultParams()
+ */
public static void setHttpParamsFactory(HttpParamsFactory httpParamsFactory) {
+ if (httpParamsFactory == null) {
+ throw new IllegalArgumentException("httpParamsFactory may not be null");
+ }
DefaultHttpParams.httpParamsFactory = httpParamsFactory;
}
-
+ /** The set of default values to defer to */
private HttpParams defaults = null;
/** Hash map of HTTP parameters that this object contains */
@@ -106,6 +123,12 @@
this.defaults = defaults;
}
+ /**
+ * Initializes this class with defaults set to the value returned from
+ * DefaultHttpParams.getDefaultParams().
+ *
+ * @see #getDefaultParams()
+ */
public DefaultHttpParams() {
this(getDefaultParams());
}
@@ -212,18 +235,10 @@
}
public boolean isParameterTrue(final String name) {
- Object param = getParameter(name);
- if (param == null) {
- return false;
- }
- return ((Boolean)param).booleanValue() == true;
+ return getBooleanParameter(name, false);
}
public boolean isParameterFalse(final String name) {
- Object param = getParameter(name);
- if (param == null) {
- return false;
- }
- return ((Boolean)param).booleanValue() == false;
+ return !getBooleanParameter(name, true);
}
}
Index: java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v
retrieving revision 1.1
diff -u -r1.1 DefaultHttpParamsFactory.java
--- java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 11 Sep 2003 20:08:33 -0000 1.1
+++ java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 16 Sep 2003 02:22:02 -0000
@@ -1,6 +1,8 @@
package org.apache.commons.httpclient.params;
import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.SimpleHttpConnectionManager;
+import org.apache.commons.httpclient.util.DateParser;
@@ -31,6 +33,27 @@
params.setParameter(HttpMethodParams.USER_AGENT, "Jakarta Commons-HttpClient/2.1m1");
params.setVersion(HttpVersion.HTTP_1_1);
+ params.setConnectionManagerClass(SimpleHttpConnectionManager.class);
+
+ params.setParameter(
+ DateParser.KEY_DATE_PATTERNS,
+ new String[] {
+ DateParser.PATTERN_RFC1123,
+ DateParser.PATTERN_RFC1036,
+ DateParser.PATTERN_ASCTIME,
+ "EEE, dd-MMM-yyyy HH:mm:ss z",
+ "EEE, dd-MMM-yyyy HH-mm-ss z",
+ "EEE, dd MMM yy HH:mm:ss z",
+ "EEE dd-MMM-yyyy HH:mm:ss z",
+ "EEE dd MMM yyyy HH:mm:ss z",
+ "EEE dd-MMM-yyyy HH-mm-ss z",
+ "EEE dd-MMM-yy HH:mm:ss z",
+ "EEE dd MMM yy HH:mm:ss z",
+ "EEE,dd-MMM-yy HH:mm:ss z",
+ "EEE,dd-MMM-yyyy HH:mm:ss z",
+ "EEE, dd-MM-yyyy HH:mm:ss z",
+ }
+ );
// TODO: To be removed. Provided for backward compatibility
String agent = System.getProperties().getProperty("httpclient.useragent");
Index: java/org/apache/commons/httpclient/params/HttpParamsFactory.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpParamsFactory.java,v
retrieving revision 1.1
diff -u -r1.1 HttpParamsFactory.java
--- java/org/apache/commons/httpclient/params/HttpParamsFactory.java 11 Sep 2003 20:08:33 -0000 1.1
+++ java/org/apache/commons/httpclient/params/HttpParamsFactory.java 16 Sep 2003 02:22:02 -0000
@@ -1,9 +1,82 @@
+/*
+ * $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
+ * .
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
package org.apache.commons.httpclient.params;
-
-
+/**
+ * A factory for getting the default set of parameters to use when creating an instance of
+ * HttpParams.
+ *
+ * @see org.apache.commons.httpclient.params.DefaultHttpParams#setHttpParamsFactory(HttpParamsFactory)
+ */
public interface HttpParamsFactory {
+ /**
+ * Gets the default parameters. This method may be called more than once and is not required
+ * to always return the same value.
+ *
+ * @return an instance of HttpParams
+ */
HttpParams getDefaultParams();
}
Index: java/org/apache/commons/httpclient/util/DateParser.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/DateParser.java,v
retrieving revision 1.6
diff -u -r1.6 DateParser.java
--- java/org/apache/commons/httpclient/util/DateParser.java 25 Aug 2003 03:09:57 -0000 1.6
+++ java/org/apache/commons/httpclient/util/DateParser.java 16 Sep 2003 02:22:03 -0000
@@ -69,6 +69,10 @@
import java.util.Locale;
import java.util.TimeZone;
+import org.apache.commons.httpclient.params.DefaultHttpParams;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* A utility class for parsing HTTP dates as used in cookies and other headers.
* This class handles dates as defined by RFC 2616 section 3.3.1 as well as
@@ -79,6 +83,16 @@
*/
public class DateParser {
+ /** Log object for this class. */
+ private static final Log LOG = LogFactory.getLog(DateParser.class);
+
+ /**
+ * The key used to look up the date patterns to be used.
+ *
+ * @see org.apache.commons.httpclient.params.DefaultHttpParams
+ */
+ public static final String KEY_DATE_PATTERNS = "http.dateParser.patterns";
+
/**
* Date format pattern used to parse HTTP date headers in RFC 1123 format.
*/
@@ -95,26 +109,9 @@
*/
public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
- /** The patterns used for parsing dates */
- private static final String[] DATE_PATTERNS = {
- PATTERN_RFC1123,
- PATTERN_RFC1036,
- PATTERN_ASCTIME,
- "EEE, dd-MMM-yyyy HH:mm:ss z",
- "EEE, dd-MMM-yyyy HH-mm-ss z",
- "EEE, dd MMM yy HH:mm:ss z",
- "EEE dd-MMM-yyyy HH:mm:ss z",
- "EEE dd MMM yyyy HH:mm:ss z",
- "EEE dd-MMM-yyyy HH-mm-ss z",
- "EEE dd-MMM-yy HH:mm:ss z",
- "EEE dd MMM yy HH:mm:ss z",
- "EEE,dd-MMM-yy HH:mm:ss z",
- "EEE,dd-MMM-yyyy HH:mm:ss z",
- "EEE, dd-MM-yyyy HH:mm:ss z",
- };
-
/**
- * Parses a date value.
+ * Parses a date value. The formats used for parsing the date value are retrieved from
+ * the default http params.
*
* @param dateValue the date value to parse
*
@@ -122,9 +119,19 @@
*
* @throws DateParseException if the value could not be parsed using any of the
* supported date formats
+ *
+ * @see DefaultHttpParams#getDefaultParams()
*/
public static Date parseDate(String dateValue) throws DateParseException {
- return parseDate(dateValue, DATE_PATTERNS);
+
+ String[] patterns = (String[]) DefaultHttpParams.getDefaultParams().getParameter(
+ KEY_DATE_PATTERNS
+ );
+ if (patterns == null) {
+ LOG.warn("DateParser patterns not included in the default params.");
+ patterns = new String[] { PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123 };
+ }
+ return parseDate(dateValue, patterns);
}
/**