Class CookieBuilder


  • public final class CookieBuilder
    extends Object
    Class to collate all static cookie configuration data for building response cookies.
    • Method Detail

      • builder

        public static CookieBuilder builder​(JsonValue cookieConfig,
                                            String defaultName,
                                            String defaultPath)
        Create a CookieBuilder based on the JSON structure of:
         {
                "name"                    : Name of cookie. Defaults to {@literal defaultName}.
                "domain"                  : Domain that cookie is applicable to.
                "path"                    : Path to apply to the cookie. Defaults to {@literal defaultPath}.
                "secure"                  : Set to {@code true} if the cookie should be secure. Default is {@code false}.
                "httpOnly"                : Set to {@code true} if cookie should be httpOnly. Default is {@code true}.
                "sameSite"                : SameSite cookie configuration. Default is {@code null}.
               }
         
         
        Parameters:
        cookieConfig - The JSON containing the cookie details.
        defaultName - The cookie name to use if not defined in the cookieConfig.
        defaultPath - The cookie path to use if not defined in the cookieConfig.
        Returns:
        a CookieBuilder based on the values defined in the cookieConfig.
      • builder

        public static CookieBuilder builder​(String name)
        Create a CookieBuilder with just the cookie name set.
        Parameters:
        name - The name to use for the cookie name.
        Returns:
        a CookieBuilder with just the cookie name set.
      • getName

        public String getName()
        The name of the cookie that will be built from this CookieBuilder.
        Returns:
        the name of the cookie that will be built from this CookieBuilder.
      • domain

        public CookieBuilder domain​(String domain)
        Set the domain and return a new instance of this builder.
        Parameters:
        domain - the value of domain to use.
        Returns:
        a new instance of the builder
      • path

        public CookieBuilder path​(String path)
        Set the path and return a new instance of this builder.
        Parameters:
        path - the value of path to use.
        Returns:
        a new instance of the builder
      • secure

        public CookieBuilder secure​(boolean secure)
        Set the secure flag and return a new instance of this builder.
        Parameters:
        secure - true if secure cookies should be enabled or false otherwise.
        Returns:
        a new instance of the builder
      • httpOnly

        public CookieBuilder httpOnly​(boolean httpOnly)
        Set the httpOnly flag and return a new instance of this builder.
        Parameters:
        httpOnly - true if httpOnly cookies should be enabled or false otherwise.
        Returns:
        a new instance of the builder
      • sameSite

        public CookieBuilder sameSite​(Cookie.SameSite sameSite)
        Set the SameSite enum and return a new instance of this builder.
        Parameters:
        sameSite - LAX or STRICT.
        Returns:
        a new instance of the builder