Example usage for javax.websocket Session getRequestParameterMap

List of usage examples for javax.websocket Session getRequestParameterMap

Introduction

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

Prototype

Map<String, List<String>> getRequestParameterMap();

Source Link

Usage

From source file:cito.server.AbstractEndpoint.java

@OnOpen
@Override/*from   www .  j av  a2 s  .  c om*/
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   w ww .  j  a  va2 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:org.brutusin.rpc.websocket.WebsocketEndpoint.java

/**
 *
 * @param session/*from w  w  w. j  av  a2  s  .  com*/
 * @param config
 */
@Override
public void onOpen(Session session, EndpointConfig config) {
    final WebsocketContext websocketContext = contextMap
            .get(session.getRequestParameterMap().get("requestId").get(0));
    if (!allowAccess(session, websocketContext)) {
        try {
            session.close(new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT, "Authentication required"));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return;
    }
    final SessionImpl sessionImpl = new SessionImpl(session, websocketContext);
    sessionImpl.init();
    wrapperMap.put(session.getId(), sessionImpl);

    session.addMessageHandler(new MessageHandler.Whole<String>() {
        public void onMessage(String message) {
            WebsocketActionSupportImpl.setInstance(new WebsocketActionSupportImpl(sessionImpl));
            try {
                String response = process(message, sessionImpl);
                if (response != null) {
                    sessionImpl.sendToPeerRaw(response);
                }
            } finally {
                WebsocketActionSupportImpl.clear();
            }
        }
    });
}

From source file:furkan.app.tictactoewebsocket.TicTacToeServer.java

@OnOpen
public void onOpen(Session session, @PathParam("gameId") long gameId, @PathParam("username") String username) {
    System.out.println("Inside onOpen");
    try {/*ww  w.ja va  2s  .  c om*/
        TicTacToeGame ticTacToeGame = TicTacToeGame.getActiveGame(gameId);
        if (ticTacToeGame != null) {
            session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION,
                    "This game has already started!"));
        }

        List<String> actions = session.getRequestParameterMap().get("action");
        if (actions != null && actions.size() == 1) {
            String action = actions.get(0);
            if (action.equalsIgnoreCase("start")) {
                Game game = new Game();
                game.gameId = gameId;
                game.player1 = session;
                TicTacToeServer.games.put(gameId, game);
            } else if (action.equalsIgnoreCase("join")) {
                Game game = TicTacToeServer.games.get(gameId);
                game.player2 = session;
                game.ticTacToeGame = TicTacToeGame.startGame(gameId, username);
                this.sendJsonMessage(game.player1, game, new GameStartedMessage(game.ticTacToeGame));
                this.sendJsonMessage(game.player2, game, new GameStartedMessage(game.ticTacToeGame));
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
        try {
            session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, ioe.toString()));
        } catch (IOException ignore) {
        }
    }
}