/** * Get the accepted WebSocket protocol. * * @return the accepted WebSocket protocol. */ public String getAcceptedSubProtocol() { return getHeader(SEC_WEBSOCKET_PROTOCOL); }
/** * Get the accepted WebSocket protocol. * * @return the accepted WebSocket protocol. */ public String getAcceptedSubProtocol() { return getHeader(SEC_WEBSOCKET_PROTOCOL); }
public String getExternalId(final String path, final Session session) { final String sessionHandshake = session.getUpgradeResponse().getHeader(WS_HAND_SHAKE_KEY); for (SessionIdWrapper sw : sessionMap.get(path)) { if (sw.getSession().getUpgradeResponse().getHeader(WS_HAND_SHAKE_KEY).equals(sessionHandshake)) { return sw.getId(); } } return null; }
/** * * Removes the closing client's session from 'sessionMap' (using the handshake identifier). * * @param session */ public void removeSession(final Session session) { logger.debug("removeSession called"); final String sessionHandshake = session.getUpgradeResponse().getHeader(WS_HAND_SHAKE_KEY); sessionMap.values().forEach(sessionSet -> sessionSet.forEach( s -> { if (s.getSession().getUpgradeResponse().getHeader(WS_HAND_SHAKE_KEY).equals(sessionHandshake)) { sessionSet.remove(s); liveLoggingHandler.broadcast(LiveLoggingUtils.buildLiveLogOutboundDTO(s.getTraceId(), null, null, "Websocket closed", false, false)); if (s.isLogMockCalls()) LiveLoggingUtils.MOCK_TRAFFIC_LOGGER.info(LiveLoggingUtils.buildLiveLogOutboundFileEntry(s.getTraceId(), null, null, "Websocket closed", false, false)); return; } }) ); }
/** * * Stores all websocket client sessions in the internal map 'sessionMap'. * * Note sessions are 'internally' identified using the encrypted handshake 'Sec-WebSocket-Accept' value and * 'externally' identified using an allocated UUID. * * * @param mockExtId * @param path * @param idleTimeoutMillis * @param session * */ public void registerSession(final String mockExtId, final String path, final long idleTimeoutMillis, final boolean proxyPushIdOnConnect, final Session session, final boolean logMockCalls) { logger.debug("registerSession called"); session.setIdleTimeout((idleTimeoutMillis > 0) ? idleTimeoutMillis : MAX_IDLE_TIMEOUT_MILLIS ); final Set<SessionIdWrapper> sessions = sessionMap.getOrDefault(path, new HashSet<>()); final String assignedId = GeneralUtils.generateUUID(); final String traceId = session.getUpgradeResponse().getHeader(GeneralUtils.LOG_REQ_ID); sessions.add(new SessionIdWrapper(assignedId, traceId, session, GeneralUtils.getCurrentDate(), logMockCalls)); sessionMap.put(path, sessions); if (proxyPushIdOnConnect) { sendMessage(assignedId, new WebSocketDTO(path, "clientId: " + assignedId)); } liveLoggingHandler.broadcast(LiveLoggingUtils.buildLiveLogOutboundDTO(traceId, 101, null, "Websocket established (clientId: " + assignedId + ")", false, false)); if (logMockCalls) LiveLoggingUtils.MOCK_TRAFFIC_LOGGER.info(LiveLoggingUtils.buildLiveLogOutboundFileEntry(traceId, 101, null, "Websocket established (clientId: " + assignedId + ")", false, false)); }