public class CookieGenerator
extends java.lang.Object
Can serve as base class for components that generate specific cookies, like CookieLocaleResolcer and CookieThemeResolver.
addCookie(HttpServletResponse, java.lang.String)
,
removeCookie(HttpServletResponse)
,
CookieLocaleResolver
,
CookieThemeResolver
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
cookieDomain |
private boolean |
cookieHttpOnly |
private java.lang.Integer |
cookieMaxAge |
private java.lang.String |
cookieName |
private java.lang.String |
cookiePath |
private boolean |
cookieSecure |
static int |
DEFAULT_COOKIE_MAX_AGE
Deprecated.
in favor of setting no max age value at all in such a case
|
static java.lang.String |
DEFAULT_COOKIE_PATH
Default path that cookies will be visible to: "/", i.e.
|
protected Log |
logger |
Constructor and Description |
---|
CookieGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(HttpServletResponse response,
java.lang.String cookieValue)
Add a cookie with the given value to the response,
using the cookie descriptor settings of this generator.
|
protected Cookie |
createCookie(java.lang.String cookieValue)
Create a cookie with the given value, using the cookie descriptor
settings of this generator (except for "cookieMaxAge").
|
java.lang.String |
getCookieDomain()
Return the domain for cookies created by this generator, if any.
|
java.lang.Integer |
getCookieMaxAge()
Return the maximum age for cookies created by this generator.
|
java.lang.String |
getCookieName()
Return the given name for cookies created by this generator.
|
java.lang.String |
getCookiePath()
Return the path for cookies created by this generator.
|
boolean |
isCookieHttpOnly()
Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
boolean |
isCookieSecure()
Return whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
void |
removeCookie(HttpServletResponse response)
Remove the cookie that this generator describes from the response.
|
void |
setCookieDomain(java.lang.String cookieDomain)
Use the given domain for cookies created by this generator.
|
void |
setCookieHttpOnly(boolean cookieHttpOnly)
Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
void |
setCookieMaxAge(java.lang.Integer cookieMaxAge)
Use the given maximum age (in seconds) for cookies created by this generator.
|
void |
setCookieName(java.lang.String cookieName)
Use the given name for cookies created by this generator.
|
void |
setCookiePath(java.lang.String cookiePath)
Use the given path for cookies created by this generator.
|
void |
setCookieSecure(boolean cookieSecure)
Set whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
public static final java.lang.String DEFAULT_COOKIE_PATH
@Deprecated public static final int DEFAULT_COOKIE_MAX_AGE
protected final Log logger
private java.lang.String cookieName
private java.lang.String cookieDomain
private java.lang.String cookiePath
private java.lang.Integer cookieMaxAge
private boolean cookieSecure
private boolean cookieHttpOnly
public void setCookieName(java.lang.String cookieName)
javax.servlet.http.Cookie#getName()
public java.lang.String getCookieName()
public void setCookieDomain(java.lang.String cookieDomain)
javax.servlet.http.Cookie#setDomain
public java.lang.String getCookieDomain()
public void setCookiePath(java.lang.String cookiePath)
javax.servlet.http.Cookie#setPath
public java.lang.String getCookiePath()
public void setCookieMaxAge(java.lang.Integer cookieMaxAge)
javax.servlet.http.Cookie#setMaxAge
public java.lang.Integer getCookieMaxAge()
public void setCookieSecure(boolean cookieSecure)
javax.servlet.http.Cookie#setSecure
public boolean isCookieSecure()
public void setCookieHttpOnly(boolean cookieHttpOnly)
Note that this feature is only available on Servlet 3.0 and higher.
javax.servlet.http.Cookie#setHttpOnly
public boolean isCookieHttpOnly()
public void addCookie(HttpServletResponse response, java.lang.String cookieValue)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to add the cookie tocookieValue
- the value of the cookie to addsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
,
setCookieMaxAge(java.lang.Integer)
public void removeCookie(HttpServletResponse response)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to remove the cookie fromsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
protected Cookie createCookie(java.lang.String cookieValue)
cookieValue
- the value of the cookie to cratesetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)