Package com.atlassian.jira.web.util
Class CookieUtils
java.lang.Object
com.atlassian.jira.web.util.CookieUtils
This class handles utility methods for managing HTTP cookies.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcookiePathFor(javax.servlet.http.HttpServletRequest httpServletRequest) Get path for newly created cookie.static javax.servlet.http.CookiecreateConglomerateCookie(String cookieName, Map<String, String> map, javax.servlet.http.HttpServletRequest request) static javax.servlet.http.CookiecreateCookie(String name, String value, javax.servlet.http.HttpServletRequest currentRequest) Creat cookie with path reflecting the context path of currentRequest.static StringgetCookieValue(String cookieName, javax.servlet.http.HttpServletRequest currentRequest) Get value of cookie with given cookieName from currentRequest, ornull, if the request does not have such cookie.static StringgetSingleSessionId(javax.servlet.http.Cookie[] cookies) Gets the session id as a string from the given array of Cookie objects if only oneJSESSIONIDcookie is found.static booleanhasSessionId(javax.servlet.http.Cookie[] cookies) Returns true if one or more cookies with name ofJSESSIONIDis found.parseConglomerateCookie(String cookieName, javax.servlet.http.HttpServletRequest currentRequest) Parse the key/value pairs out of a conglomerate cookie.static voidsetSessionCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sessionId) Adds a newJSESSIONIDcookie to the HTTP response if the given sessionId is not null.
-
Field Details
-
JSESSIONID
session id cookie name- See Also:
-
-
Constructor Details
-
CookieUtils
public CookieUtils()
-
-
Method Details
-
getSingleSessionId
Gets the session id as a string from the given array of Cookie objects if only oneJSESSIONIDcookie is found. If none or more than oneJSESSIONIDcookies are found, returns null.- Parameters:
cookies- the cookies.- Returns:
- session value if unique one is found.
-
hasSessionId
public static boolean hasSessionId(javax.servlet.http.Cookie[] cookies) Returns true if one or more cookies with name ofJSESSIONIDis found.- Parameters:
cookies- an array of Cookie objects- Returns:
- true if one or more sessionid cookies are found
-
setSessionCookie
public static void setSessionCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sessionId) Adds a newJSESSIONIDcookie to the HTTP response if the given sessionId is not null. No cookie is set if given sessionId is null.- Parameters:
request- HTTP requestresponse- HTTP responsesessionId- session ID to set as a value of the cookie
-
cookiePathFor
Get path for newly created cookie.- Parameters:
httpServletRequest- current request- Returns:
- cookie path reflecting the current request's path
-
createCookie
public 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.- Parameters:
name- new cookie's namevalue- new cookie's valuecurrentRequest- current request- Returns:
- new cookie
-
getCookieValue
public static String getCookieValue(String cookieName, javax.servlet.http.HttpServletRequest currentRequest) Get value of cookie with given cookieName from currentRequest, ornull, if the request does not have such cookie.- Parameters:
cookieName- name of the cookie to retrievecurrentRequest- current request- Returns:
- value of the cookie, or
null, if no cookie with such name exists
-
parseConglomerateCookie
public static Map<String,String> parseConglomerateCookie(String cookieName, javax.servlet.http.HttpServletRequest currentRequest) Parse the key/value pairs out of a conglomerate cookie.The returned map will not contain empty values (zero length strings: they are discarded).
- Parameters:
cookieName- the name of the cookiecurrentRequest- current request- Returns:
- the non-null map of key/value pairs
-
createConglomerateCookie
-