public class CookieUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
JSESSIONID
session id cookie name
|
Constructor and Description |
---|
CookieUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
cookiePathFor(javax.servlet.http.HttpServletRequest httpServletRequest)
Get path for newly created cookie.
|
static javax.servlet.http.Cookie |
createConglomerateCookie(String cookieName,
Map<String,String> map,
javax.servlet.http.HttpServletRequest request) |
static javax.servlet.http.Cookie |
createCookie(String name,
String value,
javax.servlet.http.HttpServletRequest currentRequest)
Creat cookie with path reflecting the context path of currentRequest.
|
static String |
getCookieValue(String cookieName,
javax.servlet.http.HttpServletRequest currentRequest)
Get value of cookie with given cookieName from currentRequest, or
null ,
if the request does not have such cookie. |
static String |
getSingleSessionId(javax.servlet.http.Cookie[] cookies)
Gets the session id as a string from the given array of Cookie objects if only one
JSESSIONID cookie is
found. |
static boolean |
hasSessionId(javax.servlet.http.Cookie[] cookies)
Returns true if one or more cookies with name of
JSESSIONID is found. |
static Map<String,String> |
parseConglomerateCookie(String cookieName,
javax.servlet.http.HttpServletRequest currentRequest)
Parse the key/value pairs out of a conglomerate cookie.
|
static void |
setSessionCookie(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String sessionId)
Adds a new
JSESSIONID cookie to the HTTP response if the given sessionId is not null. |
public static final String JSESSIONID
public static String getSingleSessionId(javax.servlet.http.Cookie[] cookies)
JSESSIONID
cookie is
found. If none or more than one JSESSIONID
cookies are found, returns null.cookies
- the cookies.public static boolean hasSessionId(javax.servlet.http.Cookie[] cookies)
JSESSIONID
is found.cookies
- an array of Cookie objectspublic static void setSessionCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sessionId)
JSESSIONID
cookie to the HTTP response if the given sessionId is not null. No cookie is set
if given sessionId is null.request
- HTTP requestresponse
- HTTP responsesessionId
- session ID to set as a value of the cookiepublic static String cookiePathFor(javax.servlet.http.HttpServletRequest httpServletRequest)
httpServletRequest
- current requestpublic static javax.servlet.http.Cookie createCookie(String name, String value, javax.servlet.http.HttpServletRequest currentRequest)
name
- new cookie's namevalue
- new cookie's valuecurrentRequest
- current requestpublic static String getCookieValue(String cookieName, javax.servlet.http.HttpServletRequest currentRequest)
null
,
if the request does not have such cookie.cookieName
- name of the cookie to retrievecurrentRequest
- current requestnull
, if no cookie with such name existspublic static Map<String,String> parseConglomerateCookie(String cookieName, javax.servlet.http.HttpServletRequest currentRequest)
The returned map will not contain empty values (zero length strings: they are discarded).
cookieName
- the name of the cookiecurrentRequest
- current requestCopyright © 2002-2015 Atlassian. All Rights Reserved.