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.211 diff -u -r1.211 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 19 Aug 2004 21:39:26 -0000 1.211 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 10 Sep 2004 14:19:45 -0000 @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; +import java.util.Collection; import org.apache.commons.httpclient.auth.AuthState; import org.apache.commons.httpclient.cookie.CookiePolicy; @@ -177,6 +178,10 @@ /** Whether the HTTP request has been transmitted to the target * server it its entirety */ private boolean requestSent = false; + + /** Actual cookie policy */ + private CookieSpec cookiespec = null; + // ----------------------------------------------------------- Constructors /** @@ -1045,6 +1050,7 @@ connectionCloseForced = false; hostAuthState.invalidate(); proxyAuthState.invalidate(); + cookiespec = null; requestSent = false; } @@ -1113,6 +1119,19 @@ } + /** + * Returns the actual cookie policy + * + * @return cookie spec + */ + private CookieSpec getCookieSpec() { + if (this.cookiespec == null) { + this.cookiespec = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); + this.cookiespec.setValidDateFormats( + (Collection)this.params.getParameter(HttpMethodParams.DATE_PATTERNS)); + } + return this.cookiespec; + } /** * Generates Cookie request headers for those {@link Cookie cookie}s @@ -1141,7 +1160,7 @@ } } - CookieSpec matcher = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); + CookieSpec matcher = getCookieSpec(); Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { @@ -1435,7 +1454,7 @@ headers = getResponseHeaderGroup().getHeaders("set-cookie"); } - CookieSpec parser = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); + CookieSpec parser = getCookieSpec(); for (int i = 0; i < headers.length; i++) { Header header = headers[i]; Cookie[] cookies = null; 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.28 diff -u -r1.28 HttpMethodDirector.java --- java/org/apache/commons/httpclient/HttpMethodDirector.java 5 Jul 2004 22:46:58 -0000 1.28 +++ java/org/apache/commons/httpclient/HttpMethodDirector.java 10 Sep 2004 14:19:45 -0000 @@ -406,7 +406,7 @@ // ======================================== HttpMethodRetryHandler handler = (HttpMethodRetryHandler)method.getParams().getParameter( - HttpMethodRetryHandler.HANDLER); + HttpMethodParams.RETRY_HANDLER); if (handler == null) { handler = new DefaultHttpMethodRetryHandler(); } Index: java/org/apache/commons/httpclient/HttpMethodRetryHandler.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodRetryHandler.java,v retrieving revision 1.1 diff -u -r1.1 HttpMethodRetryHandler.java --- java/org/apache/commons/httpclient/HttpMethodRetryHandler.java 5 Jul 2004 22:46:58 -0000 1.1 +++ java/org/apache/commons/httpclient/HttpMethodRetryHandler.java 10 Sep 2004 14:19:45 -0000 @@ -49,14 +49,6 @@ public interface HttpMethodRetryHandler { /** - * Sets the method retry handler parameter. - *

- * This parameter expects a value of type {@link HttpMethodRetryHandler}. - *

- */ - public static final String HANDLER = "http.method.retry-handler"; - - /** * Determines if a method should be retried after an HttpRecoverableException * occurs during execution. * Index: java/org/apache/commons/httpclient/cookie/CookiePolicy.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v retrieving revision 1.14 diff -u -r1.14 CookiePolicy.java --- java/org/apache/commons/httpclient/cookie/CookiePolicy.java 13 May 2004 04:02:00 -0000 1.14 +++ java/org/apache/commons/httpclient/cookie/CookiePolicy.java 10 Sep 2004 14:19:45 -0000 @@ -95,11 +95,11 @@ public static final String DEFAULT = "default"; static { - CookiePolicy.registerCookieSpec(DEFAULT, new RFC2109Spec()); - CookiePolicy.registerCookieSpec(RFC_2109, new RFC2109Spec()); - CookiePolicy.registerCookieSpec(BROWSER_COMPATIBILITY, new CookieSpecBase()); - CookiePolicy.registerCookieSpec(NETSCAPE, new NetscapeDraftSpec()); - CookiePolicy.registerCookieSpec(IGNORE_COOKIES, new IgnoreCookiesSpec()); + CookiePolicy.registerCookieSpec(DEFAULT, RFC2109Spec.class); + CookiePolicy.registerCookieSpec(RFC_2109, RFC2109Spec.class); + CookiePolicy.registerCookieSpec(BROWSER_COMPATIBILITY, CookieSpecBase.class); + CookiePolicy.registerCookieSpec(NETSCAPE, NetscapeDraftSpec.class); + CookiePolicy.registerCookieSpec(IGNORE_COOKIES, IgnoreCookiesSpec.class); } /** @@ -147,14 +147,14 @@ * * @since 3.0 */ - public static void registerCookieSpec(final String id, final CookieSpec spec) { + public static void registerCookieSpec(final String id, final Class clazz) { if (id == null) { throw new IllegalArgumentException("Id may not be null"); } - if (spec == null) { - throw new IllegalArgumentException("Cookie spec may not be null"); + if (clazz == null) { + throw new IllegalArgumentException("Cookie spec class may not be null"); } - SPECS.put(id, spec); + SPECS.put(id.toLowerCase(), clazz); } /** @@ -168,7 +168,7 @@ if (id == null) { throw new IllegalArgumentException("Id may not be null"); } - SPECS.remove(id); + SPECS.remove(id.toLowerCase()); } /** @@ -188,11 +188,20 @@ if (id == null) { throw new IllegalArgumentException("Id may not be null"); } - CookieSpec cookiespec = (CookieSpec)SPECS.get(id); - if (cookiespec == null) { - throw new IllegalStateException("Unsupported cookie spec '" + id + "'"); + Class clazz = (Class)SPECS.get(id.toLowerCase()); + + if (clazz != null) { + try { + return (CookieSpec)clazz.newInstance(); + } catch (Exception e) { + LOG.error("Error initializing cookie spec: " + id, e); + throw new IllegalStateException(id + + " cookie spec implemented by " + + clazz.getName() + " could not be initialized"); + } + } else { + throw new IllegalStateException("Unsupported cookie spec " + id); } - return cookiespec; } /** Index: java/org/apache/commons/httpclient/cookie/CookieSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java,v retrieving revision 1.10 diff -u -r1.10 CookieSpec.java --- java/org/apache/commons/httpclient/cookie/CookieSpec.java 13 May 2004 04:02:00 -0000 1.10 +++ java/org/apache/commons/httpclient/cookie/CookieSpec.java 10 Sep 2004 14:19:45 -0000 @@ -29,6 +29,8 @@ package org.apache.commons.httpclient.cookie; +import java.util.Collection; + import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.Cookie; @@ -99,7 +101,7 @@ * @throws MalformedCookieException if an exception occurs during parsing * @throws IllegalArgumentException if an input parameter is illegal */ - void parseAttribute(final NameValuePair attribute, final Cookie cookie) + void parseAttribute(NameValuePair attribute, Cookie cookie) throws MalformedCookieException, IllegalArgumentException; /** @@ -119,6 +121,23 @@ final Cookie cookie) throws MalformedCookieException, IllegalArgumentException; + + /** + * Sets the {@link Collection} of date patterns used for parsing. The String patterns must be + * compatible with {@link SimpleDateFormat}. + * + * @param datepatterns collection of date patterns + */ + void setValidDateFormats(Collection datepatterns); + + /** + * Returns the {@link Collection} of date patterns used for parsing. The String patterns are compatible + * with the {@link SimpleDateFormat}. + * + * @return collection of date patterns + */ + Collection getValidDateFormats(); + /** * Determines if a Cookie matches a location. * @@ -158,7 +177,7 @@ * * @since 3.0 */ - boolean domainMatch(final String host, final String domain); + boolean domainMatch(String host, String domain); /** * Performs path-match as defined by the cookie specification. @@ -168,7 +187,7 @@ * * @since 3.0 */ - boolean pathMatch(final String path, final String topmostPath); + boolean pathMatch(String path, String topmostPath); /** * Create a "Cookie" header value for an array of cookies. Index: java/org/apache/commons/httpclient/cookie/CookieSpecBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v retrieving revision 1.26 diff -u -r1.26 CookieSpecBase.java --- java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 27 Apr 2004 22:35:21 -0000 1.26 +++ java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 10 Sep 2004 14:19:45 -0000 @@ -29,6 +29,7 @@ package org.apache.commons.httpclient.cookie; +import java.util.Collection; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -64,6 +65,9 @@ /** Log object */ protected static final Log LOG = LogFactory.getLog(CookieSpec.class); + /** Valid date patterns */ + private Collection datepatterns = null; + /** Default constructor */ public CookieSpecBase() { super(); @@ -153,7 +157,7 @@ i2 = header.length(); } try { - DateParser.parseDate(header.substring(i1, i2)); + DateParser.parseDate(header.substring(i1, i2), this.datepatterns); isNetscapeCookie = true; } catch (DateParseException e) { // Does not look like a valid expiry date @@ -320,7 +324,7 @@ } try { - cookie.setExpiryDate(DateParser.parseDate(paramValue)); + cookie.setExpiryDate(DateParser.parseDate(paramValue, this.datepatterns)); } catch (DateParseException dpe) { LOG.debug("Error parsing cookie date", dpe); throw new MalformedCookieException( @@ -336,7 +340,15 @@ } - /** + public Collection getValidDateFormats() { + return this.datepatterns; + } + + public void setValidDateFormats(final Collection datepatterns) { + this.datepatterns = datepatterns; + } + + /** * Performs most common {@link Cookie} validation * * @param host the host from which the {@link Cookie} was received Index: java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java,v retrieving revision 1.5 diff -u -r1.5 IgnoreCookiesSpec.java --- java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java 13 May 2004 04:02:00 -0000 1.5 +++ java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java 10 Sep 2004 14:19:45 -0000 @@ -29,6 +29,8 @@ package org.apache.commons.httpclient.cookie; +import java.util.Collection; + import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.NameValuePair; @@ -55,6 +57,19 @@ return new Cookie[0]; } + /** + * @return null + */ + public Collection getValidDateFormats() { + return null; + } + + /** + * Does nothing. + */ + public void setValidDateFormats(Collection datepatterns) { + } + /** * @return null */ 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.11 diff -u -r1.11 DefaultHttpParamsFactory.java --- java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 5 Jul 2004 22:46:59 -0000 1.11 +++ java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 10 Sep 2004 14:19:46 -0000 @@ -33,7 +33,6 @@ import java.util.Arrays; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; -import org.apache.commons.httpclient.HttpMethodRetryHandler; import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.SimpleHttpConnectionManager; import org.apache.commons.httpclient.cookie.CookiePolicy; @@ -75,7 +74,7 @@ params.setCookiePolicy(CookiePolicy.RFC_2109); params.setHttpElementCharset("US-ASCII"); params.setContentCharset("ISO-8859-1"); - params.setParameter(HttpMethodRetryHandler.HANDLER, new DefaultHttpMethodRetryHandler()); + params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); ArrayList datePatterns = new ArrayList(); datePatterns.addAll( @@ -98,7 +97,7 @@ } ) ); - params.setParameter(DateParser.KEY_DATE_PATTERNS, datePatterns); + params.setParameter(HttpMethodParams.DATE_PATTERNS, datePatterns); // TODO: To be removed. Provided for backward compatibility String agent = null; Index: java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java,v retrieving revision 1.8 diff -u -r1.8 HttpConnectionManagerParams.java --- java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java 19 Jul 2004 20:37:43 -0000 1.8 +++ java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java 10 Sep 2004 14:19:46 -0000 @@ -29,7 +29,6 @@ package org.apache.commons.httpclient.params; -import java.util.Collections; import java.util.HashMap; import java.util.Map; 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.13 diff -u -r1.13 HttpMethodParams.java --- java/org/apache/commons/httpclient/params/HttpMethodParams.java 13 May 2004 04:01:22 -0000 1.13 +++ java/org/apache/commons/httpclient/params/HttpMethodParams.java 10 Sep 2004 14:19:47 -0000 @@ -29,6 +29,7 @@ package org.apache.commons.httpclient.params; +import org.apache.commons.httpclient.HttpMethodRetryHandler; import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.logging.Log; @@ -229,6 +230,23 @@ */ public static final String SO_TIMEOUT = "http.socket.timeout"; + /** + * The key used to look up the date patterns used for parsing. The String patterns are stored + * in a {@link Collection} and must be compatible with {@link SimpleDateFormat}. + *

+ * This parameter expects a value of type {@link Collection}. + *

+ */ + public static final String DATE_PATTERNS = "http.dateparser.patterns"; + + /** + * Sets the method retry handler parameter. + *

+ * This parameter expects a value of type {@link HttpMethodRetryHandler}. + *

+ */ + public static final String RETRY_HANDLER = "http.method.retry-handler"; + /** * Creates a new collection of parameters with the collection returned * by {@link #getDefaultParams()} as a parent. The collection will defer 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.9 diff -u -r1.9 DateParser.java --- java/org/apache/commons/httpclient/util/DateParser.java 18 Apr 2004 23:51:38 -0000 1.9 +++ java/org/apache/commons/httpclient/util/DateParser.java 10 Sep 2004 14:19:47 -0000 @@ -38,7 +38,6 @@ 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; @@ -56,14 +55,6 @@ private static final Log LOG = LogFactory.getLog(DateParser.class); /** - * The key used to look up the date patterns used for parsing. The String patterns are stored - * in a {@link Collection} and must be compatible with {@link SimpleDateFormat}. - * - * @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. */ public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz"; @@ -79,6 +70,8 @@ */ public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy"; + private static final Collection DEFAULT_PATTERNS = Arrays.asList( + new String[] { PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123 } ); /** * Parses a date value. The formats used for parsing the date value are retrieved from * the default http params. @@ -92,19 +85,9 @@ * * @see DefaultHttpParams#getDefaultParams() */ - public static Date parseDate(String dateValue) throws DateParseException { - - Collection patterns = (Collection) DefaultHttpParams.getDefaultParams().getParameter( - KEY_DATE_PATTERNS - ); - if (patterns == null) { - LOG.warn("DateParser patterns not included in the default params."); - patterns = Arrays.asList( - new String[] { PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123 } - ); - } - return parseDate(dateValue, patterns); - } +// public static Date parseDate(String dateValue) throws DateParseException { +// return parseDate(dateValue, null); +// } /** * Parses the date value using the given date formats. @@ -116,7 +99,7 @@ * * @throws DateParseException if none of the dataFormats could parse the dateValue */ - private static Date parseDate( + public static Date parseDate( String dateValue, Collection dateFormats ) throws DateParseException { @@ -124,7 +107,9 @@ if (dateValue == null) { throw new IllegalArgumentException("dateValue is null"); } - + if (dateFormats == null) { + dateFormats = DEFAULT_PATTERNS; + } // trim single quotes around date if present // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279 if (dateValue.length() > 1 Index: test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java,v retrieving revision 1.6 diff -u -r1.6 TestCookieCompatibilitySpec.java --- test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java 5 Jun 2004 16:49:20 -0000 1.6 +++ test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java 10 Sep 2004 14:19:47 -0000 @@ -28,6 +28,7 @@ package org.apache.commons.httpclient.cookie; +import java.util.Collection; import java.util.Date; import junit.framework.Test; @@ -38,6 +39,9 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.params.DefaultHttpParamsFactory; +import org.apache.commons.httpclient.params.HttpMethodParams; +import org.apache.commons.httpclient.params.HttpParams; /** @@ -768,7 +772,10 @@ private void checkDate(String date) throws Exception { Header header = new Header("Set-Cookie", "custno=12345;Expires='"+date+"';"); + HttpParams params = new DefaultHttpParamsFactory().getDefaultParams(); CookieSpec cookiespec = new CookieSpecBase(); + cookiespec.setValidDateFormats( + (Collection)params.getParameter(HttpMethodParams.DATE_PATTERNS)); cookieParse(cookiespec, "localhost", 80, "/", false, header); } Index: test/org/apache/commons/httpclient/cookie/TestCookiePolicy.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookiePolicy.java,v retrieving revision 1.1 diff -u -r1.1 TestCookiePolicy.java --- test/org/apache/commons/httpclient/cookie/TestCookiePolicy.java 25 Apr 2004 12:25:09 -0000 1.1 +++ test/org/apache/commons/httpclient/cookie/TestCookiePolicy.java 10 Sep 2004 14:19:47 -0000 @@ -86,7 +86,7 @@ } public void testRegisterUnregister() { - CookiePolicy.registerCookieSpec("whatever", new CookieSpecBase()); + CookiePolicy.registerCookieSpec("whatever", CookieSpecBase.class); CookiePolicy.unregisterCookieSpec("whatever"); try { CookiePolicy.getCookieSpec("whatever");