Package javax.ws.rs.core
Class NewCookie
java.lang.Object
javax.ws.rs.core.Cookie
javax.ws.rs.core.NewCookie
Used to create a new HTTP cookie, transferred in a response.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
static final int
Specifies that the cookie expires with the current application/browser session.private static final RuntimeDelegate.HeaderDelegate
<NewCookie> private int
private boolean
Fields inherited from class javax.ws.rs.core.Cookie
DEFAULT_VERSION
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance.NewCookie
(String name, String value, String path, String domain, int version, String comment, int maxAge, boolean secure) Create a new instance.NewCookie
(String name, String value, String path, String domain, String comment, int maxAge, boolean secure) Create a new instance.Create a new instance copying the information in the supplied cookie.Create a new instance supplementing the information in the supplied cookie. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compare for equality.Get the comment associated with the cookie.int
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.toCookie()
Obtain a new instance of aCookie
with the same name, value, path, domain and version as thisNewCookie
.toString()
Convert the cookie to a string suitable for use as the value of the corresponding HTTP header.static NewCookie
Creates a new instance of NewCookie by parsing the supplied string.
-
Field Details
-
DEFAULT_MAX_AGE
public static final int DEFAULT_MAX_AGESpecifies that the cookie expires with the current application/browser session.- See Also:
-
delegate
-
comment
-
maxAge
private int maxAge -
secure
private boolean secure
-
-
Constructor Details
-
NewCookie
Create a new instance.- Parameters:
name
- the name of the cookievalue
- the value of the cookie- Throws:
IllegalArgumentException
- if name is null
-
NewCookie
public NewCookie(String name, String value, String path, String domain, 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:
IllegalArgumentException
- if name is null
-
NewCookie
public NewCookie(String name, String value, String path, String domain, int version, 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:
IllegalArgumentException
- if name is null
-
NewCookie
Create a new instance copying the information in the supplied cookie.- Parameters:
cookie
- the cookie to clone- Throws:
IllegalArgumentException
- if cookie is null
-
NewCookie
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:
IllegalArgumentException
- if cookie is null
-
-
Method Details
-
valueOf
Creates a new instance of NewCookie by parsing the supplied string.- Parameters:
value
- the cookie string- Returns:
- the newly created NewCookie
- Throws:
IllegalArgumentException
- if the supplied string cannot be parsed or is null
-
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
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
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
Compare for equality. UsetoCookie()
to compare aNewCookie
to aCookie
considering only the common properties.
-