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
  • Constructor Details

    • BasicClientCookie

      public BasicClientCookie​(String name, String value)
      Default Constructor taking a name and a value. The value may be null.
      Parameters:
      name - The name.
      value - The value.
  • Method Details

    • getName

      public String getName()
      Returns the name.
      Specified by:
      getName in interface Cookie
      Returns:
      String name The name
    • getValue

      public String getValue()
      Returns the value.
      Specified by:
      getValue in interface Cookie
      Returns:
      String value The current value.
    • setValue

      public void setValue​(String value)
      Sets the value
      Specified by:
      setValue in interface SetCookie
      Parameters:
      value -
    • getComment

      public String getComment()
      Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
      Specified by:
      getComment in interface Cookie
      Returns:
      comment
      See Also:
      setComment(String)
    • 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.
      Specified by:
      setComment in interface SetCookie
      Parameters:
      comment -
      See Also:
      getComment()
    • getCommentURL

      public String getCommentURL()
      Returns null. Cookies prior to RFC2965 do not set this attribute
      Specified by:
      getCommentURL in interface Cookie
    • 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.

      Specified by:
      getExpiryDate in interface Cookie
      Returns:
      Expiration Date, or null.
      See Also:
      setExpiryDate(java.util.Date)
    • 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.

      Specified by:
      setExpiryDate in interface SetCookie
      Parameters:
      expiryDate - the Date after 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:
      isPersistent in interface Cookie
      Returns:
      false if the cookie should be discarded at the end of the "session"; true otherwise
    • getDomain

      public String getDomain()
      Returns domain attribute of the cookie.
      Specified by:
      getDomain in interface Cookie
      Returns:
      the value of the domain attribute
      See Also:
      setDomain(java.lang.String)
    • setDomain

      public void setDomain​(String domain)
      Sets the domain attribute.
      Specified by:
      setDomain in interface SetCookie
      Parameters:
      domain - The value of the domain attribute
      See Also:
      getDomain()
    • getPath

      public String getPath()
      Returns the path attribute of the cookie
      Specified by:
      getPath in interface Cookie
      Returns:
      The value of the path attribute.
      See Also:
      setPath(java.lang.String)
    • setPath

      public void setPath​(String path)
      Sets the path attribute.
      Specified by:
      setPath in interface SetCookie
      Parameters:
      path - The value of the path attribute
      See Also:
      getPath()
    • isSecure

      public boolean isSecure()
      Description copied from interface: Cookie
      Indicates whether this cookie requires a secure connection.
      Specified by:
      isSecure in interface Cookie
      Returns:
      true if 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:
      setSecure in interface SetCookie
      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
      Specified by:
      getPorts in interface Cookie
    • getVersion

      public int getVersion()
      Returns the version of the cookie specification to which this cookie conforms.
      Specified by:
      getVersion in interface Cookie
      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:
      setVersion in interface SetCookie
      Parameters:
      version - the version of the cookie.
      See Also:
      getVersion()
    • isExpired

      public boolean isExpired​(Date date)
      Returns true if this cookie has expired.
      Specified by:
      isExpired in interface Cookie
      Parameters:
      date - Current time
      Returns:
      true if the cookie has expired.
    • setAttribute

      public void setAttribute​(String name, String value)
    • getAttribute

      public String getAttribute​(String name)
      Specified by:
      getAttribute in interface ClientCookie
    • containsAttribute

      public boolean containsAttribute​(String name)
      Specified by:
      containsAttribute in interface ClientCookie
    • clone

      public Object clone() throws CloneNotSupportedException
      Description copied from class: Object
      Creates and returns a copy of this Object. 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 call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.
      Overrides:
      clone in class Object
      Returns:
      a copy of this object.
      Throws:
      CloneNotSupportedException - if this object's class does not implement the Cloneable interface.
    • toString

      public String toString()
      Description copied from class: Object
      Returns 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 toString method if you intend implementing your own toString method.

      Overrides:
      toString in class Object
      Returns:
      a printable representation of this object.