Top Description Fields Constructors Methods
javax.ws.rs.core

public Class NewCookie

extends Cookie
Class Inheritance
Imports
java.util.Date, javax.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

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>
private final Date
private final boolean
private final int
private final boolean
Inherited from javax.ws.rs.core.Cookie:
DEFAULT_VERSION

Constructor Summary

AccessConstructor and Description
public
NewCookie(String
the name of the cookie.
name
,
String
the value of the cookie.
value
)

Create a new instance.

public
NewCookie(String
the name of the cookie.
name
,
String
the value of the cookie.
value
,
String
the URI path for which the cookie is valid.
path
,
String
the host domain for which the cookie is valid.
domain
,
String
the comment.
comment
,
int
the maximum age of the cookie in seconds.
maxAge
,
boolean
specifies whether the cookie will only be sent over a secure connection.
secure
)

Create a new instance.

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

Create a new instance.

public
NewCookie(String
the name of the cookie
name
,
String
the value of the cookie
value
,
String
the URI path for which the cookie is valid
path
,
String
the host domain for which the cookie is valid
domain
,
int
the version of the specification to which the cookie complies
version
,
String
the comment
comment
,
int
the maximum age of the cookie in seconds
maxAge
,
boolean
specifies whether the cookie will only be sent over a secure connection
secure
)

Create a new instance.

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

Create a new instance.

public
NewCookie(Cookie
the cookie to clone.
cookie
)

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

public
NewCookie(Cookie
the cookie to clone.
cookie
,
String
the comment.
comment
,
int
the maximum age of the cookie in seconds.
maxAge
,
boolean
specifies whether the cookie will only be sent over a secure connection.
secure
)

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

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

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

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
(Object
the object to compare to
obj
)

Overrides javax.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 int

Returns:

the hash code.
hashCode
()

Overrides javax.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 javax.ws.rs.core.Cookie.toString.

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
(String
the cookie string.
value
)

Hides javax.ws.rs.core.Cookie.valueOf.

Creates a new instance of NewCookie by parsing the supplied string.
Inherited from javax.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
expiryback to summary
private final Date expiry
httpOnlyback to summary
private final boolean httpOnly
maxAgeback to summary
private final int maxAge
secureback to summary
private final boolean secure

Constructor Detail

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

Create a new instance.

Parameters
name:String

the name of the cookie.

value:String

the value of the cookie.

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

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.

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

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.

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

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

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

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.

Exceptions
IllegalArgumentException:
if name is null.
Since
2.0
NewCookieback to summary
public NewCookie(Cookie cookie)

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

Parameters
cookie:Cookie

the cookie to clone.

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

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.

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

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.

Exceptions
IllegalArgumentException:
if cookie is null.
Since
2.0

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides javax.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()
hashCodeback to summary
public int hashCode()

Overrides javax.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 javax.ws.rs.core.Cookie.toString.

Convert the cookie to a string suitable for use as the value of the corresponding HTTP header.

Returns:String

a stringified cookie.

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

Hides javax.ws.rs.core.Cookie.valueOf.

Creates a new instance of NewCookie by parsing the supplied string.

Parameters
value:String

the cookie string.

Returns:NewCookie

the newly created NewCookie.

Exceptions
IllegalArgumentException:
if the supplied string cannot be parsed or is null.