Package jakarta.ws.rs.core
Class NewCookie
java.lang.Object
jakarta.ws.rs.core.Cookie
jakarta.ws.rs.core.NewCookie
Used to create a new HTTP cookie, transferred in a response.
- Since:
- 1.0
- Author:
- Paul Sandoz, Marc Hadley
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classJAX-RS abstractNewCookiebuilder class.static classJAX-RSNewCookiebuilder class.static enumThe available values for theSameSitecookie attribute.Nested classes/interfaces inherited from class jakarta.ws.rs.core.Cookie
Cookie.AbstractCookieBuilder<T extends Cookie.AbstractCookieBuilder<T>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSpecifies that the cookie expires with the current application/browser session.Fields inherited from class jakarta.ws.rs.core.Cookie
DEFAULT_VERSION -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.This constructor will be removed in a future version.Deprecated.This constructor will be removed in a future version.Deprecated.This constructor will be removed in a future version.NewCookie(Cookie cookie, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly, NewCookie.SameSite sameSite) Deprecated.This constructor will be removed in a future version.protectedNewCookie(NewCookie.AbstractNewCookieBuilder<?> builder) Create a new instance from the suppliedNewCookie.AbstractNewCookieBuilderinstance.Deprecated.This constructor will be removed in a future version.NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, boolean secure) Deprecated.This constructor will be removed in a future version.NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly) Deprecated.This constructor will be removed in a future version.NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly, NewCookie.SameSite sameSite) Deprecated.This constructor will be removed in a future version.NewCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure) Deprecated.This constructor will be removed in a future version.NewCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly) Deprecated.This constructor will be removed in a future version. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompare for equality.Get the comment associated with the cookie.Get the cookie expiry date.intGet the maximum age of the the cookie in seconds.Returns the value of theSameSiteattribute for this cookie ornullif the attribute is not set.inthashCode()Generate a hash code by hashing all of the properties.booleanReturnstrueif this cookie contains theHttpOnlyattribute.booleanisSecure()Whether the cookie will only be sent over a secure connection.toCookie()Obtain a new instance of aCookiewith the same name, value, path, domain and version as thisNewCookie.toString()Deprecated.The format of the toString() method is subject to change in a future version.static NewCookieDeprecated.This method will be removed in a future version.
-
Field Details
-
DEFAULT_MAX_AGE
public static final int DEFAULT_MAX_AGESpecifies that the cookie expires with the current application/browser session.- See Also:
-
-
Constructor Details
-
NewCookie
Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance.- Parameters:
name- the name of the cookie.value- the value of the cookie.- Throws:
IllegalArgumentException- if name isnull.
-
NewCookie
@Deprecated public NewCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance.- Parameters:
name- the name of the cookie.value- the value of the cookie.path- the URI path for which the cookie is valid.domain- the host domain for which the cookie is valid.comment- the comment.maxAge- the maximum age of the cookie in seconds.secure- specifies whether the cookie will only be sent over a secure connection.- Throws:
IllegalArgumentException- if name isnull.
-
NewCookie
@Deprecated public NewCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance.- Parameters:
name- the name of the cookie.value- the value of the cookie.path- the URI path for which the cookie is valid.domain- the host domain for which the cookie is valid.comment- the comment.maxAge- the maximum age of the cookie in seconds.secure- specifies whether the cookie will only be sent over a secure connection.httpOnly- iftruemake the cookie HTTP only, i.e. only visible as part of an HTTP request.- Throws:
IllegalArgumentException- if name isnull.- Since:
- 2.0
-
NewCookie
@Deprecated public NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, boolean secure) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.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 isnull.
-
NewCookie
@Deprecated public NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.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 secondsexpiry- the cookie expiry date.secure- specifies whether the cookie will only be sent over a secure connectionhttpOnly- iftruemake the cookie HTTP only, i.e. only visible as part of an HTTP request.- Throws:
IllegalArgumentException- if name isnull.- Since:
- 2.0
-
NewCookie
@Deprecated public NewCookie(String name, String value, String path, String domain, int version, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly, NewCookie.SameSite sameSite) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.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 secondsexpiry- the cookie expiry date.secure- specifies whether the cookie will only be sent over a secure connectionhttpOnly- iftruemake the cookie HTTP only, i.e. only visible as part of an HTTP request.sameSite- specifies the value of theSameSitecookie attribute- Throws:
IllegalArgumentException- if name isnull.- Since:
- 3.1
-
NewCookie
Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance copying the information in the supplied cookie.- Parameters:
cookie- the cookie to clone.- Throws:
IllegalArgumentException- if cookie isnull.
-
NewCookie
Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance supplementing the information in the supplied cookie.- Parameters:
cookie- the cookie to clone.comment- the comment.maxAge- the maximum age of the cookie in seconds.secure- specifies whether the cookie will only be sent over a secure connection.- Throws:
IllegalArgumentException- if cookie isnull.
-
NewCookie
@Deprecated public NewCookie(Cookie cookie, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance supplementing the information in the supplied cookie.- Parameters:
cookie- the cookie to clone.comment- the comment.maxAge- the maximum age of the cookie in seconds.expiry- the cookie expiry date.secure- specifies whether the cookie will only be sent over a secure connection.httpOnly- iftruemake the cookie HTTP only, i.e. only visible as part of an HTTP request.- Throws:
IllegalArgumentException- if cookie isnull.- Since:
- 2.0
-
NewCookie
@Deprecated public NewCookie(Cookie cookie, String comment, int maxAge, Date expiry, boolean secure, boolean httpOnly, NewCookie.SameSite sameSite) Deprecated.This constructor will be removed in a future version. Please useNewCookie.Builderinstead.Create a new instance supplementing the information in the supplied cookie.- Parameters:
cookie- the cookie to clone.comment- the comment.maxAge- the maximum age of the cookie in seconds.expiry- the cookie expiry date.secure- specifies whether the cookie will only be sent over a secure connection.httpOnly- iftruemake the cookie HTTP only, i.e. only visible as part of an HTTP request.sameSite- specifies the value of theSameSitecookie attribute- Throws:
IllegalArgumentException- if cookie isnull.- Since:
- 3.1
-
NewCookie
Create a new instance from the suppliedNewCookie.AbstractNewCookieBuilderinstance.- Parameters:
builder- the builder.- Throws:
IllegalArgumentException- ifbuilder.nameisnull.- Since:
- 3.1
-
-
Method Details
-
valueOf
Deprecated.This method will be removed in a future version. Please use RuntimeDelegate.getInstance().createHeaderDelegate(NewCookie.class).fromString(value) instead.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 isnull.
-
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-1indicates that the cookie will be discarded at the end of the browser/application session.Note that it is recommended to use
Max-Ageto control cookie expiration, however some browsers do not understandMax-Age, in which case settinggetExpiry()Expires} parameter may be necessary.- Returns:
- the maximum age in seconds.
- See Also:
-
getExpiry
Get the cookie expiry date. Cookies whose expiry date has passed are discarded. A cookie can be unset by setting a new cookie with an expiry date in the past, typically the lowest possible date that can be set.Note that it is recommended to use
Max-Ageto control cookie expiration, however some browsers do not understandMax-Age, in which case settingExpiresparameter may be necessary.- Returns:
- cookie expiry date or
nullif no expiry date was set. - Since:
- 2.0
- See Also:
-
isSecure
public boolean isSecure()Whether the cookie will only be sent over a secure connection. Defaults tofalse.- Returns:
trueif the cookie will only be sent over a secure connection,falseotherwise.
-
isHttpOnly
public boolean isHttpOnly()Returnstrueif this cookie contains theHttpOnlyattribute. This means that the cookie should not be accessible to scripting engines, like javascript.- Returns:
trueif this cookie should be considered http only,falseotherwise.- Since:
- 2.0
-
getSameSite
Returns the value of theSameSiteattribute for this cookie ornullif the attribute is not set. This attributes controls whether the cookie is sent with cross-origin requests, providing protection against cross-site request forgery.- Returns:
- the value of the
SameSitecookie attribute ornull. - Since:
- 3.1
-
toCookie
Obtain a new instance of aCookiewith 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 aCookiewill never compare equal to aNewCookie.- Returns:
- a
Cookie
-
toString
Deprecated.The format of the toString() method is subject to change in a future version. Please use RuntimeDelegate.getInstance().createHeaderDelegate(NewCookie.class).toString(value) instead if you rely on the format of this method.Convert the cookie to a string suitable for use as the value of the corresponding HTTP header. -
hashCode
public int hashCode()Generate a hash code by hashing all of the properties. -
equals
Compare for equality. UsetoCookie()to compare aNewCookieto aCookieconsidering only the common properties.
-