Example usage for javax.websocket Session getId

List of usage examples for javax.websocket Session getId

Introduction

In this page you can find the example usage for javax.websocket Session getId.

Prototype

String getId();

Source Link

Document

Provides a unique identifier for the session.

Usage

From source file:hu.bme.iit.quiz.endpoint.PollEndpoint.java

@OnOpen
public void onOpen(final Session session, @PathParam("presentationID") Integer presentationID) {
    logger.debug("onOpen websocket event id: " + session.getId());
    peers.add(session);//from   w w  w.ja va2s  . c om
    if (!quizzesInOngoingPhase.containsKey(presentationID)) {
        QuizRoom newQuizRoom = new QuizRoom(presentationID);
        quizzesInOngoingPhase.put(presentationID, newQuizRoom);
        newQuizRoom.initQuizPresentation();
    }
}

From source file:cito.server.AbstractEndpoint.java

@OnError
@Override//from ww  w.ja  va 2s .  c  om
public void onError(Session session, Throwable cause) {
    final String errorId = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
    this.log.warn("WebSocket error. [id={},principle={},errorId={}]", session.getId(),
            session.getUserPrincipal(), errorId, cause);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.errorEvent.select(cito.annotation.OnError.Literal.onError()).fire(cause);
        final Frame errorFrame = Frame.error()
                .body(MediaType.TEXT_PLAIN_TYPE, format("%s [errorId=%s]", cause.getMessage(), errorId))
                .build();
        session.getBasicRemote().sendObject(errorFrame);
        session.close(
                new CloseReason(CloseCodes.PROTOCOL_ERROR, format("See server log. [errorId=%s]", errorId)));
    } catch (IOException | EncodeException e) {
        this.log.error("Unable to send error frame! [id={},principle={}]", session.getId(),
                session.getUserPrincipal(), e);
    }
}

From source file:hu.bme.iit.quiz.endpoint.PollEndpoint.java

private void sendQuizQestion(Session session, Integer presentationID, String userkey, Integer questionID) {
    logger.debug("sendQuizQestion function start: " + session.getId());
    quizzesInOngoingPhase.get(presentationID).setActualQuestion(questionID);
    EndpointUtil.sendUpdateToAll(peers, createQuizQuestionUpdateString(presentationID, questionID));

    for (String secretkey : quizzesInOngoingPhase.get(presentationID).getFollowers().keySet()) {
        this.storeUserAnswer(presentationID, secretkey, -1);
    }//  w w  w.  j  av a 2s .  co  m
    EndpointUtil.sendUpdateToPeer(quizzesInOngoingPhase.get(presentationID).getOwnerPeer(),
            createUserAnswerUpdateString(presentationID));
    logger.debug("sendQuizQestion function finish: " + session.getId());
}

From source file:TenantSubscriptionEndpoint.java

@OnMessage
public void onMessage(Session session, String message, @PathParam("adaptorname") String adaptorName,
        @PathParam("tdomain") String tdomain) {
    if (log.isDebugEnabled()) {
        log.debug("Received and dropped message from client. Message: " + message + ", for Session id: "
                + session.getId() + ", for tenant domain" + tdomain + ", for the Adaptor:" + adaptorName);
    }//w  w w  .ja  va  2 s. c  om
}

From source file:com.github.mrstampy.gameboot.otp.websocket.WebSocketEndpoint.java

@Override
public void onClose(Session session, CloseReason closeReason) {
    log.debug("Session {} closed on channel", session.getId());
    if (this.session == session)
        this.session = null;
}

From source file:hu.bme.iit.quiz.endpoint.PollEndpoint.java

private boolean isQuizOwner(Integer presentationID, Session peer) {
    return quizzesInOngoingPhase.get(presentationID).getQuizPresentation().getOwner().getSecretkey()
            .equalsIgnoreCase(userSessions.get(peer.getId()));
}

From source file:com.github.mrstampy.gameboot.otp.websocket.WebSocketEndpoint.java

@Override
public void onOpen(Session session, EndpointConfig config) {
    log.debug("Session {} open on channel", session.getId());

    session.addMessageHandler(new MessageHandler.Whole<byte[]>() {

        @Override//from  w  ww.j  a  va 2  s. co m
        public void onMessage(byte[] message) {
            try {
                WebSocketEndpoint.this.onMessage(message, session);
            } catch (Exception e) {
                log.error("Unexpected exception", e);
            }
        }
    });
}

From source file:cito.server.AbstractEndpoint.java

@OnOpen
@Override/* w  w w  .j  a  v  a 2s  .  c  o  m*/
public void onOpen(Session session, EndpointConfig config) {
    final String httpSessionId = session.getRequestParameterMap().get("httpSessionId").get(0);
    this.log.info("WebSocket connection opened. [id={},httpSessionId={},principle={}]", session.getId(),
            httpSessionId, session.getUserPrincipal());
    final SecurityContext securityCtx = WebSocketConfigurator.removeSecurityContext(config.getUserProperties(),
            httpSessionId);
    SecurityContextProducer.set(session, securityCtx);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.registry.register(session);
        this.sessionEvent.select(cito.annotation.OnOpen.Literal.onOpen()).fire(session);
    }

    this.rttService.start(session);
}

From source file:org.brutusin.rpc.websocket.WebsocketEndpoint.java

@Override
public void onClose(Session session, CloseReason closeReason) {
    contextMap.remove(session.getRequestParameterMap().get("requestId").get(0));
    final SessionImpl sessionImpl = wrapperMap.remove(session.getId());
    if (sessionImpl != null) {
        try {//from ww w  . ja v  a2  s .c  o  m
            WebsocketActionSupportImpl.setInstance(new WebsocketActionSupportImpl(sessionImpl));
            for (Topic topic : sessionImpl.getCtx().getSpringContext().getTopics().values()) {
                try {
                    topic.unsubscribe();
                } catch (InvalidSubscriptionException ise) {
                    // Ignored already unsubscribed
                }
            }
        } finally {
            WebsocketActionSupportImpl.clear();
            sessionImpl.close();
        }
    }
}

From source file:com.github.mrstampy.gameboot.otp.websocket.WebSocketEndpoint.java

/**
 * On message.//from  w  ww  .  j a  v a 2s . co m
 *
 * @param msg
 *          the msg
 * @param session
 *          the session
 * @throws Exception
 *           the exception
 */
@OnMessage
public void onMessage(byte[] msg, Session session) throws Exception {
    log.debug("Message received for channel {}", session.getId());
    try {
        if (isEncrypting(session)) {
            try {
                decrypt(msg);
                return;
            } catch (Exception e) {
                log.error("Cannot decrypt: assuming delete request sent: {}", e.getMessage());
            }
        }

        unencrypted(session, msg);
    } finally {
        if (responseLatch != null)
            responseLatch.countDown();
    }
}