private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) {
        List<String> values = headers.getAll("io");
        if (values.size() == 1) {
            try {
                return UUID.fromString(values.get(0));
            } catch (IllegalArgumentException iaex) {
                log.warn("Malformed UUID received for session! io=" + values.get(0));
            }
        }

        for (String cookieHeader : headers.getAll(HttpHeaderNames.COOKIE)) {
            Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader);

            for (Cookie cookie : cookies) {
                if (cookie.name().equals("io")) {
                    try {
                        return UUID.fromString(cookie.value());
                    } catch (IllegalArgumentException iaex) {
                        log.warn("Malformed UUID received for session! io=" + cookie.value());
                    }
                }
            }
        }

        return UUID.randomUUID();
    }
private UUID generateOrGetSessionIdFromRequest ( HttpHeaders headers ) { List < String > values = headers . getAll ( "io" ) ; if ( values . size ( ) == 1 ) { try { return UUID . fromString ( values . get ( 0 ) ) ; } catch ( IllegalArgumentException iaex ) { log . warn ( "Malformed UUID received for session! io=" + values . get ( 0 ) ) ; } } for ( String cookieHeader : headers . getAll ( HttpHeaderNames . COOKIE ) ) { Set < Cookie > cookies = ServerCookieDecoder . LAX . decode ( cookieHeader ) ; for ( Cookie cookie : cookies ) { if ( cookie . name ( ) . equals ( "io" ) ) { try { return UUID . fromString ( cookie . value ( ) ) ; } catch ( IllegalArgumentException iaex ) { log . warn ( "Malformed UUID received for session! io=" + cookie . value ( ) ) ; } } } } return UUID . randomUUID ( ) ; }
This method will either generate a new random sessionId or will retrieve the value stored
in the "io" cookie.  Failures to parse will cause a logging warning to be generated and a
random uuid to be generated instead (same as not passing a cookie in the first place).