How to use OkHttp3 to get the generated SessionId for a WebSocket connection?

Viewed 246

I need to get SessionId for WebSocket connection. How can I get it?
When my client was on js there were no problems getting it (you can parse socket._transport.url).

A lot of logic is tied to SessionId which cannot be changed already.

If you use SockJS in a browser, you can see this transport URL from which you can subsequently pull out sessionId

wss://host/websocket/052/rs5ahsly/websocket

But this is SockJS, in OkHttp it is probably something else

On the server, I can get sessionId this way, but how to do this on the client?

@MessageMapping("/find")
public void find(SimpMessageHeaderAccessor sha, User user) {
    String sessionId = sha.getSessionId();
    LOG.debug("New session find - {}, {}", sessionId, user);
    // New session find - rs5ahsly, {user: Name, ...}
    Repository.add(sessionId, user);
}

Server: spring, stomp
Client: android, Kotlin, stomp client written on top of okhttp3 / WebSocket

0 Answers
Related