Top Description Inners Fields Constructors Methods
jakarta.ws.rs.core

public Class NewCookie

extends Cookie
Class Inheritance
Imports
java.util.Date, .Objects, jakarta.ws.rs.ext.RuntimeDelegate, .RuntimeDelegate.HeaderDelegate

Used to create a new HTTP cookie, transferred in a response.
Authors
Paul Sandoz, Marc Hadley
Since
1.0
See Also
IETF RFC 2109

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
NewCookie.AbstractNewCookieBuilder<
the current AbstractNewCookieBuilder type.
T extends NewCookie.AbstractNewCookieBuilder<T>
>

JAX-RS abstract NewCookie builder class.

public static class
NewCookie.Builder

JAX-RS NewCookie builder class.

public static enum
NewCookie.SameSite

The available values for the SameSite cookie attribute.

Field Summary

Modifier and TypeField and Description
private final String
public static final int
DEFAULT_MAX_AGE

Specifies that the cookie expires with the current application/browser session.

private static final RuntimeDelegate.HeaderDelegate<NewCookie>
DELEGATE

Deprecated This field will be removed in a future version. See https://github.com/jakartaee/rest/issues/607
private final Date
private final boolean
private final int
private final NewCookie.SameSite
private final boolean
Inherited from jakarta.ws.rs.core.Cookie:
DEFAULT_VERSION

Constructor Summary

AccessConstructor and Description
public
NewCookie(final String
the name of the cookie.
name
,
final String
the value of the cookie.
value
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final String
the name of the cookie.
name
,
final String
the value of the cookie.
value
,
final String
the URI path for which the cookie is valid.
path
,
final String
the host domain for which the cookie is valid.
domain
,
final String
the comment.
comment
,
final int
the maximum age of the cookie in seconds.
maxAge
,
final boolean
specifies whether the cookie will only be sent over a secure connection.
secure
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final String
the name of the cookie.
name
,
final String
the value of the cookie.
value
,
final String
the URI path for which the cookie is valid.
path
,
final String
the host domain for which the cookie is valid.
domain
,
final String
the comment.
comment
,
final int
the maximum age of the cookie in seconds.
maxAge
,
final boolean
specifies whether the cookie will only be sent over a secure connection.
secure
,
final boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final String
the name of the cookie
name
,
final String
the value of the cookie
value
,
final String
the URI path for which the cookie is valid
path
,
final String
the host domain for which the cookie is valid
domain
,
final int
the version of the specification to which the cookie complies
version
,
final String
the comment
comment
,
final int
the maximum age of the cookie in seconds
maxAge
,
final boolean
specifies whether the cookie will only be sent over a secure connection
secure
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final String
the name of the cookie
name
,
final String
the value of the cookie
value
,
final String
the URI path for which the cookie is valid
path
,
final String
the host domain for which the cookie is valid
domain
,
final int
the version of the specification to which the cookie complies
version
,
final String
the comment
comment
,
final int
the maximum age of the cookie in seconds
maxAge
,
final Date
the cookie expiry date.
expiry
,
final boolean
specifies whether the cookie will only be sent over a secure connection
secure
,
final boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final String
the name of the cookie
name
,
final String
the value of the cookie
value
,
final String
the URI path for which the cookie is valid
path
,
final String
the host domain for which the cookie is valid
domain
,
final int
the version of the specification to which the cookie complies
version
,
final String
the comment
comment
,
final int
the maximum age of the cookie in seconds
maxAge
,
final Date
the cookie expiry date.
expiry
,
final boolean
specifies whether the cookie will only be sent over a secure connection
secure
,
final boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
,
final NewCookie.SameSite
specifies the value of the SameSite cookie attribute
sameSite
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

public
NewCookie(final Cookie
the cookie to clone.
cookie
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance copying the information in the supplied cookie.

public
NewCookie(final Cookie
the cookie to clone.
cookie
,
final String
the comment.
comment
,
final int
the maximum age of the cookie in seconds.
maxAge
,
final boolean
specifies whether the cookie will only be sent over a secure connection.
secure
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

public
NewCookie(final Cookie
the cookie to clone.
cookie
,
final String
the comment.
comment
,
final int
the maximum age of the cookie in seconds.
maxAge
,
final Date
the cookie expiry date.
expiry
,
final boolean
specifies whether the cookie will only be sent over a secure connection.
secure
,
final boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

public
NewCookie(final Cookie
the cookie to clone.
cookie
,
final String
the comment.
comment
,
final int
the maximum age of the cookie in seconds.
maxAge
,
final Date
the cookie expiry date.
expiry
,
final boolean
specifies whether the cookie will only be sent over a secure connection.
secure
,
final boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
,
final NewCookie.SameSite
specifies the value of the SameSite cookie attribute
sameSite
)
Deprecated This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

protected
NewCookie(NewCookie.AbstractNewCookieBuilder<?>
the builder.
builder
)

Create a new instance from the supplied AbstractNewCookieBuilder instance.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the object is a NewCookie with the same value for all properties, false otherwise.
equals
(final Object
the object to compare to
obj
)

Overrides jakarta.ws.rs.core.Cookie.equals.

Compare for equality.

public String

Returns:

the comment or null if none set
getComment
()

Get the comment associated with the cookie.

public Date

Returns:

cookie expiry date or null if no expiry date was set.
getExpiry
()

Get the cookie expiry date.

public int

Returns:

the maximum age in seconds.
getMaxAge
()

Get the maximum age of the the cookie in seconds.

public NewCookie.SameSite

Returns:

the value of the SameSite cookie attribute or null.
getSameSite
()

Returns the value of the SameSite attribute for this cookie or null if the attribute is not set.

public int

Returns:

the hash code.
hashCode
()

Overrides jakarta.ws.rs.core.Cookie.hashCode.

Generate a hash code by hashing all of the properties.

public boolean

Returns:

true if this cookie should be considered http only, false otherwise.
isHttpOnly
()

Returns true if this cookie contains the HttpOnly attribute.

public boolean

Returns:

true if the cookie will only be sent over a secure connection, false otherwise.
isSecure
()

Whether the cookie will only be sent over a secure connection.

public Cookie

Returns:

a Cookie
toCookie
()

Obtain a new instance of a Cookie with the same name, value, path, domain and version as this NewCookie.

public String

Returns:

a stringified cookie.
toString
()

Overrides jakarta.ws.rs.core.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.

public static NewCookie

Returns:

the newly created NewCookie.
valueOf
(final String
the cookie string.
value
)

Hides jakarta.ws.rs.core.Cookie.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.

Inherited from jakarta.ws.rs.core.Cookie:
getDomaingetNamegetPathgetValuegetVersion

Field Detail

commentback to summary
private final String comment
DEFAULT_MAX_AGEback to summary
public static final int DEFAULT_MAX_AGE

Specifies that the cookie expires with the current application/browser session.

DELEGATEback to summary
private static final RuntimeDelegate.HeaderDelegate<NewCookie> DELEGATE

Deprecated

This field will be removed in a future version. See https://github.com/jakartaee/rest/issues/607

Annotations
@Deprecated
expiryback to summary
private final Date expiry
httpOnlyback to summary
private final boolean httpOnly
maxAgeback to summary
private final int maxAge
sameSiteback to summary
private final NewCookie.SameSite sameSite
secureback to summary
private final boolean secure

Constructor Detail

NewCookieback to summary
public NewCookie(final String name, final String value)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie.

value:String

the value of the cookie.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
NewCookieback to summary
public NewCookie(final String name, final String value, final String path, final String domain, final String comment, final int maxAge, final boolean secure)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie.

value:String

the value of the cookie.

path:String

the URI path for which the cookie is valid.

domain:String

the host domain for which the cookie is valid.

comment:String

the comment.

maxAge:int

the maximum age of the cookie in seconds.

secure:boolean

specifies whether the cookie will only be sent over a secure connection.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
NewCookieback to summary
public NewCookie(final String name, final String value, final String path, final String domain, final String comment, final int maxAge, final boolean secure, final boolean httpOnly)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie.

value:String

the value of the cookie.

path:String

the URI path for which the cookie is valid.

domain:String

the host domain for which the cookie is valid.

comment:String

the comment.

maxAge:int

the maximum age of the cookie in seconds.

secure:boolean

specifies whether the cookie will only be sent over a secure connection.

httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
Since
2.0
NewCookieback to summary
public NewCookie(final String name, final String value, final String path, final String domain, final int version, final String comment, final int maxAge, final boolean secure)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie

value:String

the value of the cookie

path:String

the URI path for which the cookie is valid

domain:String

the host domain for which the cookie is valid

version:int

the version of the specification to which the cookie complies

comment:String

the comment

maxAge:int

the maximum age of the cookie in seconds

secure:boolean

specifies whether the cookie will only be sent over a secure connection

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
NewCookieback to summary
public NewCookie(final String name, final String value, final String path, final String domain, final int version, final String comment, final int maxAge, final Date expiry, final boolean secure, final boolean httpOnly)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie

value:String

the value of the cookie

path:String

the URI path for which the cookie is valid

domain:String

the host domain for which the cookie is valid

version:int

the version of the specification to which the cookie complies

comment:String

the comment

maxAge:int

the maximum age of the cookie in seconds

expiry:Date

the cookie expiry date.

secure:boolean

specifies whether the cookie will only be sent over a secure connection

httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
Since
2.0
NewCookieback to summary
public NewCookie(final String name, final String value, final String path, final String domain, final int version, final String comment, final int maxAge, final Date expiry, final boolean secure, final boolean httpOnly, final NewCookie.SameSite sameSite)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance.

Parameters
name:String

the name of the cookie

value:String

the value of the cookie

path:String

the URI path for which the cookie is valid

domain:String

the host domain for which the cookie is valid

version:int

the version of the specification to which the cookie complies

comment:String

the comment

maxAge:int

the maximum age of the cookie in seconds

expiry:Date

the cookie expiry date.

secure:boolean

specifies whether the cookie will only be sent over a secure connection

httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

sameSite:NewCookie.SameSite

specifies the value of the SameSite cookie attribute

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if name is null.
Since
3.1
NewCookieback to summary
public NewCookie(final Cookie cookie)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance copying the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if cookie is null.
NewCookieback to summary
public NewCookie(final Cookie cookie, final String comment, final int maxAge, final boolean secure)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

comment:String

the comment.

maxAge:int

the maximum age of the cookie in seconds.

secure:boolean

specifies whether the cookie will only be sent over a secure connection.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if cookie is null.
NewCookieback to summary
public NewCookie(final Cookie cookie, final String comment, final int maxAge, final Date expiry, final boolean secure, final boolean httpOnly)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

comment:String

the comment.

maxAge:int

the maximum age of the cookie in seconds.

expiry:Date

the cookie expiry date.

secure:boolean

specifies whether the cookie will only be sent over a secure connection.

httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if cookie is null.
Since
2.0
NewCookieback to summary
public NewCookie(final Cookie cookie, final String comment, final int maxAge, final Date expiry, final boolean secure, final boolean httpOnly, final NewCookie.SameSite sameSite)

Deprecated

This constructor will be removed in a future version. Please use NewCookie.Builder instead.

Create a new instance supplementing the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

comment:String

the comment.

maxAge:int

the maximum age of the cookie in seconds.

expiry:Date

the cookie expiry date.

secure:boolean

specifies whether the cookie will only be sent over a secure connection.

httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

sameSite:NewCookie.SameSite

specifies the value of the SameSite cookie attribute

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if cookie is null.
Since
3.1
NewCookieback to summary
protected NewCookie(NewCookie.AbstractNewCookieBuilder<?> builder)

Create a new instance from the supplied AbstractNewCookieBuilder instance.

Parameters
builder:NewCookie.AbstractNewCookieBuilder<?>

the builder.

Exceptions
IllegalArgumentException:
if builder.name is null.
Since
3.1

Method Detail

equalsback to summary
public boolean equals(final Object obj)

Overrides jakarta.ws.rs.core.Cookie.equals.

Compare for equality. Use toCookie() to compare a NewCookie to a Cookie considering only the common properties.

Parameters
obj:Object

the object to compare to

Returns:boolean

true if the object is a NewCookie with the same value for all properties, false otherwise.

Annotations
@SuppressWarnings:StringEquality, RedundantIfStatement
@Override
getCommentback to summary
public String getComment()

Get the comment associated with the cookie.

Returns:String

the comment or null if none set

getExpiryback to summary
public Date 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-Age to control cookie expiration, however some browsers do not understand Max-Age, in which case setting Expires parameter may be necessary.

Returns:Date

cookie expiry date or null if no expiry date was set.

Since
2.0
See Also
getMaxAge()
getMaxAgeback to summary
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.

Note that it is recommended to use Max-Age to control cookie expiration, however some browsers do not understand Max-Age, in which case setting getExpiry() Expires} parameter may be necessary.

Returns:int

the maximum age in seconds.

See Also
getExpiry()
getSameSiteback to summary
public NewCookie.SameSite getSameSite()

Returns the value of the SameSite attribute for this cookie or null if 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:NewCookie.SameSite

the value of the SameSite cookie attribute or null.

Since
3.1
hashCodeback to summary
public int hashCode()

Overrides jakarta.ws.rs.core.Cookie.hashCode.

Generate a hash code by hashing all of the properties.

Returns:int

the hash code.

Annotations
@Override
isHttpOnlyback to summary
public boolean isHttpOnly()

Returns true if this cookie contains the HttpOnly attribute. This means that the cookie should not be accessible to scripting engines, like javascript.

Returns:boolean

true if this cookie should be considered http only, false otherwise.

Since
2.0
isSecureback to summary
public boolean isSecure()

Whether the cookie will only be sent over a secure connection. Defaults to false.

Returns:boolean

true if the cookie will only be sent over a secure connection, false otherwise.

toCookieback to summary
public Cookie toCookie()

Obtain a new instance of a Cookie with the same name, value, path, domain and version as this NewCookie. This method can be used to obtain an object that can be compared for equality with another Cookie; since a Cookie will never compare equal to a NewCookie.

Returns:Cookie

a Cookie

toStringback to summary
public String toString()

Overrides jakarta.ws.rs.core.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.

Returns:String

a stringified cookie.

Annotations
@Override
@Deprecated
valueOfback to summary
public static NewCookie valueOf(final String value)

Hides jakarta.ws.rs.core.Cookie.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:String

the cookie string.

Returns:NewCookie

the newly created NewCookie.

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if the supplied string cannot be parsed or is null.
jakarta.ws.rs.core back to summary

public abstract Class NewCookie.AbstractNewCookieBuilder<T extends NewCookie.AbstractNewCookieBuilder<T>>

extends Cookie.AbstractCookieBuilder<NewCookie.AbstractNewCookieBuilder<T extends NewCookie.AbstractNewCookieBuilder<T>>>
Class Inheritance
Known Direct Subclasses
jakarta.ws.rs.core.NewCookie.Builder
Type Parameters
<T>
the current AbstractNewCookieBuilder type.

JAX-RS abstract NewCookie builder class.
Since
3.1

Field Summary

Modifier and TypeField and Description
private String
private Date
private boolean
private int
private NewCookie.SameSite
private boolean

Constructor Summary

AccessConstructor and Description
public
AbstractNewCookieBuilder(String
the name of the cookie.
name
)

Create a new instance.

public
AbstractNewCookieBuilder(Cookie
the cookie to clone.
cookie
)

Create a new instance supplementing the information in the supplied cookie.

Method Summary

Modifier and TypeMethod and Description
public abstract NewCookie

Returns:

a new NewCookie instance.
build
()

Implements abstract jakarta.ws.rs.core.Cookie.AbstractCookieBuilder.build.

Build a new NewCookie instance using all the configuration previously specified in this builder.

public T

Returns:

the updated builder instance.
comment
(String
the comment.
comment
)

Set the comment associated with the cookie.

public T

Returns:

the updated builder instance.
expiry
(Date
the cookie expiry date
expiry
)

Set the cookie expiry date.

public T

Returns:

the updated builder instance.
httpOnly
(boolean
if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.
httpOnly
)

Whether the cookie will only be visible as part of an HTTP request.

public T

Returns:

the updated builder instance.
maxAge
(int
the maximum age in seconds.
maxAge
)

Set the maximum age of the the cookie in seconds.

public T

Returns:

the updated builder instance.
sameSite
(NewCookie.SameSite
specifies the value of the SameSite cookie attribute.
sameSite
)

Set the attribute that controls whether the cookie is sent with cross-origin requests, providing protection against cross-site request forgery.

public T

Returns:

the updated builder instance.
secure
(boolean
specifies whether the cookie will only be sent over a secure connection.
secure
)

Whether the cookie will only be sent over a secure connection.

private T
Inherited from jakarta.ws.rs.core.Cookie.AbstractCookieBuilder:
domainpathvalueversion

Field Detail

commentback to summary
private String comment
expiryback to summary
private Date expiry
httpOnlyback to summary
private boolean httpOnly
maxAgeback to summary
private int maxAge
sameSiteback to summary
private NewCookie.SameSite sameSite
secureback to summary
private boolean secure

Constructor Detail

AbstractNewCookieBuilderback to summary
public AbstractNewCookieBuilder(String name)

Create a new instance.

Parameters
name:String

the name of the cookie.

AbstractNewCookieBuilderback to summary
public AbstractNewCookieBuilder(Cookie cookie)

Create a new instance supplementing the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

Method Detail

buildback to summary
public abstract NewCookie build()

Implements abstract jakarta.ws.rs.core.Cookie.AbstractCookieBuilder.build.

Build a new NewCookie instance using all the configuration previously specified in this builder.

Returns:NewCookie

a new NewCookie instance.

Annotations
@Override
Exceptions
IllegalArgumentException:
if name is null.
commentback to summary
public T comment(String comment)

Set the comment associated with the cookie.

Parameters
comment:String

the comment.

Returns:T

the updated builder instance.

expiryback to summary
public T expiry(Date expiry)

Set 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-Age to control cookie expiration, however some browsers do not understand Max-Age, in which case setting Expires parameter may be necessary.

Parameters
expiry:Date

the cookie expiry date

Returns:T

the updated builder instance.

See Also
maxAge(int)
httpOnlyback to summary
public T httpOnly(boolean httpOnly)

Whether the cookie will only be visible as part of an HTTP request. Defaults to false.

Parameters
httpOnly:boolean

if true make the cookie HTTP only, i.e. only visible as part of an HTTP request.

Returns:T

the updated builder instance.

maxAgeback to summary
public T maxAge(int maxAge)

Set 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.

Parameters
maxAge:int

the maximum age in seconds.

Returns:T

the updated builder instance.

See Also
expiry(Date)
sameSiteback to summary
public T sameSite(NewCookie.SameSite sameSite)

Set the attribute that controls whether the cookie is sent with cross-origin requests, providing protection against cross-site request forgery.

Parameters
sameSite:NewCookie.SameSite

specifies the value of the SameSite cookie attribute.

Returns:T

the updated builder instance.

secureback to summary
public T secure(boolean secure)

Whether the cookie will only be sent over a secure connection. Defaults to false.

Parameters
secure:boolean

specifies whether the cookie will only be sent over a secure connection.

Returns:T

the updated builder instance.

selfback to summary
private T self()

Hides jakarta.ws.rs.core.Cookie.AbstractCookieBuilder.self.

Annotations
@SuppressWarnings:unchecked
jakarta.ws.rs.core back to summary

public Class NewCookie.Builder

extends NewCookie.AbstractNewCookieBuilder<NewCookie.Builder>
Class Inheritance

JAX-RS NewCookie builder class.

New Cookie builder provides methods that let you conveniently configure and subsequently build a new NewCookie instance.

For example:
NewCookie cookie = new NewCookie.Builder("name")
        .path("/")
        .domain("domain.com")
        .sameSite(SameSite.LAX)
        .build();
Since
3.1

Constructor Summary

AccessConstructor and Description
public
Builder(String
the name of the cookie.
name
)

Create a new instance.

public
Builder(Cookie
the cookie to clone.
cookie
)

Create a new instance supplementing the information in the supplied cookie.

Method Summary

Modifier and TypeMethod and Description
public NewCookie
build()

Implements abstract jakarta.ws.rs.core.NewCookie.AbstractNewCookieBuilder.build.

Build a new NewCookie instance using all the configuration previously specified in this builder.

Inherited from jakarta.ws.rs.core.NewCookie.AbstractNewCookieBuilder:
commentexpiryhttpOnlymaxAgesameSitesecure

Constructor Detail

Builderback to summary
public Builder(String name)

Create a new instance.

Parameters
name:String

the name of the cookie.

Builderback to summary
public Builder(Cookie cookie)

Create a new instance supplementing the information in the supplied cookie.

Parameters
cookie:Cookie

the cookie to clone.

Method Detail

buildback to summary
public NewCookie build()

Implements abstract jakarta.ws.rs.core.NewCookie.AbstractNewCookieBuilder.build.

Doc from jakarta.ws.rs.core.NewCookie.AbstractNewCookieBuilder.build.

Build a new NewCookie instance using all the configuration previously specified in this builder.

Returns:NewCookie

a new NewCookie instance.

Annotations
@Override
jakarta.ws.rs.core back to summary

public final Enum NewCookie.SameSite

extends Enum<NewCookie.SameSite>
Class Inheritance

The available values for the SameSite cookie attribute.
Since
3.1

Field Summary

Modifier and TypeField and Description
public static final NewCookie.SameSite
LAX

The Lax mode only allows to send cookies for cross-site top level navigation requests.

public static final NewCookie.SameSite
NONE

The None mode disables protection provided by the SameSite cookie attribute.

public static final NewCookie.SameSite
STRICT

The Strict mode prevents clients from sending cookies with any cross-site request.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NewCookie.SameSite
public static NewCookie.SameSite[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LAXback to summary
public static final NewCookie.SameSite LAX

The Lax mode only allows to send cookies for cross-site top level navigation requests.

NONEback to summary
public static final NewCookie.SameSite NONE

The None mode disables protection provided by the SameSite cookie attribute.

STRICTback to summary
public static final NewCookie.SameSite STRICT

The Strict mode prevents clients from sending cookies with any cross-site request.

Constructor Detail

SameSiteback to summary
private SameSite()

Method Detail

valueOfback to summary
public static NewCookie.SameSite valueOf(String name)
valuesback to summary
public static NewCookie.SameSite[] values()