commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestCookie.java TestWebappCookie.java
Date Mon, 20 Oct 2003 22:17:12 GMT
olegk       2003/10/20 15:17:12

  Modified:    httpclient/src/examples CookieDemoApp.java
                        FormLoginDemo.java
               httpclient/src/java/org/apache/commons/httpclient
                        Cookie.java HttpMethodBase.java HttpState.java
               httpclient/src/java/org/apache/commons/httpclient/cookie
                        CookiePolicy.java
               httpclient/src/java/org/apache/commons/httpclient/params
                        DefaultHttpParamsFactory.java HttpMethodParams.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestCookie.java TestWebappCookie.java
  Log:
  PR# 21151 (Customizable Cookie Policy)
  
  The patch extends CookiePolicy class with a custom cookie specification plug-in
  mechanism.
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.12      +12 -10    jakarta-commons/httpclient/src/examples/CookieDemoApp.java
  
  Index: CookieDemoApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CookieDemoApp.java	3 Oct 2003 20:57:35 -0000	1.11
  +++ CookieDemoApp.java	20 Oct 2003 22:17:11 -0000	1.12
  @@ -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
  
  
  
  1.3       +1 -1      jakarta-commons/httpclient/src/examples/FormLoginDemo.java
  
  Index: FormLoginDemo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/FormLoginDemo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormLoginDemo.java	17 Jul 2003 21:57:42 -0000	1.2
  +++ FormLoginDemo.java	20 Oct 2003 22:17:11 -0000	1.3
  @@ -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
  
  
  
  1.40      +11 -6     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java
  
  Index: Cookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Cookie.java	5 Jul 2003 22:31:20 -0000	1.39
  +++ Cookie.java	20 Oct 2003 22:17:11 -0000	1.40
  @@ -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); 
       }
   
       /**
  
  
  
  1.184     +6 -6      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.183
  retrieving revision 1.184
  diff -u -r1.183 -r1.184
  --- HttpMethodBase.java	19 Oct 2003 18:46:02 -0000	1.183
  +++ HttpMethodBase.java	20 Oct 2003 22:17:12 -0000	1.184
  @@ -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;
  
  
  
  1.28      +15 -15    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java
  
  Index: HttpState.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- HttpState.java	16 Sep 2003 21:29:45 -0000	1.27
  +++ HttpState.java	20 Oct 2003 22:17:12 -0000	1.28
  @@ -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) {
  
  
  
  1.9       +133 -41   jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
  
  Index: CookiePolicy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CookiePolicy.java	11 Oct 2003 19:46:51 -0000	1.8
  +++ CookiePolicy.java	20 Oct 2003 22:17:12 -0000	1.9
  @@ -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
    * <p>The following specifications are provided:
    *  <ul>
  - *   <li><tt>COMPATIBILITY</tt>: compatible with the common cookie management
  - *   practices *  (even if they are not 100% standards compliant)
  - *   <li><tt>NETSCAPE_DRAFT</tt>: Netscape cookie draft compliant
  - *   <li><tt>RFC2109</tt>: RFC2109 compliant (default)
  + *   <li><tt>BROWSER_COMPATIBILITY</tt>: compatible with the common cookie

  + *   management practices (even if they are not 100% standards compliant)
  + *   <li><tt>NETSCAPE</tt>: Netscape cookie draft compliant
  + *   <li><tt>RFC_2109</tt>: RFC2109 compliant (default)
    *  </ul>
  - * <p>Default policy can be set on JVM start-up through the system property 
  - *  <tt>"apache.commons.httpclient.cookiespec"</tt>. Recognized values: 
  - *  <tt>COMPATIBILITY</tt>, <tt>NETSCAPE_DRAFT</tt>, <tt>RFC2109</tt>.
    * 
    * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  @@ -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 <tt>COMPATIBILITY</tt> policy provides high compatibilty 
        * with common cookie management of popular HTTP agents.
  +     * 
  +     * @deprecated Use {@link #BROWSER_COMPATIBILITY}
        */
       public static final int COMPATIBILITY = 0;
   
  -    /** The <tt>NETSCAPE_DRAFT</tt> Netscape draft compliant policy. */
  +    /** 
  +     * The <tt>NETSCAPE_DRAFT</tt> Netscape draft compliant policy.
  +     * 
  +     * @deprecated Use {@link #NETSCAPE} 
  +     */
       public static final int NETSCAPE_DRAFT = 1;
   
  -    /** The <tt>RFC2109</tt> RFC 2109 compliant policy. */
  +    /** 
  +     * The <tt>RFC2109</tt> 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
        *  <tt>(COMPATIBILITY | NETSCAPE_DRAFT | RFC2109)</tt>
  +     * 
  +     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
  +     * @see #DEFAULT 
        */
       public static int getDefaultPolicy() {
           return defaultPolicy;
  @@ -144,16 +218,19 @@
       /**
        * @param policy new default cookie policy
        *  <tt>(COMPATIBILITY | NETSCAPE_DRAFT | RFC2109)</tt>
  +     * 
  +     * @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
        *  <tt>(COMPATIBILITY | NETSCAPE_DRAFT | RFC2109)</tt>
  +     * 
  +     * @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 @@
        * 
        * <p>Supported versions:
        * <ul>
  -     *  <li><tt>version 0</tt> corresponds to the NETSCAPE_DRAFT
  -     *  <li><tt>version 1</tt> corresponds to the RFC2109
  +     *  <li><tt>version 0</tt> corresponds to the Netscape draft
  +     *  <li><tt>version 1</tt> corresponds to the RFC 2109
        *  <li>Any other cookie value coresponds to the default spec
        * <ul>
        *
        * @param ver the cookie version to get the spec for
        * @return cookie specification interface intended for processing 
  -     *  cookies with the given version 
  +     *  cookies with the given version
  +     * 
  +     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
        */
       public static CookieSpec getSpecByVersion(int ver) {
           switch(ver) {
  @@ -205,6 +295,8 @@
       /**
        * @return cookie specification interface that provides high compatibilty 
        * with common cookie management of popular HTTP agents
  +     * 
  +     * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
        */
       public static CookieSpec getCompatibilitySpec() {
           return getSpecByPolicy(COMPATIBILITY);
  
  
  
  1.4       +21 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java
  
  Index: DefaultHttpParamsFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultHttpParamsFactory.java	11 Oct 2003 19:46:51 -0000	1.3
  +++ DefaultHttpParamsFactory.java	20 Oct 2003 22:17:12 -0000	1.4
  @@ -68,6 +68,7 @@
   
   import org.apache.commons.httpclient.HttpVersion;
   import org.apache.commons.httpclient.SimpleHttpConnectionManager;
  +import org.apache.commons.httpclient.cookie.CookiePolicy;
   import org.apache.commons.httpclient.util.DateParser;
   
   
  @@ -100,6 +101,7 @@
           params.setParameter(HttpMethodParams.USER_AGENT, "Jakarta Commons-HttpClient/2.1m1");
           params.setVersion(HttpVersion.HTTP_1_1);
           params.setConnectionManagerClass(SimpleHttpConnectionManager.class);
  +        params.setCookiePolicy(CookiePolicy.RFC_2109);
   
           ArrayList datePatterns = new ArrayList();
           datePatterns.addAll(
  @@ -149,6 +151,22 @@
               }
           }
           
  +        // TODO: To be removed. Provided for backward compatibility
  +        String defaultCookiePolicy = null;
  +        try {
  +            defaultCookiePolicy = System.getProperty("apache.commons.httpclient.cookiespec");
  +        } catch (SecurityException ignore) {
  +        }
  +        if (defaultCookiePolicy != null) {
  +            if ("COMPATIBILITY".equalsIgnoreCase(defaultCookiePolicy)) {
  +                params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  +            } else if ("NETSCAPE_DRAFT".equalsIgnoreCase(defaultCookiePolicy)) {
  +                params.setCookiePolicy(CookiePolicy.NETSCAPE);
  +            } else if ("RFC2109".equalsIgnoreCase(defaultCookiePolicy)) {
  +                params.setCookiePolicy(CookiePolicy.RFC_2109);
  +            }
  +        }
  +
           return params;
       } 
   
  
  
  
  1.4       +54 -4     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java
  
  Index: HttpMethodParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpMethodParams.java	3 Oct 2003 20:57:36 -0000	1.3
  +++ HttpMethodParams.java	20 Oct 2003 22:17:12 -0000	1.4
  @@ -64,6 +64,7 @@
   package org.apache.commons.httpclient.params;
   
   import org.apache.commons.httpclient.HttpVersion;
  +import org.apache.commons.httpclient.cookie.CookiePolicy;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -86,7 +87,9 @@
       /**
        * Defines the content of the <tt>User-Agent</tt> header used by  
        * {@link org.apache.commons.httpclient.HttpMethod HTTP methods}.
  +     * <p>
        * This parameter expects a value of type {@link String}.
  +     * </p>
        */
       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.
  +     * <p>
        * This parameter expects a value of type {@link HttpVersion}.
  +     * </p>
        */
       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}.
  +     * <p>
        * This parameter expects a value of type {@link Boolean}.
  +     * </p>
        */
       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}.
  +     * <p>
        * This parameter expects a value of type {@link Boolean}.
  +     * </p>
        */
       public static final String SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";

   
       /**
        * Defines whether responses with an invalid <tt>Transfer-Encoding</tt>
header should be 
        * rejected.
  +     * <p>
        * This parameter expects a value of type {@link Boolean}.
  +     * </p>
        */
       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.
  +     * <p>
        * This parameter expects a value of type {@link Boolean}.
  +     * </p>
        */
       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 <tt>-1</tt>
non-compliant 
        * response body check is disabled.
  +     * <p>
        * This parameter expects a value of type {@link Integer}.
  +     * </p>
        */
       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.
  +     * <p>
  +     * This parameter expects a value of type {@link String}.
  +     * </p>
  +     */
  +    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);
       }
   
   
  
  
  
  1.24      +23 -23    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java
  
  Index: TestCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- TestCookie.java	19 Jul 2003 08:46:59 -0000	1.23
  +++ TestCookie.java	20 Oct 2003 22:17:12 -0000	1.24
  @@ -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());
  
  
  
  1.13      +7 -6      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java
  
  Index: TestWebappCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestWebappCookie.java	3 Oct 2003 20:57:36 -0000	1.12
  +++ TestWebappCookie.java	20 Oct 2003 22:17:12 -0000	1.13
  @@ -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);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message