Class CookieUtil


  • @ProviderType
    public class CookieUtil
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean addCookie​(javax.servlet.http.Cookie cookie, javax.servlet.http.HttpServletResponse response)
      Add the provided HTTP Cookie to the Response
      static int dropAllCookies​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String cookiePath)
      Removes all cookies for the domain
      static int dropCookies​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String cookiePath, String... cookieNames)
      Remove the named Cookies from Response
      static int dropCookiesByRegex​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String cookiePath, String... regexes)
      Remove the Cookies whose names match the provided Regex from Response
      static int dropCookiesByRegexArray​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String cookiePath, String[] regexes)
      Remove the Cookies whose names match the provided Regex from Response
      static boolean extendCookieLife​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String cookieName, String cookiePath, int expiry)
      Extend the cookie life.
      static javax.servlet.http.Cookie getCookie​(javax.servlet.http.HttpServletRequest request, String cookieName)
      Get the named cookie from the HTTP Request
      static List<javax.servlet.http.Cookie> getCookies​(javax.servlet.http.HttpServletRequest request, String regex)
      Gets Cookies from the Request whose names match the provides Regex
    • Method Detail

      • addCookie

        public static boolean addCookie​(javax.servlet.http.Cookie cookie,
                                        javax.servlet.http.HttpServletResponse response)
        Add the provided HTTP Cookie to the Response
        Parameters:
        cookie - Cookie to add
        response - Response to add Cookie to
        Returns:
        true unless cookie or response is null
      • getCookie

        public static javax.servlet.http.Cookie getCookie​(javax.servlet.http.HttpServletRequest request,
                                                          String cookieName)
        Get the named cookie from the HTTP Request
        Parameters:
        request - Request to get the Cookie from
        cookieName - name of Cookie to get
        Returns:
        the named Cookie, null if the named Cookie cannot be found
      • getCookies

        public static List<javax.servlet.http.Cookie> getCookies​(javax.servlet.http.HttpServletRequest request,
                                                                 String regex)
        Gets Cookies from the Request whose names match the provides Regex
        Parameters:
        request - Request to get the Cookie from
        regex - Regex to match against Cookie names
        Returns:
        Cookies which match the Regex
      • extendCookieLife

        public static boolean extendCookieLife​(javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response,
                                               String cookieName,
                                               String cookiePath,
                                               int expiry)

        Extend the cookie life.

        This can be used when a cookie should be valid for X minutes from the last point of activity.

        This method will leave expired or deleted cookies alone.

        Parameters:
        request - Request to get the Cookie from
        response - Response to write the extended Cookie to
        cookieName - Name of Cookie to extend the life of
        expiry - New Cookie expiry
      • dropCookies

        public static int dropCookies​(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response,
                                      String cookiePath,
                                      String... cookieNames)
        Remove the named Cookies from Response
        Parameters:
        request - Request to get the Cookies to drop
        response - Response to expire the Cookies on
        cookieNames - Names of cookies to drop
        Returns:
        Number of Cookies dropped
      • dropCookiesByRegex

        public static int dropCookiesByRegex​(javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response,
                                             String cookiePath,
                                             String... regexes)
        Remove the Cookies whose names match the provided Regex from Response
        Parameters:
        request - Request to get the Cookies to drop
        response - Response to expire the Cookies on
        regexes - Regex to find Cookies to drop
        Returns:
        Number of Cookies dropped
      • dropCookiesByRegexArray

        public static int dropCookiesByRegexArray​(javax.servlet.http.HttpServletRequest request,
                                                  javax.servlet.http.HttpServletResponse response,
                                                  String cookiePath,
                                                  String[] regexes)
        Remove the Cookies whose names match the provided Regex from Response
        Parameters:
        request - Request to get the Cookies to drop
        response - Response to expire the Cookies on
        regexes - Regex to find Cookies to drop
        Returns:
        Number of Cookies dropped
      • dropAllCookies

        public static int dropAllCookies​(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response,
                                         String cookiePath)
        Removes all cookies for the domain
        Parameters:
        request - Request to get the Cookies to drop
        response - Response to expire the Cookies on