Package org.jwebsocket.token

Examples of org.jwebsocket.token.Token


     */
    @Override
    public void processPacket(WebSocketClientEvent aEvent, WebSocketPacket aPacket) {
      for (WebSocketClientListener lListener : getListeners()) {
        if (lListener instanceof WebSocketClientTokenListener) {
          Token lToken = packetToToken(aPacket);

          String lType = lToken.getType();
          String lReqType = lToken.getString("reqType");

          if (lType != null) {
            if (WELCOME.equals(lType)) {
              fClientId = lToken.getString("sourceId");
              fSessionId = lToken.getString("usid");
            } else if (GOODBYE.equals(lType)) {
              fUsername = null;
            }
          }
          if (lReqType != null) {
            if (LOGIN.equals(lReqType)) {
              fUsername = lToken.getString("username");
            } else if (LOGOUT.equals(lReqType)) {
              fUsername = null;
            }
          }
          ((WebSocketClientTokenListener) lListener).processToken(aEvent, lToken);
View Full Code Here


     * @param aDataPacket
     * @return
     */
    public static Token packetToToken(WebSocketPacket aDataPacket) {
        // todo: implement!
        Token lArgs = new Token();
        return lArgs;
    }
View Full Code Here

   * converts a JSON formatted data packet into a token.
   * @param aDataPacket
   * @return
   */
  public static Token packetToToken(WebSocketPacket aDataPacket) {
    Token lToken = new Token();
    try {
      String lStr = aDataPacket.getString("UTF-8");
      JSONTokener lJSONTokener = new JSONTokener(lStr);
      lToken.setJSONObject(new JSONObject(lJSONTokener));
    } catch (UnsupportedEncodingException ex) {
      // TODO: handle exception
      // log.error(ex.getClass().getSimpleName() + ": " + ex.getMessage());
    } catch (JSONException ex) {
      // // TODO: handle exception
View Full Code Here

  public void broadcastConnectEvent(WebSocketConnector aConnector) {
    if (log.isDebugEnabled()) {
      log.debug("Broadcasting connect...");
    }
    // broadcast connect event to other clients of the jWebSocket network
    Token lConnect = new Token(Token.TT_EVENT);
    lConnect.put("name", "connect");
    // lConnect.put("usid", getSessionId(aConnector));
    lConnect.put("sourceId", aConnector.getId());
    // if a unique node id is specified for the client include that
    String lNodeId = aConnector.getNodeId();
    if (lNodeId != null) {
      lConnect.put("unid", lNodeId);
    }
    lConnect.put("clientCount", getConnectorCount());

    // broadcast to all except source
    broadcastToken(aConnector, lConnect);
  }
View Full Code Here

  public void broadcastDisconnectEvent(WebSocketConnector aConnector) {
    if (log.isDebugEnabled()) {
      log.debug("Broadcasting disconnect...");
    }
    // broadcast connect event to other clients of the jWebSocket network
    Token lDisconnect = new Token(Token.TT_EVENT);
    lDisconnect.put("name", "disconnect");
    // lDisconnect.put("usid", getSessionId(aConnector));
    lDisconnect.put("sourceId", aConnector.getId());
    // if a unique node id is specified for the client include that
    String lNodeId = aConnector.getNodeId();
    if (lNodeId != null) {
      lDisconnect.put("unid", lNodeId);
    }
    lDisconnect.put("clientCount", getConnectorCount());

    // broadcast to all except source
    broadcastToken(aConnector, lDisconnect);
  }
View Full Code Here

  private void sendWelcome(WebSocketConnector aConnector) {
    if (log.isDebugEnabled()) {
      log.debug("Sending welcome...");
    }
    // send "welcome" token to client
    Token lWelcome = new Token(TT_WELCOME);
    lWelcome.put("vendor", JWebSocketCommonConstants.VENDOR);
    lWelcome.put("version", JWebSocketServerConstants.VERSION_STR);
    // here the session id is MANDATORY! to pass to the client!
    lWelcome.put("usid", aConnector.getSession().getSessionId());
    lWelcome.put("sourceId", aConnector.getId());
    // if a unique node id is specified for the client include that
    String lNodeId = aConnector.getNodeId();
    if (lNodeId != null) {
      lWelcome.put("unid", lNodeId);
    }
    lWelcome.put("timeout", aConnector.getEngine().getConfiguration().getTimeout());

    sendToken(aConnector, aConnector, lWelcome);
  }
View Full Code Here

  private void broadcastLoginEvent(WebSocketConnector aConnector) {
    if (log.isDebugEnabled()) {
      log.debug("Broadcasting login event...");
    }
    // broadcast login event to other clients of the jWebSocket network
    Token lLogin = new Token(Token.TT_EVENT);
    lLogin.put("name", "login");
    lLogin.put("username", getUsername(aConnector));
    lLogin.put("clientCount", getConnectorCount());
    // lLogin.put("usid", getSessionId(aConnector));
    lLogin.put("sourceId", aConnector.getId());
    // if a unique node id is specified for the client include that
    String lNodeId = aConnector.getNodeId();
    if (lNodeId != null) {
      lLogin.put("unid", lNodeId);
    }
    // broadcast to all except source
    broadcastToken(aConnector, lLogin);
  }
View Full Code Here

     * converts a CSV formatted data packet into a token.
     * @param aDataPacket
     * @return
     */
    public static Token packetToToken(WebSocketPacket aDataPacket) {
        Token lToken = new Token();
        try {
            String aData = aDataPacket.getString("UTF-8");
            String[] lItems = aData.split(",");
            for (int i = 0; i < lItems.length; i++) {
                String[] lKeyVal = lItems[i].split("=", 2);
                if (lKeyVal.length == 2) {
                    String lVal = lKeyVal[1];
                    if (lVal.length() <= 0) {
                        lToken.put(lKeyVal[0], null);
                    } else if (lVal.startsWith("\"") && lVal.endsWith("\"")) {
                        // unescape commata by \x2C
                        lVal = lVal.replace("\\x2C", ",");
                        // unescape quotes by \x22
                        lVal = lVal.replace("\\x22", "\"");
                        lToken.put(lKeyVal[0], lVal.substring(1, lVal.length() - 1));
                    } else {
                        lToken.put(lKeyVal[0], lVal);
                    }
                }
            }
        } catch (UnsupportedEncodingException ex) {
            // TODO: process exception
View Full Code Here

  private void broadcastLogoutEvent(WebSocketConnector aConnector) {
    if (log.isDebugEnabled()) {
      log.debug("Broadcasting logout event...");
    }
    // broadcast login event to other clients of the jWebSocket network
    Token lLogout = new Token(Token.TT_EVENT);
    lLogout.put("name", "logout");
    lLogout.put("username", getUsername(aConnector));
    lLogout.put("clientCount", getConnectorCount());
    // lLogout.put("usid", getSessionId(aConnector));
    lLogout.put("sourceId", aConnector.getId());
    // if a unique node id is specified for the client include that
    String lNodeId = aConnector.getNodeId();
    if (lNodeId != null) {
      lLogout.put("unid", lNodeId);
    }
    // broadcast to all except source
    broadcastToken(aConnector, lLogout);
  }
View Full Code Here

  private void sendGoodBye(WebSocketConnector aConnector, CloseReason aCloseReason) {
    if (log.isDebugEnabled()) {
      log.debug("Sending good bye...");
    }
    // send "goodBye" token to client
    Token lGoodBye = new Token(TT_GOODBYE);
    lGoodBye.put("vendor", JWebSocketCommonConstants.VENDOR);
    lGoodBye.put("version", JWebSocketServerConstants.VERSION_STR);
    lGoodBye.put("sourceId", aConnector.getId());
    if (aCloseReason != null) {
      lGoodBye.put("reason", aCloseReason.toString().toLowerCase());
    }

    // don't send session-id on good bye, neither required nor desired
    sendToken(aConnector, aConnector, lGoodBye);
  }
View Full Code Here

TOP

Related Classes of org.jwebsocket.token.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.