Package org.apache.http.impl.cookie
Class BasicClientCookie
java.lang.Object
org.apache.http.impl.cookie.BasicClientCookie
- All Implemented Interfaces:
Cloneable,ClientCookie,Cookie,SetCookie
- Direct Known Subclasses:
BasicClientCookie2
public class BasicClientCookie extends Object implements SetCookie, ClientCookie, Cloneable
HTTP "magic-cookie" represents a piece of state information
that the HTTP agent and the target server can exchange to maintain
a session.
- Version:
- $Revision: 659191 $
- Author:
- B.C. Holmes, Park, Sung-Gu, Doug Sale, Rod Waldhoff, dIon Gillard, Sean C. Sullivan, John Evans, Marc A. Saegesser, Oleg Kalnichevski, Mike Bowler
-
Field Summary
Fields inherited from interface org.apache.http.cookie.ClientCookie
COMMENT_ATTR, COMMENTURL_ATTR, DISCARD_ATTR, DOMAIN_ATTR, EXPIRES_ATTR, MAX_AGE_ATTR, PATH_ATTR, PORT_ATTR, SECURE_ATTR, VERSION_ATTR -
Constructor Summary
Constructors Constructor Description BasicClientCookie(String name, String value)Default Constructor taking a name and a value. -
Method Summary
Modifier and Type Method Description Objectclone()Creates and returns a copy of thisObject.booleancontainsAttribute(String name)StringgetAttribute(String name)StringgetComment()Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.StringgetCommentURL()Returns null.StringgetDomain()Returns domain attribute of the cookie.DategetExpiryDate()Returns the expirationDateof the cookie, or null if none exists.StringgetName()Returns the name.StringgetPath()Returns the path attribute of the cookieint[]getPorts()Returns null.StringgetValue()Returns the value.intgetVersion()Returns the version of the cookie specification to which this cookie conforms.booleanisExpired(Date date)Returns true if this cookie has expired.booleanisPersistent()Returns false if the cookie should be discarded at the end of the "session"; true otherwise.booleanisSecure()Indicates whether this cookie requires a secure connection.voidsetAttribute(String name, String value)voidsetComment(String comment)If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.voidsetDomain(String domain)Sets the domain attribute.voidsetExpiryDate(Date expiryDate)Sets expiration date.voidsetPath(String path)Sets the path attribute.voidsetSecure(boolean secure)Sets the secure attribute of the cookie.voidsetValue(String value)Sets the valuevoidsetVersion(int version)Sets the version of the cookie specification to which this cookie conforms.StringtoString()Returns a string containing a concise, human-readable description of this object.
-
Constructor Details
-
BasicClientCookie
Default Constructor taking a name and a value. The value may be null.- Parameters:
name- The name.value- The value.
-
-
Method Details
-
getName
Returns the name. -
getValue
Returns the value. -
setValue
Sets the value -
getComment
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.- Specified by:
getCommentin interfaceCookie- Returns:
- comment
- See Also:
setComment(String)
-
setComment
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.- Specified by:
setCommentin interfaceSetCookie- Parameters:
comment-- See Also:
getComment()
-
getCommentURL
Returns null. Cookies prior to RFC2965 do not set this attribute- Specified by:
getCommentURLin interfaceCookie
-
getExpiryDate
Returns the expirationDateof 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.
- Specified by:
getExpiryDatein interfaceCookie- Returns:
- Expiration
Date, or null. - See Also:
setExpiryDate(java.util.Date)
-
setExpiryDate
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.
- Specified by:
setExpiryDatein interfaceSetCookie- Parameters:
expiryDate- theDateafter which this cookie is no longer valid.- See Also:
getExpiryDate()
-
isPersistent
public boolean isPersistent()Returns false if the cookie should be discarded at the end of the "session"; true otherwise.- Specified by:
isPersistentin interfaceCookie- Returns:
- false if the cookie should be discarded at the end of the "session"; true otherwise
-
getDomain
Returns domain attribute of the cookie.- Specified by:
getDomainin interfaceCookie- Returns:
- the value of the domain attribute
- See Also:
setDomain(java.lang.String)
-
setDomain
Sets the domain attribute.- Specified by:
setDomainin interfaceSetCookie- Parameters:
domain- The value of the domain attribute- See Also:
getDomain()
-
getPath
Returns the path attribute of the cookie- Specified by:
getPathin interfaceCookie- Returns:
- The value of the path attribute.
- See Also:
setPath(java.lang.String)
-
setPath
Sets the path attribute. -
isSecure
public boolean isSecure()Description copied from interface:CookieIndicates whether this cookie requires a secure connection.- Specified by:
isSecurein interfaceCookie- Returns:
trueif this cookie should only be sent over secure connections.- See Also:
setSecure(boolean)
-
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.
- Specified by:
setSecurein interfaceSetCookie- Parameters:
secure- The value of the secure attribute- See Also:
isSecure()
-
getPorts
public int[] getPorts()Returns null. Cookies prior to RFC2965 do not set this attribute -
getVersion
public int getVersion()Returns the version of the cookie specification to which this cookie conforms.- Specified by:
getVersionin interfaceCookie- Returns:
- the version of the cookie.
- See Also:
setVersion(int)
-
setVersion
public void setVersion(int version)Sets the version of the cookie specification to which this cookie conforms.- Specified by:
setVersionin interfaceSetCookie- Parameters:
version- the version of the cookie.- See Also:
getVersion()
-
isExpired
Returns true if this cookie has expired. -
setAttribute
-
getAttribute
- Specified by:
getAttributein interfaceClientCookie
-
containsAttribute
- Specified by:
containsAttributein interfaceClientCookie
-
clone
Description copied from class:ObjectCreates and returns a copy of thisObject. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should callsuper.clone()to create the new instance and then create deep copies of the nested, mutable objects.- Overrides:
clonein classObject- Returns:
- a copy of this object.
- Throws:
CloneNotSupportedException- if this object's class does not implement theCloneableinterface.
-
toString
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-