code: public static String appendRedirectMessage(String outcomeUrl,
                                                 Message message,
                                                 HttpServletRequest request) {
          String key = addMessageToRedirect(message, request);
          if (!outcomeUrl.contains("?")) {
              outcomeUrl += "?";
          } else {
              outcomeUrl += "&";
          }
  
          int index = outcomeUrl.indexOf(REDIRECT_KEY);
  
          if (index > 0) {
              int start = index + REDIRECT_KEY.length() + 1;
              int end = outcomeUrl.indexOf("=", start);
              if (end < 0) {
                  end = outcomeUrl.length();
              }
              String value = outcomeUrl.substring(start, end);
              outcomeUrl = outcomeUrl.replace(REDIRECT_KEY + "=" + value,
                                              REDIRECT_KEY + "=" + key);
          } else {
              outcomeUrl += REDIRECT_KEY + "=" + key;
          }
  
          return outcomeUrl;
      }
docs: adds a redirect message and appends the redirect key to the outcomeUrl.
  If a redirect key already exists, it is replaced. replace redirect key if
  it exists in the outcomeUrl.
  
  @param outcomeUrl
  @param message
  @param request
  @return