Package javax.ws.rs.core
Class NewCookie
- java.lang.Object
-
- javax.ws.rs.core.Cookie
-
- javax.ws.rs.core.NewCookie
-
public class NewCookie extends Cookie
Used to create a new HTTP cookie, transferred in a response.- See Also:
- IETF RFC 2109
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
comment
static int
DEFAULT_MAX_AGE
Specifies that the cookie expires with the current application/browser session.private static RuntimeDelegate.HeaderDelegate<NewCookie>
delegate
private int
maxAge
private boolean
secure
-
Fields inherited from class javax.ws.rs.core.Cookie
DEFAULT_VERSION
-
-
Constructor Summary
Constructors Constructor Description NewCookie(java.lang.String name, java.lang.String value)
Create a new instance.NewCookie(java.lang.String name, java.lang.String value, java.lang.String path, java.lang.String domain, int version, java.lang.String comment, int maxAge, boolean secure)
Create a new instance.NewCookie(java.lang.String name, java.lang.String value, java.lang.String path, java.lang.String domain, java.lang.String comment, int maxAge, boolean secure)
Create a new instance.NewCookie(Cookie cookie)
Create a new instance copying the information in the supplied cookie.NewCookie(Cookie cookie, java.lang.String comment, int maxAge, boolean secure)
Create a new instance supplementing the information in the supplied cookie.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Compare for equality.java.lang.String
getComment()
Get the comment associated with the cookie.int
getMaxAge()
Get the maximum age of the the cookie in seconds.int
hashCode()
Generate a hashcode by hashing all of the propertiesboolean
isSecure()
Whether the cookie will only be sent over a secure connection.Cookie
toCookie()
Obtain a new instance of aCookie
with the same name, value, path, domain and version as thisNewCookie
.java.lang.String
toString()
Convert the cookie to a string suitable for use as the value of the corresponding HTTP header.static NewCookie
valueOf(java.lang.String value)
Creates a new instance of NewCookie by parsing the supplied string.
-
-
-
Field Detail
-
DEFAULT_MAX_AGE
public static final int DEFAULT_MAX_AGE
Specifies that the cookie expires with the current application/browser session.- See Also:
- Constant Field Values
-
delegate
private static final RuntimeDelegate.HeaderDelegate<NewCookie> delegate
-
comment
private java.lang.String comment
-
maxAge
private int maxAge
-
secure
private boolean secure
-
-
Constructor Detail
-
NewCookie
public NewCookie(java.lang.String name, java.lang.String value)
Create a new instance.- Parameters:
name
- the name of the cookievalue
- the value of the cookie- Throws:
java.lang.IllegalArgumentException
- if name is null
-
NewCookie
public NewCookie(java.lang.String name, java.lang.String value, java.lang.String path, java.lang.String domain, java.lang.String comment, int maxAge, boolean secure)
Create a new instance.- Parameters:
name
- the name of the cookievalue
- the value of the cookiepath
- the URI path for which the cookie is validdomain
- the host domain for which the cookie is validcomment
- the commentmaxAge
- the maximum age of the cookie in secondssecure
- specifies whether the cookie will only be sent over a secure connection- Throws:
java.lang.IllegalArgumentException
- if name is null
-
NewCookie
public NewCookie(java.lang.String name, java.lang.String value, java.lang.String path, java.lang.String domain, int version, java.lang.String comment, int maxAge, boolean secure)
Create a new instance.- Parameters:
name
- the name of the cookievalue
- the value of the cookiepath
- the URI path for which the cookie is validdomain
- the host domain for which the cookie is validversion
- the version of the specification to which the cookie compliescomment
- the commentmaxAge
- the maximum age of the cookie in secondssecure
- specifies whether the cookie will only be sent over a secure connection- Throws:
java.lang.IllegalArgumentException
- if name is null
-
NewCookie
public NewCookie(Cookie cookie)
Create a new instance copying the information in the supplied cookie.- Parameters:
cookie
- the cookie to clone- Throws:
java.lang.IllegalArgumentException
- if cookie is null
-
NewCookie
public NewCookie(Cookie cookie, java.lang.String comment, int maxAge, boolean secure)
Create a new instance supplementing the information in the supplied cookie.- Parameters:
cookie
- the cookie to clonecomment
- the commentmaxAge
- the maximum age of the cookie in secondssecure
- specifies whether the cookie will only be sent over a secure connection- Throws:
java.lang.IllegalArgumentException
- if cookie is null
-
-
Method Detail
-
valueOf
public static NewCookie valueOf(java.lang.String value) throws java.lang.IllegalArgumentException
Creates a new instance of NewCookie by parsing the supplied string.- Parameters:
value
- the cookie string- Returns:
- the newly created NewCookie
- Throws:
java.lang.IllegalArgumentException
- if the supplied string cannot be parsed or is null
-
getComment
public java.lang.String getComment()
Get the comment associated with the cookie.- Returns:
- the comment or null if none set
-
getMaxAge
public int getMaxAge()
Get the maximum age of the the cookie in seconds. Cookies older than the maximum age are discarded. A cookie can be unset by sending a new cookie with maximum age of 0 since it will overwrite any existing cookie and then be immediately discarded. The default value of -1 indicates that the cookie will be discarded at the end of the browser/application session.- Returns:
- the maximum age in seconds
-
isSecure
public boolean isSecure()
Whether the cookie will only be sent over a secure connection. Defaults to false.- Returns:
- true if the cookie will only be sent over a secure connection, false otherwise.
-
toCookie
public Cookie toCookie()
Obtain a new instance of aCookie
with the same name, value, path, domain and version as thisNewCookie
. This method can be used to obtain an object that can be compared for equality with anotherCookie
; since aCookie
will never compare equal to aNewCookie
.- Returns:
- a
Cookie
-
toString
public java.lang.String toString()
Convert the cookie to a string suitable for use as the value of the corresponding HTTP header.
-
hashCode
public int hashCode()
Generate a hashcode by hashing all of the properties
-
equals
public boolean equals(java.lang.Object obj)
Compare for equality. UsetoCookie()
to compare aNewCookie
to aCookie
considering only the common properties.
-
-