Search in sources :

Example 1 with NativeWebSocketSession

use of org.springframework.web.socket.adapter.NativeWebSocketSession in project thingsboard by thingsboard.

the class TbWebSocketHandler method afterConnectionEstablished.

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    super.afterConnectionEstablished(session);
    try {
        if (session instanceof NativeWebSocketSession) {
            Session nativeSession = ((NativeWebSocketSession) session).getNativeSession(Session.class);
            if (nativeSession != null) {
                nativeSession.getAsyncRemote().setSendTimeout(sendTimeout);
            }
        }
        String internalSessionId = session.getId();
        TelemetryWebSocketSessionRef sessionRef = toRef(session);
        String externalSessionId = sessionRef.getSessionId();
        if (!checkLimits(session, sessionRef)) {
            return;
        }
        internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef, maxMsgQueuePerSession));
        externalSessionMap.put(externalSessionId, internalSessionId);
        processInWebSocketService(sessionRef, SessionEvent.onEstablished());
        log.info("[{}][{}][{}] Session is opened", sessionRef.getSecurityCtx().getTenantId(), externalSessionId, session.getId());
    } catch (InvalidParameterException e) {
        log.warn("[{}] Failed to start session", session.getId(), e);
        session.close(CloseStatus.BAD_DATA.withReason(e.getMessage()));
    } catch (Exception e) {
        log.warn("[{}] Failed to start session", session.getId(), e);
        session.close(CloseStatus.SERVER_ERROR.withReason(e.getMessage()));
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) TelemetryWebSocketSessionRef(org.thingsboard.server.service.telemetry.TelemetryWebSocketSessionRef) NativeWebSocketSession(org.springframework.web.socket.adapter.NativeWebSocketSession) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) WebSocketSession(org.springframework.web.socket.WebSocketSession) Session(javax.websocket.Session) NativeWebSocketSession(org.springframework.web.socket.adapter.NativeWebSocketSession)

Aggregations

IOException (java.io.IOException)1 InvalidParameterException (java.security.InvalidParameterException)1 Session (javax.websocket.Session)1 BeanCreationNotAllowedException (org.springframework.beans.factory.BeanCreationNotAllowedException)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1 NativeWebSocketSession (org.springframework.web.socket.adapter.NativeWebSocketSession)1 TelemetryWebSocketSessionRef (org.thingsboard.server.service.telemetry.TelemetryWebSocketSessionRef)1