public static void setForcedGroupsCookie(final HttpServletRequest request, final HttpServletResponse response, final Map<String, Integer> forceGroups) {
        //  don't overwrite with empty; this would be relevant in a race condition where there is a forceGroups request simultaneous with a non-forceGroups request
        if (forceGroups.isEmpty()) {
            return;
        }

        //  be sure to quote cookies because they have characters that are not allowed raw
        final StringBuilder sb = new StringBuilder(10*forceGroups.size());
        sb.append('"');
        for (final Iterator<Entry<String, Integer>> iterator = forceGroups.entrySet().iterator(); iterator.hasNext(); ) {
            final Entry<String, Integer> next = iterator.next();
            sb.append(next.getKey()).append(next.getValue());
            if (iterator.hasNext()) {
                sb.append(',');
            }
        }
        sb.append('"');

        final String contextPath = request.getContextPath();
        final String cookiePath;
        if (CharMatcher.WHITESPACE.matchesAllOf(Strings.nullToEmpty(contextPath))) {
            cookiePath = "/";
        } else {
            cookiePath = contextPath;
        }

        final Cookie cookie = new Cookie(FORCE_GROUPS_COOKIE_NAME, sb.toString());
        cookie.setPath(cookiePath);
        response.addCookie(cookie);
    }
public static void setForcedGroupsCookie ( final HttpServletRequest request , final HttpServletResponse response , final Map < String , Integer > forceGroups ) { if ( forceGroups . isEmpty ( ) ) { return ; } final StringBuilder sb = new StringBuilder ( 10 * forceGroups . size ( ) ) ; sb . append ( '"' ) ; for ( final Iterator < Entry < String , Integer > > iterator = forceGroups . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { final Entry < String , Integer > next = iterator . next ( ) ; sb . append ( next . getKey ( ) ) . append ( next . getValue ( ) ) ; if ( iterator . hasNext ( ) ) { sb . append ( ',' ) ; } } sb . append ( '"' ) ; final String contextPath = request . getContextPath ( ) ; final String cookiePath ; if ( CharMatcher . WHITESPACE . matchesAllOf ( Strings . nullToEmpty ( contextPath ) ) ) { cookiePath = "/" ; } else { cookiePath = contextPath ; } final Cookie cookie = new Cookie ( FORCE_GROUPS_COOKIE_NAME , sb . toString ( ) ) ; cookie . setPath ( cookiePath ) ; response . addCookie ( cookie ) ; }
Set a cookie that will be parsed by {@link #parseForcedGroups(HttpServletRequest)}.  Cookie expires at end of browser session
@param request request
@param response response
@param forceGroups parsed force groups