org.apache.commons.httpclient
Class Cookie

public class Cookie
extends NameValuePair
implements Serializable, Comparator

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

SinceNot specified.
Version$Revision:
AuthorB.C. Holmes, <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>, <a href="mailto:dsale@us.britannica.com">Doug Sale</a>, Rod Waldhoff, dIon Gillard, Sean C. Sullivan, <a href="mailto:JEvans@Cyveillance.com">John Evans</a>, Marc A. Saegesser, <a href
Wiki javadoc Use textile entry format.
Add your comments here.
Constructor Summary
Cookie()
Default constructor.
Cookie( String domain, String name, String value )
Creates a cookie with the given name, value and domain attribute.
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
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
Method Summary
int compare( Object o1, Object o2 )

Compares two cookies to determine order for cookie header.

boolean equals( Object obj )
Two cookies are equal if the name, path and domain match.
String getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
String getDomain()
Returns domain attribute of the cookie.
Date getExpiryDate()
Returns the expiration Date of the cookie, or null if none exists.
String getPath()
Returns the path attribute of the cookie
boolean getSecure()
No description provided.
int getVersion()
Returns the version of the cookie specification to which this cookie conforms.
int hashCode()
Returns a hash code in keeping with the hashCode() general hashCode contract.
boolean isDomainAttributeSpecified()
Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
boolean isExpired()
Returns true if this cookie has expired.
boolean isExpired( Date now )
Returns true if this cookie has expired according to the time passed in.
boolean isPathAttributeSpecified()
Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
boolean isPersistent()
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
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.
void setDomain( String domain )
Sets the domain attribute.
void setDomainAttributeSpecified( boolean value )
Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header.
void setExpiryDate( Date expiryDate )
Sets expiration date.
void setPath( String path )
Sets the path attribute.
void setPathAttributeSpecified( boolean value )
Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header.
void setSecure( boolean secure )
Sets the secure attribute of the cookie.
void setVersion( int version )
Sets the version of the cookie specification to which this cookie conforms.
String toExternalForm()
Return a textual representation of the cookie.
String toString()
Return a textual representation of the cookie.
Methods inherited from org.apache.commons.httpclientNameValuePair
Cookie
public Cookie ( )
Default constructor. Creates a blank cookie
Wiki javadoc Use textile entry format.
Add your comments here.
Cookie
public Cookie ( String domain, String name, String value )
Creates a cookie with the given name, value and domain attribute.
Parameters
TypeNameDescription
String domain the domain this cookie can be sent to
String name the cookie name
String value the cookie value
Wiki javadoc Use textile entry format.
Add your comments here.
Cookie
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
TypeNameDescription
String domain the domain this cookie can be sent to
String name the cookie name
String value the cookie value
String path the path prefix for which this cookie can be sent
Date expires the Date at which this cookie expires, or null if the cookie expires at the end of the session
boolean secure if true this cookie can only be sent over secure connections
Wiki javadoc Use textile entry format.
Add your comments here.
Cookie
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
TypeNameDescription
String domain the domain this cookie can be sent to
String name the cookie name
String value the cookie value
String path the path prefix for which this cookie can be sent
int 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.
boolean secure if true this cookie can only be sent over secure connections
Wiki javadoc Use textile entry format.
Add your comments here.
compare
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.

Implements method in Comparator
Parameters
TypeNameDescription
Object o1 The first object to be compared
Object o2 The second object to be compared
Wiki javadoc Use textile entry format.
Add your comments here.
equals
public boolean equals ( Object obj )
Two cookies are equal if the name, path and domain match.
Overrides method in NameValuePair
Parameters
TypeNameDescription
Object obj The object to compare against.
Wiki javadoc Use textile entry format.
Add your comments here.
getComment
public String getComment ( )
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
Wiki javadoc Use textile entry format.
Add your comments here.
getDomain
public String getDomain ( )
Returns domain attribute of the cookie.
Wiki javadoc Use textile entry format.
Add your comments here.
getExpiryDate
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.

Wiki javadoc Use textile entry format.
Add your comments here.
getPath
public String getPath ( )
Returns the path attribute of the cookie
See also
Wiki javadoc Use textile entry format.
Add your comments here.
getSecure
public boolean getSecure ( )
No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
getVersion
public int getVersion ( )
Returns the version of the cookie specification to which this cookie conforms.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
hashCode
public int hashCode ( )
Returns a hash code in keeping with the hashCode() general hashCode contract.
Overrides method in NameValuePair
Wiki javadoc Use textile entry format.
Add your comments here.
isDomainAttributeSpecified
public boolean isDomainAttributeSpecified ( )
Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
Wiki javadoc Use textile entry format.
Add your comments here.
isExpired
public boolean isExpired ( )
Returns true if this cookie has expired.
Wiki javadoc Use textile entry format.
Add your comments here.
isExpired
public boolean isExpired ( Date now )
Returns true if this cookie has expired according to the time passed in.
Parameters
TypeNameDescription
Date now The current time.
Wiki javadoc Use textile entry format.
Add your comments here.
isPathAttributeSpecified
public boolean isPathAttributeSpecified ( )
Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
Wiki javadoc Use textile entry format.
Add your comments here.
isPersistent
public boolean isPersistent ( )
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
Wiki javadoc Use textile entry format.
Add your comments here.
setComment
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.
Parameters
TypeNameDescription
String comment No description provided.
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setDomain
public void setDomain ( String domain )
Sets the domain attribute.
Parameters
TypeNameDescription
String domain The value of the domain attribute
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setDomainAttributeSpecified
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.
Parameters
TypeNameDescription
boolean value true if the cookie's domain was explicitly set, false otherwise.
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setExpiryDate
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.

Parameters
TypeNameDescription
Date expiryDate the Date after which this cookie is no longer valid.
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setPath
public void setPath ( String path )
Sets the path attribute.
Parameters
TypeNameDescription
String path The value of the path attribute
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setPathAttributeSpecified
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.
Parameters
TypeNameDescription
boolean value true if the cookie's path was explicitly set, false otherwise.
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
setSecure
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.

Parameters
TypeNameDescription
boolean secure The value of the secure attribute
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
setVersion
public void setVersion ( int version )
Sets the version of the cookie specification to which this cookie conforms.
Parameters
TypeNameDescription
int version the version of the cookie.
Returns void No description provided.
See also
Wiki javadoc Use textile entry format.
Add your comments here.
toExternalForm
public String toExternalForm ( )
Return a textual representation of the cookie.
Wiki javadoc Use textile entry format.
Add your comments here.
toString
public String toString ( )
Return a textual representation of the cookie.
Overrides method in NameValuePair
See also
Wiki javadoc Use textile entry format.
Add your comments here.