Index: examples/CookieDemoApp.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v retrieving revision 1.11 diff -u -r1.11 CookieDemoApp.java --- examples/CookieDemoApp.java 3 Oct 2003 20:57:35 -0000 1.11 +++ examples/CookieDemoApp.java 19 Oct 2003 17:08:34 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v 1.11 2003/10/03 20:57:35 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v 1.11 2003/10/03 20:57:35 olegk Exp $ * $Revision: 1.11 $ * $Date: 2003/10/03 20:57:35 $ * ==================================================================== @@ -108,24 +108,26 @@ Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false); // and then added to your HTTP state instance initialState.addCookie(mycookie); + + // Get HTTP client instance + HttpClient httpclient = new HttpClient(); + httpclient.getParams().setConnectionTimeout(30000); + httpclient.setState(initialState); + // RFC 2101 cookie management spec is used per default // to parse, validate, format & match cookies - initialState.setCookiePolicy(CookiePolicy.RFC2109); + httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109); // A different cookie management spec can be selected // when desired -// initialState.setCookiePolicy(CookiePolicy.NETSCAPE_DRAFT); + //httpclient.getParams().setCookiePolicy(CookiePolicy.NETSCAPE); // Netscape Cookie Draft spec is provided for completeness // You would hardly want to use this spec in real life situations -// initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY); + //httppclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); // Compatibility policy is provided in order to mimic cookie // management of popular web browsers that is in some areas // not 100% standards compliant - // Get HTTP client instance - HttpClient httpclient = new HttpClient(); - httpclient.getParams().setConnectionTimeout(30000); - httpclient.setState(initialState); // Get HTTP GET method GetMethod httpget = new GetMethod(strURL); // Execute HTTP GET Index: examples/FormLoginDemo.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/examples/FormLoginDemo.java,v retrieving revision 1.2 diff -u -r1.2 FormLoginDemo.java --- examples/FormLoginDemo.java 17 Jul 2003 21:57:42 -0000 1.2 +++ examples/FormLoginDemo.java 19 Oct 2003 17:08:35 -0000 @@ -84,7 +84,7 @@ HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http"); - client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); + client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); // 'developer.java.sun.com' has cookie compliance problems // Their session cookie's domain attribute is in violation of the RFC2109 // We have to resort to using compatibility cookie policy Index: java/org/apache/commons/httpclient/Cookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v retrieving revision 1.39 diff -u -r1.39 Cookie.java --- java/org/apache/commons/httpclient/Cookie.java 5 Jul 2003 22:31:20 -0000 1.39 +++ java/org/apache/commons/httpclient/Cookie.java 19 Oct 2003 17:08:38 -0000 @@ -468,8 +468,13 @@ * @return a string suitable for sending in a Cookie header. */ public String toExternalForm() { - return CookiePolicy.getSpecByVersion( - getVersion()).formatCookie(this); + CookieSpec spec = null; + if (getVersion() > 0) { + spec = CookiePolicy.getDefaultSpec(); + } else { + spec = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); + } + return spec.formatCookie(this); } /** 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 19 Oct 2003 17:08:50 -0000 @@ -1156,7 +1156,7 @@ // Clean up the cookie headers removeRequestHeader("cookie"); - CookieSpec matcher = CookiePolicy.getSpecByPolicy(state.getCookiePolicy()); + CookieSpec matcher = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { @@ -1487,7 +1487,7 @@ headers = getResponseHeaderGroup().getHeaders("set-cookie"); } - CookieSpec parser = CookiePolicy.getSpecByPolicy(state.getCookiePolicy()); + CookieSpec parser = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); for (int i = 0; i < headers.length; i++) { Header header = headers[i]; Cookie[] cookies = null; Index: java/org/apache/commons/httpclient/HttpState.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v retrieving revision 1.27 diff -u -r1.27 HttpState.java --- java/org/apache/commons/httpclient/HttpState.java 16 Sep 2003 21:29:45 -0000 1.27 +++ java/org/apache/commons/httpclient/HttpState.java 19 Oct 2003 17:08:54 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v 1.27 2003/09/16 21:29:45 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v 1.27 2003/09/16 21:29:45 olegk Exp $ * $Revision: 1.27 $ * $Date: 2003/09/16 21:29:45 $ * @@ -124,15 +124,11 @@ * Array of {@link Cookie cookies} that this HTTP state contains. */ private ArrayList cookies = new ArrayList(); - /** - * Cookie policy that applies to this HTTP state. Default is - * {@link CookiePolicy#RFC2109} - */ - private int cookiePolicy = CookiePolicy.RFC2109; private boolean preemptive = false; - // -------------------------------------------------------- Class Variables + private int cookiePolicy = 0; + // -------------------------------------------------------- Class Variables /** Log object for this class. */ private static final Log LOG = LogFactory.getLog(HttpState.class); @@ -141,11 +137,7 @@ * Default constructor. */ public HttpState() { - super(); - - this.cookiePolicy = CookiePolicy.getDefaultPolicy(); - } // ------------------------------------------------------------- Properties @@ -290,10 +282,14 @@ * HTTP state. * * @return The {@link CookiePolicy cookie policy}. + * + * @deprecated Use + * {@link org.apache.commons.httpclient.params.HttpMethodParams#getCookiePolicy()}, + * {@link HttpMethod#getParams()}. */ public int getCookiePolicy() { - return this.cookiePolicy; + return CookiePolicy.getDefaultPolicy(); } @@ -338,6 +334,10 @@ * {@link CookiePolicy#RFC2109}. * * @param policy new {@link CookiePolicy cookie policy} + * + * @deprecated + * Use {@link org.apache.commons.httpclient.params.HttpMethodParams#setCookiePolicy(String)}, + * {@link HttpMethod#getParams()}. */ public void setCookiePolicy(int policy) { 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.8 diff -u -r1.8 CookiePolicy.java --- java/org/apache/commons/httpclient/cookie/CookiePolicy.java 11 Oct 2003 19:46:51 -0000 1.8 +++ java/org/apache/commons/httpclient/cookie/CookiePolicy.java 19 Oct 2003 17:08:56 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v 1.8 2003/10/11 19:46:51 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v 1.8 2003/10/11 19:46:51 olegk Exp $ * $Revision: 1.8 $ * $Date: 2003/10/11 19:46:51 $ * @@ -63,6 +63,10 @@ package org.apache.commons.httpclient.cookie; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -73,14 +77,11 @@ * can be chosen when appropriate or set default when desired *
The following specifications are provided: *
Default policy can be set on JVM start-up through the system property - * "apache.commons.httpclient.cookiespec". Recognized values: - * COMPATIBILITY, NETSCAPE_DRAFT, RFC2109. * * @author Oleg Kalnichevski * @author Mike Bowler @@ -89,52 +90,125 @@ */ public abstract class CookiePolicy { - /** cookiespec system property. */ - private static final String SYSTEM_PROPERTY = - "apache.commons.httpclient.cookiespec"; + private static Map SPECS = Collections.synchronizedMap(new HashMap()); + + /** + * The policy that provides high degree of compatibilty + * with common cookie management of popular HTTP agents. + */ + public static final String BROWSER_COMPATIBILITY = "compatibility"; + + /** + * The Netscape cookie draft compliant policy. + */ + public static final String NETSCAPE = "netscape"; + /** + * The RFC 2109 compliant policy. + */ + public static final String RFC_2109 = "rfc2109"; + + /** + * The default cookie policy. + */ + 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()); + } + /** * The COMPATIBILITY policy provides high compatibilty * with common cookie management of popular HTTP agents. + * + * @deprecated Use {@link #BROWSER_COMPATIBILITY} */ public static final int COMPATIBILITY = 0; - /** The NETSCAPE_DRAFT Netscape draft compliant policy. */ + /** + * The NETSCAPE_DRAFT Netscape draft compliant policy. + * + * @deprecated Use {@link #NETSCAPE} + */ public static final int NETSCAPE_DRAFT = 1; - /** The RFC2109 RFC 2109 compliant policy. */ + /** + * The RFC2109 RFC 2109 compliant policy. + * + * @deprecated Use {@link #RFC_2109} + */ public static final int RFC2109 = 2; - /** The default cookie policy. */ + /** + * The default cookie policy. + * + * @deprecated Use {@link #DEFAULT} + */ private static int defaultPolicy = RFC2109; /** Log object. */ protected static final Log LOG = LogFactory.getLog(CookiePolicy.class); - static { - String s = null; - try { - s = System.getProperty(SYSTEM_PROPERTY); - } catch (SecurityException ignore) { - } - if ("COMPATIBILITY".equalsIgnoreCase(s)) { - setDefaultPolicy(COMPATIBILITY); - } else if ("NETSCAPE_DRAFT".equalsIgnoreCase(s)) { - setDefaultPolicy(NETSCAPE_DRAFT); - } else if ("RFC2109".equalsIgnoreCase(s)) { - setDefaultPolicy(RFC2109); - } else { - if (s != null) { - LOG.warn("Unrecognized cookiespec property '" + s - + "' - using default"); - } - setDefaultPolicy(defaultPolicy); + /** + * Registers a new {@link CookieSpec cookie specification} with the given identifier. + * If a specification with the given ID already exists it will be overridden. + * This ID is the same one used to retrieve the {@link CookieSpec cookie specification} + * from {@link #getCookieSpec(String)}. + * + * @param id the identifier for this specification + * @param spec the {@link CookieSpec cookie specification} to register + * + * @see #getCookieSpec(String) + */ + public static void registerCookieSpec(final String id, final CookieSpec spec) { + if (id == null) { + throw new IllegalArgumentException("Id may not be null"); + } + if (spec == null) { + throw new IllegalArgumentException("Cookie spec may not be null"); } + SPECS.put(id, spec); + } + + /** + * Unregisters the {@link CookieSpec cookie specification} with the given ID. + * + * @param id the ID of the {@link CookieSpec cookie specification} to unregister + */ + public static void unregisterCookieSpec(final String id) { + if (id == null) { + throw new IllegalArgumentException("Id may not be null"); + } + SPECS.remove(id); } /** + * Gets the {@link CookieSpec cookie specification} with the given ID. + * + * @param id the {@link CookieSpec cookie specification} ID + * + * @return {@link CookieSpec cookie specification} + * + * @throws IllegalStateException if a policy with the ID cannot be found + */ + public static CookieSpec getCookieSpec(final String id) + throws IllegalStateException { + + if (id == null) { + throw new IllegalArgumentException("Id may not be null"); + } + return (CookieSpec)SPECS.get(id); + } + + /** * @return default cookie policy * (COMPATIBILITY | NETSCAPE_DRAFT | RFC2109) + * + * @deprecated Use {@link CookiePolicy#getCookieSpec(String)} + * @see #DEFAULT */ public static int getDefaultPolicy() { return defaultPolicy; @@ -144,16 +218,19 @@ /** * @param policy new default cookie policy * (COMPATIBILITY | NETSCAPE_DRAFT | RFC2109) + * + * @deprecated Use {@link CookiePolicy#registerCookieSpec(String, CookieSpec)} */ public static void setDefaultPolicy(int policy) { defaultPolicy = policy; } - /** * @param policy cookie policy to get the CookieSpec for * @return cookie specification interface for the given policy * (COMPATIBILITY | NETSCAPE_DRAFT | RFC2109) + * + * @deprecated Use {@link CookiePolicy#getCookieSpec(String)} */ public static CookieSpec getSpecByPolicy(int policy) { switch(policy) { @@ -164,16 +241,27 @@ case RFC2109: return new RFC2109Spec(); default: - return getSpecByPolicy(defaultPolicy); + return getDefaultSpec(); } } /** - * @return default cookie specification interface + * Returns {@link CookieSpec cookie specification} registered as {@link #DEFAULT}. + * If no default {@link CookieSpec cookie specification} has been registered, + * {@link RFC2109Spec RFC2109 specification} is returned. + * + * @return default {@link CookieSpec cookie specification} + * + * @see #DEFAULT */ public static CookieSpec getDefaultSpec() { - return getSpecByPolicy(defaultPolicy); + try { + return getCookieSpec(DEFAULT); + } catch (IllegalStateException e) { + LOG.warn("Default cookie policy is not registered"); + return new RFC2109Spec(); + } } @@ -182,14 +270,16 @@ * *
Supported versions: *
* This parameter expects a value of type {@link String}. + *
*/ public static final String USER_AGENT = "http.useragent"; @@ -94,35 +97,45 @@ * Defines the {@link HttpVersion HTTP protocol version} used by * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} per * default. + ** This parameter expects a value of type {@link HttpVersion}. + *
*/ public static final String PROTOCOL_VERSION = "http.protocol.version"; /** * Defines whether {@link org.apache.commons.httpclient.HttpMethod HTTP methods} should * reject ambiguous {@link org.apache.commons.httpclient.StatusLine HTTP status line}. + ** This parameter expects a value of type {@link Boolean}. + *
*/ public static final String UNAMBIGUOUS_STATUS_LINE = "http.protocol.unambiguous-statusline"; /** * Defines whether {@link org.apache.commons.httpclient.Cookie cookies} should be put on * a single {@link org.apache.commons.httpclient.Header response header}. + ** This parameter expects a value of type {@link Boolean}. + *
*/ public static final String SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; /** * Defines whether responses with an invalid Transfer-Encoding header should be * rejected. + ** This parameter expects a value of type {@link Boolean}. + *
*/ public static final String STRICT_TRANSFER_ENCODING = "http.protocol.strict-transfer-encoding"; /** * Defines whether the content body sent in response to * {@link org.apache.commons.httpclient.methods.HeadMethod} should be rejected. + ** This parameter expects a value of type {@link Boolean}. + *
*/ public static final String REJECT_HEAD_BODY = "http.protocol.reject-head-body"; @@ -131,7 +144,9 @@ * {@link org.apache.commons.httpclient.methods.HeadMethod HEAD method} from a * non-compliant server. If the parameter is not set or set to -1 non-compliant * response body check is disabled. + ** This parameter expects a value of type {@link Integer}. + *
*/ public static final String HEAD_BODY_CHECK_TIMEOUT = "http.protocol.head-body-timeout"; @@ -164,6 +179,14 @@ public static final String USE_EXPECT_CONTINUE = "http.protocol.expect-continue"; /** + * Defines {@link CookiePolicy cookie policy} to be used for cookie management. + *+ * This parameter expects a value of type {@link String}. + *
+ */ + public static final String COOKIE_POLICY = "http.protocol.cookie-policy"; + + /** * 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 @@ -214,6 +237,33 @@ */ public void setVersion(HttpVersion version) { setParameter(PROTOCOL_VERSION, version); + } + + + /** + * Returns {@link CookiePolicy cookie policy} to be used by the + * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} + * this collection of parameters applies to. + * + * @return {@link CookiePolicy cookie policy} + */ + public String getCookiePolicy() { + Object param = getParameter(COOKIE_POLICY); + if (param == null) { + return CookiePolicy.DEFAULT; + } + return (String)param; + } + + /** + * Assigns the {@link CookiePolicy cookie policy} to be used by the + * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} + * this collection of parameters applies to. + * + * @param policy the {@link CookiePolicy cookie policy} + */ + public void setCookiePolicy(String policy) { + setParameter(COOKIE_POLICY, policy); } Index: test/org/apache/commons/httpclient/TestCookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v retrieving revision 1.23 diff -u -r1.23 TestCookie.java --- test/org/apache/commons/httpclient/TestCookie.java 19 Jul 2003 08:46:59 -0000 1.23 +++ test/org/apache/commons/httpclient/TestCookie.java 19 Oct 2003 17:09:06 -0000 @@ -120,10 +120,10 @@ // ------------------------------------------------------- Helper Methods - private static Cookie[] cookieParse(int policy, String host, String path, boolean isSecure, Header setHeader) + private static Cookie[] cookieParse(String policy, String host, String path, boolean isSecure, Header setHeader) throws MalformedCookieException { - CookieSpec parser = CookiePolicy.getSpecByPolicy(policy); + CookieSpec parser = CookiePolicy.getCookieSpec(policy); Cookie[] cookies = parser.parse(host, DEFAULT_PORT, path, isSecure, setHeader); if (cookies != null) { @@ -139,27 +139,27 @@ private static Cookie[] cookieParse(String host, String path, boolean isSecure, Header setHeader) throws MalformedCookieException { - return cookieParse(CookiePolicy.RFC2109, host, path, isSecure, setHeader); + return cookieParse(CookiePolicy.RFC_2109, host, path, isSecure, setHeader); } private static Cookie[] cookieParse(String host, String path, Header setHeader) throws MalformedCookieException { - return cookieParse(CookiePolicy.RFC2109, host, path, false, setHeader); + return cookieParse(CookiePolicy.RFC_2109, host, path, false, setHeader); } private static Cookie[] netscapeCcookieParse(String host, String path, Header setHeader) throws MalformedCookieException { - return cookieParse(CookiePolicy.NETSCAPE_DRAFT, host, path, false, setHeader); + return cookieParse(CookiePolicy.NETSCAPE, host, path, false, setHeader); } - public static Header cookieCreateHeader(int policy, String domain, int port, String path, boolean secure, Cookie[] cookies) + public static Header cookieCreateHeader(String policy, String domain, int port, String path, boolean secure, Cookie[] cookies) { - CookieSpec matcher = CookiePolicy.getSpecByPolicy(policy); + CookieSpec matcher = CookiePolicy.getCookieSpec(policy); cookies = matcher.match(domain, port, path, secure, cookies); if ((cookies != null) && (cookies.length > 0)) { @@ -173,20 +173,20 @@ public static Header cookieCreateHeader(String domain, int port, String path, boolean secure, Cookie[] cookies) { - return cookieCreateHeader(CookiePolicy.RFC2109, domain, port, path, secure, cookies); + return cookieCreateHeader(CookiePolicy.RFC_2109, domain, port, path, secure, cookies); } - public boolean cookieMatch(int policy, String domain, int port, String path, boolean secure, Cookie cookie) + public boolean cookieMatch(String policy, String domain, int port, String path, boolean secure, Cookie cookie) { - CookieSpec matcher = CookiePolicy.getSpecByPolicy(policy); + CookieSpec matcher = CookiePolicy.getCookieSpec(policy); return matcher.match(domain, port, path, secure, cookie); } public boolean cookieMatch(String domain, int port, String path, boolean secure, Cookie cookie) { - return cookieMatch(CookiePolicy.RFC2109, domain, port, path, secure, cookie); + return cookieMatch(CookiePolicy.RFC_2109, domain, port, path, secure, cookie); } // ------------------------------------------------------------ Parse1 Test @@ -886,7 +886,7 @@ Header setCookie = new Header( "Set-Cookie", "name=value; path=/; domain=.mydomain.com"); try { - CookieSpec parser = CookiePolicy.getSpecByPolicy(CookiePolicy.COMPATIBILITY); + CookieSpec parser = CookiePolicy.getCookieSpec(CookiePolicy.BROWSER_COMPATIBILITY); Cookie[] cookies = parser.parse("myhost.mydomain.com", 80, "/", false, setCookie ); parser.validate("myhost.mydomain.com", 80, "/", false, cookies[0]); String s = parser.formatCookie(cookies[0]); @@ -906,7 +906,7 @@ Header setCookie = new Header( "Set-Cookie", "name=value; path=/; domain=.mydomain.com"); try { - CookieSpec parser = CookiePolicy.getSpecByPolicy(CookiePolicy.NETSCAPE_DRAFT); + CookieSpec parser = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); Cookie[] cookies = parser.parse("myhost.mydomain.com", 80, "/", false, setCookie ); parser.validate("myhost.mydomain.com", 80, "/", false, cookies[0]); String s = parser.formatCookie(cookies[0]); @@ -924,7 +924,7 @@ */ public void testRFC2109CookieFormatting() { - CookieSpec parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109); + CookieSpec parser = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2109); Header setCookie = null; Cookie[] cookies = null; try { @@ -954,7 +954,7 @@ */ public void testNetscapeCookieExpireAttribute() { - CookieSpec parser = CookiePolicy.getSpecByPolicy(CookiePolicy.NETSCAPE_DRAFT); + CookieSpec parser = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); Header setCookie = null; Cookie[] cookies = null; try { @@ -991,11 +991,11 @@ CookieSpec parser = null; String s = null; - parser = CookiePolicy.getSpecByPolicy(CookiePolicy.COMPATIBILITY); + parser = CookiePolicy.getCookieSpec(CookiePolicy.BROWSER_COMPATIBILITY); s = parser.formatCookie(cookie); assertEquals("name=", s); - parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109); + parser = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2109); s = parser.formatCookie(cookie); assertEquals("$Version=0; name=; $Domain=.whatever.com; $Path=/", s); } @@ -1009,7 +1009,7 @@ Cookie[] cookies = null; Header header = new Header("Set-Cookie", "a=b,c"); - parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109); + parser = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2109); cookies = parser.parse("localhost", 80, "/", false, header); assertEquals("number of cookies", 2, cookies.length); assertEquals("a", cookies[0].getName()); @@ -1017,7 +1017,7 @@ assertEquals("c", cookies[1].getName()); assertEquals(null, cookies[1].getValue()); - parser = CookiePolicy.getSpecByPolicy(CookiePolicy.NETSCAPE_DRAFT); + parser = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); cookies = parser.parse("localhost", 80, "/", false, header); assertEquals("number of cookies", 1, cookies.length); assertEquals("a", cookies[0].getName()); Index: test/org/apache/commons/httpclient/TestWebappCookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v retrieving revision 1.12 diff -u -r1.12 TestWebappCookie.java --- test/org/apache/commons/httpclient/TestWebappCookie.java 3 Oct 2003 20:57:36 -0000 1.12 +++ test/org/apache/commons/httpclient/TestWebappCookie.java 19 Oct 2003 17:09:24 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v 1.12 2003/10/03 20:57:36 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v 1.12 2003/10/03 20:57:36 olegk Exp $ * $Revision: 1.12 $ * $Date: 2003/10/03 20:57:36 $ * ==================================================================== @@ -716,8 +716,8 @@ { - client.getState().setCookiePolicy(CookiePolicy.RFC2109); GetMethod method = new GetMethod("/" + getWebappContext() + "/cookie/write"); + method.getParams().setCookiePolicy(CookiePolicy.RFC_2109); method.setQueryString("simple=set"); try { @@ -749,8 +749,8 @@ } { - client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); GetMethod method = new GetMethod("/" + getWebappContext() + "/cookie/write"); + method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); method.setQueryString("simple=set"); try { @@ -767,6 +767,7 @@ assertEquals("value",((Cookie)(client.getState().getCookies()[0])).getValue()); GetMethod method2 = new GetMethod("/" + getWebappContext() + "/cookie/read"); + method2.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); try { client.executeMethod(method2);