docs: public static String encodeURL(String url, SessionInfo info) {
          // could be /path/page#fragment?query
          // could be /page/page;session=existing#fragment?query
          // where fragment and query are both optional
  
          HttpSession session = info.getSession();
          if (null == session) {
              return url;
          }
          final String id = session.getId();
          final String target = info.getSessionConfig().getURLRewritingMarker();
          URLParser parser = new URLParser(url, target);
  
          StringBuilder sb = new StringBuilder();
          if (-1 != parser.idMarker) {
              // a session exists in the URL, overlay this ID
              sb.append(url);
              int start = parser.idMarker + target.length();
              if (start + 23 < url.length()) {
                  sb.replace(start, start + 23, id);
              } else {
                  // invalid length on existing session, just remove that
                  // TODO: what if a fragment or query string was after the
                  // invalid session data
                  sb.setLength(parser.idMarker);
                  sb.append(target).append(id);
              }
          } else {
              // add session data to the URL
              if (-1 != parser.fragmentMarker) {
                  // prepend it before the uri fragment
                  sb.append(url, 0, parser.fragmentMarker);
                  sb.append(target).append(id);
                  sb.append(url, parser.fragmentMarker, url.length());
              } else if (-1 != parser.queryMarker) {
                  // prepend it before the query data
                  sb.append(url, 0, parser.queryMarker);
                  sb.append(target).append(id);
                  sb.append(url, parser.queryMarker, url.length());
              } else {
                  // just a uri
                  sb.append(url).append(target).append(id);
              }
          }
          return sb.toString();
      }