Save This Page
Home » commons-httpclient-3.1-src » org.apache.commons » httpclient » [javadoc | source]
org.apache.commons.httpclient
public class: Cookie [javadoc | source]
java.lang.Object
   org.apache.commons.httpclient.NameValuePair
      org.apache.commons.httpclient.Cookie

All Implemented Interfaces:
    Comparator, Serializable

Direct Known Subclasses:
    Cookie2

HTTP "magic-cookie" represents a piece of state information that the HTTP agent and the target server can exchange to maintain a session.

Constructor:
 public Cookie() 
 public Cookie(String domain,
    String name,
    String value) 
    Creates a cookie with the given name, value and domain attribute.
    Parameters:
    name - the cookie name
    value - the cookie value
    domain - the domain this cookie can be sent to
 public Cookie(String domain,
    String name,
    String value,
    String path,
    Date expires,
    boolean secure) 
    Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, and secure attribute
    Parameters:
    name - the cookie name
    value - the cookie value
    domain - the domain this cookie can be sent to
    path - the path prefix for which this cookie can be sent
    expires - the Date at which this cookie expires, or null if the cookie expires at the end of the session
    secure - if true this cookie can only be sent over secure connections
    Throws:
    IllegalArgumentException - If cookie name is null or blank, cookie name contains a blank, or cookie name starts with character $
 public Cookie(String domain,
    String name,
    String value,
    String path,
    int maxAge,
    boolean secure) 
    Creates a cookie with the given name, value, domain attribute, path attribute, maximum age attribute, and secure attribute
    Parameters:
    name - the cookie name
    value - the cookie value
    domain - the domain this cookie can be sent to
    path - the path prefix for which this cookie can be sent
    maxAge - the number of seconds for which this cookie is valid. maxAge is expected to be a non-negative number. -1 signifies that the cookie should never expire.
    secure - if true this cookie can only be sent over secure connections
Method from org.apache.commons.httpclient.Cookie Summary:
compare,   equals,   getComment,   getDomain,   getExpiryDate,   getPath,   getSecure,   getVersion,   hashCode,   isDomainAttributeSpecified,   isExpired,   isExpired,   isPathAttributeSpecified,   isPersistent,   setComment,   setDomain,   setDomainAttributeSpecified,   setExpiryDate,   setPath,   setPathAttributeSpecified,   setSecure,   setVersion,   toExternalForm,   toString
Methods from org.apache.commons.httpclient.NameValuePair:
equals,   getName,   getValue,   hashCode,   setName,   setValue,   toString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.httpclient.Cookie Detail:
 public int compare(Object o1,
    Object o2) 

    Compares two cookies to determine order for cookie header.

    Most specific should be first.

    This method is implemented so a cookie can be used as a comparator for a SortedSet of cookies. Specifically it's used above in the createCookieHeader method.

 public boolean equals(Object obj) 
    Two cookies are equal if the name, path and domain match.
 public String getComment() 
    Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
 public String getDomain() 
    Returns domain attribute of the cookie.
 public Date getExpiryDate() 
    Returns the expiration Date of the cookie, or null if none exists.

    Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

 public String getPath() 
    Returns the path attribute of the cookie
 public boolean getSecure() 
 public int getVersion() 
    Returns the version of the cookie specification to which this cookie conforms.
 public int hashCode() 
    Returns a hash code in keeping with the Object#hashCode general hashCode contract.
 public boolean isDomainAttributeSpecified() 
    Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
 public boolean isExpired() 
    Returns true if this cookie has expired.
 public boolean isExpired(Date now) 
    Returns true if this cookie has expired according to the time passed in.
 public boolean isPathAttributeSpecified() 
    Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
 public boolean isPersistent() 
    Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
 public  void setComment(String comment) 
    If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.
 public  void setDomain(String domain) 
    Sets the domain attribute.
 public  void setDomainAttributeSpecified(boolean value) 
    Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a domain attribute if the cookie's domain was specified in the Set-Cookie header.
 public  void setExpiryDate(Date expiryDate) 
    Sets expiration date.

    Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

 public  void setPath(String path) 
    Sets the path attribute.
 public  void setPathAttributeSpecified(boolean value) 
    Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a path attribute if the cookie's path was specified in the Set-Cookie header.
 public  void setSecure(boolean secure) 
    Sets the secure attribute of the cookie.

    When true the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.

 public  void setVersion(int version) 
    Sets the version of the cookie specification to which this cookie conforms.
 public String toExternalForm() 
    Return a textual representation of the cookie.
 public String toString() 
    Return a textual representation of the cookie.