public class DefaultCookieSerializer extends Object implements CookieSerializer
CookieSerializerCookieSerializer.CookieValue| Constructor and Description |
|---|
DefaultCookieSerializer() |
| Modifier and Type | Method and Description |
|---|---|
List<String> |
readCookieValues(HttpServletRequest request)
Reads all the matching cookies from the
HttpServletRequest. |
void |
setCookieMaxAge(int cookieMaxAge)
Sets the maxAge property of the Cookie.
|
void |
setCookieName(String cookieName) |
void |
setCookiePath(String cookiePath)
Sets the path of the Cookie.
|
void |
setDomainName(String domainName)
Sets an explicit Domain Name.
|
void |
setDomainNamePattern(String domainNamePattern)
Sets a case insensitive pattern used to extract the domain name from the
ServletRequest.getServerName(). |
void |
setJvmRoute(String jvmRoute)
Used to identify which JVM to route to for session affinity.
|
void |
setUseHttpOnlyCookie(boolean useHttpOnlyCookie)
Sets if a Cookie marked as HTTP Only should be used.
|
void |
setUseSecureCookie(boolean useSecureCookie)
Sets if a Cookie marked as secure should be used.
|
void |
writeCookieValue(CookieSerializer.CookieValue cookieValue)
Writes a given
CookieSerializer.CookieValue to the provided
HttpServletResponse |
public List<String> readCookieValues(HttpServletRequest request)
CookieSerializerHttpServletRequest. The
result is a List since there can be multiple Cookie in a single
request with a matching name. For example, one Cookie may have a path of
/ and another of /context, but the path is not transmitted in the
request.readCookieValues in interface CookieSerializerrequest - the HttpServletRequest to read the cookie from. Cannot
be null.public void writeCookieValue(CookieSerializer.CookieValue cookieValue)
CookieSerializerCookieSerializer.CookieValue to the provided
HttpServletResponsewriteCookieValue in interface CookieSerializercookieValue - the CookieSerializer.CookieValue to write to
CookieSerializer.CookieValue.getResponse(). Cannot be null.public void setUseSecureCookie(boolean useSecureCookie)
ServletRequest.isSecure().useSecureCookie - determines if the cookie should be marked as secure.public void setUseHttpOnlyCookie(boolean useHttpOnlyCookie)
useHttpOnlyCookie - determines if the cookie should be marked as HTTP Only.public void setCookiePath(String cookiePath)
HttpServletRequest.cookiePath - the path of the Cookie. If null, the default of the context
path will be used.public void setCookieName(String cookieName)
public void setCookieMaxAge(int cookieMaxAge)
cookieMaxAge - the maxAge property of the Cookiepublic void setDomainName(String domainName)
domainName - the name of the domain to use. (i.e. "example.com")IllegalStateException - if the domainNamePattern is also setpublic void setDomainNamePattern(String domainNamePattern)
Sets a case insensitive pattern used to extract the domain name from the
ServletRequest.getServerName(). The pattern should provide a
single grouping that defines what the value is that should be matched.
User's should be careful not to output malicious characters like new
lines to prevent from things like
HTTP
Response Splitting.
If the pattern does not match, then no domain will be set. This is useful to ensure the domain is not set during development when localhost might be used.
An example value might be "^.+?\\.(\\w+\\.[a-z]+)$". For the given input, it would provide the following explicit domain (null means no domain name is set):
domainNamePattern - the case insensitive pattern to extract the domain name withIllegalStateException - if the domainName is also setpublic void setJvmRoute(String jvmRoute)
Used to identify which JVM to route to for session affinity. With some implementations (i.e. Redis) this provides no performance benefit. However, this can help with tracing logs of a particular user. This will ensure that the value of the cookie is formatted as
sessionId + "." jvmRoute
To use set a custom route on each JVM instance and setup a frontend proxy to forward all requests to the JVM based on the route.
jvmRoute - the JVM Route to use (i.e. "node01jvmA", "n01ja", etc)