oracle.adf.view.rich.remote

## Class CookieWrapper

- java.lang.Object
- - javax.servlet.http.Cookie
  - - oracle.adf.view.rich.remote.CookieWrapper

- All Implemented Interfaces:
    Serializable, Cloneable, org.apache.http.cookie.Cookie, org.apache.http.cookie.SetCookie, org.apache.http.cookie.SetCookie2

      public class CookieWrapper
      extends javax.servlet.http.Cookie
      implements org.apache.http.cookie.SetCookie2

  The RemoteApplicationFramework needs to use two cookie types on a regular basis. The first is the javax.servlet.http.Cookie which is required on the producer side in order to be served from some of our ServletWrappers. The second is the org.apache.http.cookie.SetCookie2 which is used by the Apache HttpComponents used to connect to the client from the producer. We often need to use these cookie types at different times and casting the cookies from one format to another is confusing.

  This class extends both the javax.servlet.http.Cookie and implements the org.apache.http.cookie.SetCookie2 interface and makes them serializable. There are copy constructors designed for either of these cookie types in order to create a new cookie wrapper that should have the capabilities of both. By using the CookieWrapper for all cookies in the RemoteApplication framework, we can ensure that our handling of cookies between these two frameworks is less error prone.

  Since:
    12.1.4.0
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CookieWrapper()`
    `CookieWrapper(javax.servlet.http.Cookie cookie)` Creates a new CookieWrapper based on a javax.servlet.http.Cookie.
    `CookieWrapper(org.apache.http.cookie.Cookie cookie)` Creates a new CookieWrapper based on org.apache.http.cookie
    `CookieWrapper(CookieWrapper cookie)` This is a copy constructor which creates a new CookieWrapper based on another CookieWrapper.
    `CookieWrapper(String name, String value)` Creates a new Cookie using a name and value pair

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `static CookieWrapper` | `createFromJsonObject(javax.json.JsonObject jocw)`
    `boolean` | `equals(Object object)` Checks to see whether these cookies are "functionally" equivalent by checking the equivalency of the object's "toString()" function which has all the relivant information.
    `String` | `getCommentURL()` Returns the comment URL.
    `Date` | `getExpiryDate()` Returns the expiration Date of the cookie, or `null` if none exists.
    `int` | `getMaxAge()` Computes the max age of this cookie based on the ExpiryDate compared to the local time.
    `String` | `getName()` Returns the name of the cookie.
    `int[]` | `getPorts()` Get the Port attribute.
    `int` | `hashCode()` Returns a hashcode based on name and value.
    `boolean` | `isExpired(Date date)` Returns `true` if this cookie is expired as of the procided date.
    `boolean` | `isPersistent()` Returns `false` if the cookie should be discarded at the end of the "session"; `true` otherwise.
    `boolean` | `isSecure()` Indicates whether this cookie requires a secure connection.
    `void` | `readExternal(ObjectInput in)` Reads the CookieWrapper from the input stream.
    `void` | `setCommentURL(String commentURL)` Sets the comment URL
    `void` | `setDiscard(boolean discard)` Set the Discard attribute.
    `void` | `setExpiryDate(Date expiryDate)` Sets the expiration Date of the cookie.
    `void` | `setMaxAge(int expiry)` Sets the cookie's max age in seconds ala the javax.servlet.http.Cookie spec.
    `void` | `setPorts(int[] ports)` Sets the Port attribute.
    `void` | `setSecure(boolean secure)` Sets whether this cookie requires a secure connection.
    `static javax.json.JsonObject` | `toJsonObject(CookieWrapper cw)`
    `String` | `toString()`
    `void` | `writeExternal(ObjectOutput out)` Writes the object to the output stream.

    - ### Methods inherited from class javax.servlet.http.Cookie

      `getComment, getDomain, getPath, getSecure, getValue, getVersion, isHttpOnly, setComment, setDomain, setHttpOnly, setPath, setValue, setVersion`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.http.cookie.SetCookie

      `setComment, setDomain, setPath, setValue, setVersion`

    - ### Methods inherited from interface org.apache.http.cookie.Cookie

      `getComment, getDomain, getPath, getValue, getVersion`

- - ### Constructor Detail

    - #### CookieWrapper

          public CookieWrapper()

    - #### CookieWrapper

          public CookieWrapper(String name,
                               String value)

      Creates a new Cookie using a name and value pair
      Parameters:
        `name` - The name of the Cookie
        `value` - The Cookie Value.

    - #### CookieWrapper

          public CookieWrapper(javax.servlet.http.Cookie cookie)

      Creates a new CookieWrapper based on a javax.servlet.http.Cookie.
      Parameters:
        `cookie` - A javax.servlet.http.Cookie

    - #### CookieWrapper

          public CookieWrapper(CookieWrapper cookie)

      This is a copy constructor which creates a new CookieWrapper based on another CookieWrapper.
      Parameters:
        `cookie` - A javax.servlet.http.Cookie

    - #### CookieWrapper

          public CookieWrapper(org.apache.http.cookie.Cookie cookie)

      Creates a new CookieWrapper based on org.apache.http.cookie
      Parameters:
        `cookie` - A javax.servlet.http.Cookie

  - ### Method Detail

    - #### getName

          public String getName()

      Returns the name of the cookie.
      Specified by:
        `getName` in interface `org.apache.http.cookie.Cookie`
      Overrides:
        `getName` in class `javax.servlet.http.Cookie`
      Returns:
        the name of the cookie

    - #### setCommentURL

          public void setCommentURL(String commentURL)

      Sets the comment URL
      Specified by:
        `setCommentURL` in interface `org.apache.http.cookie.SetCookie2`
      Parameters:
        `commentURL` - the URL for the comment.

    - #### getCommentURL

          public String getCommentURL()

      Returns the comment URL.
      Specified by:
        `getCommentURL` in interface `org.apache.http.cookie.Cookie`

    - #### setMaxAge

          public void setMaxAge(int expiry)

      Sets the cookie's max age in seconds ala the javax.servlet.http.Cookie spec. If the value specified is less then zero, this will be treated as a session cookie and the getExpiryDate method will also be set to return `null`.

      If the expiry is greater then zero, then the ExpiryDate will be computed from the current System time and saved accordingly.

      If the expiry is zero, then the ExpiryDate will be set to the current System time -1 milisecond to indicate the that cookie has already expired.

      Overrides:
        `setMaxAge` in class `javax.servlet.http.Cookie`
      Parameters:
        `expiry` - The delta time to use to add to system time for experation.

    - #### getMaxAge

          public int getMaxAge()

      Computes the max age of this cookie based on the ExpiryDate compared to the local time. If ExpiryDate is null, then the value returned will be -1. If the ExpiryDate has already passed, then the value returned will be 0.
      Overrides:
        `getMaxAge` in class `javax.servlet.http.Cookie`

    - #### setExpiryDate

          public void setExpiryDate(Date expiryDate)

      Sets the expiration Date of the cookie.
      Specified by:
        `setExpiryDate` in interface `org.apache.http.cookie.SetCookie`
      Parameters:
        `expiryDate` - the Date or `null` is this cookie has no expiration.

    - #### getExpiryDate

          public Date getExpiryDate()

      Returns the expiration Date of the cookie, or `null` if none exists.
      Specified by:
        `getExpiryDate` in interface `org.apache.http.cookie.Cookie`
      Returns:
        Expiration Date or `null`

    - #### 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 `org.apache.http.cookie.Cookie`
      Returns:
        a boolean whether this cookie should be persisted or not.

    - #### setPorts

          public void setPorts(int[] ports)

      Sets the Port attribute. It restricts the ports to which a cookie may be returned in a Cookie request header.
      Specified by:
        `setPorts` in interface `org.apache.http.cookie.SetCookie2`
      Parameters:
        `ports` - Array of ports values.

    - #### getPorts

          public int[] getPorts()

      Get the Port attribute. It restricts the ports to which a cookie may be returned in a Cookie request header.
      Specified by:
        `getPorts` in interface `org.apache.http.cookie.Cookie`
      Returns:
        an array of ports

    - #### setSecure

          public void setSecure(boolean secure)

      Sets whether this cookie requires a secure connection. This is almost always needed when the cookie contains "secure" information.
      Specified by:
        `setSecure` in interface `org.apache.http.cookie.SetCookie`
      Overrides:
        `setSecure` in class `javax.servlet.http.Cookie`
      Parameters:
        `secure` - value for security.

    - #### setDiscard

          public void setDiscard(boolean discard)

      Set the Discard attribute.

      Note: Discard attribute overrides Max-age.

      Specified by:
        `setDiscard` in interface `org.apache.http.cookie.SetCookie2`
      Parameters:
        `discard` - If the value should be discarded.

    - #### isSecure

          public boolean isSecure()

      Indicates whether this cookie requires a secure connection.
      Specified by:
        `isSecure` in interface `org.apache.http.cookie.Cookie`
      Returns:
        `true` if this cookie should only be sent over secure connections, `false` otherwise.

    - #### isExpired

          public boolean isExpired(Date date)

      Returns `true` if this cookie is expired as of the procided date.
      Specified by:
        `isExpired` in interface `org.apache.http.cookie.Cookie`
      Parameters:
        `date` - Current time
      Returns:
        `true` if the cookie has expired.
      Throws:
        `IllegalArgumentException` - is Date is null

    - #### hashCode

          public int hashCode()

      Returns a hashcode based on name and value.
      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object object)

      Checks to see whether these cookies are "functionally" equivalent by checking the equivalency of the object's "toString()" function which has all the relivant information. There are items like comments and such which may differ on functionally equivalent cookies.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `object` - The cookie object to be tested against.

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `javax.servlet.http.Cookie`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### writeExternal

          public void writeExternal(ObjectOutput out)
                             throws IOException

      Writes the object to the output stream. This is needed because the base cookie object is not serializable NOR does it have a default constructor. As such, standard serialization will not work. This method will ensure all fields are sent over the wire, including those from the parent class.
      Parameters:
        `out` - the ObjectOutput object
      Throws:
        `IOException` - if something goes wrong

    - #### readExternal

          public void readExternal(ObjectInput in)
                            throws IOException,
                                   ClassNotFoundException

      Reads the CookieWrapper from the input stream. This is needed because the base cookie object is not serializable NOR does it have a default constructor. As such, the base serialization needs to be done manually. This method will ensurte all field are received over the wire and set on the class, including those from the parent class.
      Parameters:
        `in` - the ObjectInput
      Throws:
        `IOException` - if something goes wrong with the IO
        `ClassNotFoundException` - if we have trouble recieving an object member field.

    - #### createFromJsonObject

          public static CookieWrapper createFromJsonObject(javax.json.JsonObject jocw)
                                                    throws ParseException

      Throws:
        `ParseException`

    - #### toJsonObject

          public static javax.json.JsonObject toJsonObject(CookieWrapper cw)

Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.